This is getting...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Monotoko
Forum Commoner
Posts: 64
Joined: Fri Oct 26, 2007 4:24 pm

This is getting...

Post 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?
User avatar
webspider
Forum Commoner
Posts: 52
Joined: Sat Oct 27, 2007 3:29 am

Re: This is getting...

Post 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
 
Monotoko
Forum Commoner
Posts: 64
Joined: Fri Oct 26, 2007 4:24 pm

Re: This is getting...

Post 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";
 
 
?>
Post Reply