Page 1 of 1

This is getting...

Posted: Sun Mar 02, 2008 1:08 am
by Monotoko
annoying now....i am trying to do a simple questionair script, which takes the answers, then puts them in submit.php and finally puts them in the table.

Code: Select all

<?php
$age = $_POST['qst_1'];
$gender = $_POST['sex'];
$music = $_POST['list_music'];
$music_rock = $_POST['fav_genre'];
$mus_list = $_POST['mus_list'];
$fav_band = $_POST['fav_band'];
$ply_games = $_POST['RadioGroup2'];
$fav_pltfrm = $_POST['fav_genre2'];
$time_plyed = $_POST['RadioGroup1'];
echo "$age<br>$gender<br>$music<br>$music_rock<br>$mus_list<br>$fav_band<br>$ply_games<br>$fav_pltfrm<br>$time_plyed";
 
$con = mysql_connect("localhost","gamersne_lounge","xxxxxxxxxx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("gamersne_mysys", $con);
 
mysql_query("INSERT INTO stats (age, gender, list_music, fav_genre, mus_list, vid_games, pltfrm, gme_length) 
VALUES ('$age', '$gender', '$music', '$music_rock', '$mus_list', '$ply_games', '$fav_pltfrm', '$time_played')");
 
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";
 
 
?>
Now, it seems to be working up until i actualy try and place it in the DB, it echos ok showing that my answers have indeed gone through to submit.php

Its just when i try to insert it, i get: Error: Query was empty

little help?

Re: This is getting...

Posted: Sun Mar 02, 2008 2:26 am
by webspider

Code: Select all

 
 mysql_query("INSERT INTO stats (age, gender, list_music, fav_genre, mus_list, vid_games, pltfrm, gme_length)
 VALUES ('$age', '$gender', '$music', '$music_rock', '$mus_list', '$ply_games', '$fav_pltfrm', '$time_played')");
 
replace this with

Code: Select all

 
$sql = " "; //write your query
 

Re: This is getting...

Posted: Sun Mar 02, 2008 5:24 am
by Monotoko
Ok, i did your editing and now it tells me no DB is selected, when there is one right there....

Code: Select all

<?php
$age = $_POST['qst_1'];
$gender = $_POST['sex'];
$music = $_POST['list_music'];
$music_rock = $_POST['fav_genre'];
$mus_list = $_POST['mus_list'];
$fav_band = $_POST['fav_band'];
$ply_games = $_POST['RadioGroup2'];
$fav_pltfrm = $_POST['fav_genre2'];
$time_plyed = $_POST['RadioGroup1'];
echo "$age<br>$gender<br>$music<br>$music_rock<br>$mus_list<br>$fav_band<br>$ply_games<br>$fav_pltfrm<br>$time_plyed";
 
$con = mysql_connect("localhost","gamersne_lounge","xx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("gamersne_mysys", $con); //DB selection?
 
$sql = "INSERT INTO stats (age, gender, list_music, fav_genre, mus_list, vid_games, pltfrm, gme_length) 
VALUES ('$age', '$gender', '$music', '$music_rock', '$mus_list', '$ply_games', '$fav_pltfrm', '$time_played')";
 
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";
 
 
?>