Page 1 of 1

why is...

Posted: Wed Mar 05, 2008 12:45 am
by Monotoko
why is my code bring up "no db selected" when there is one selected, i dont understand.

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

Re: why is...

Posted: Wed Mar 05, 2008 1:35 am
by Christopher
You should check for errors and print the MySQL error messages after each call.

Re: why is...

Posted: Wed Mar 05, 2008 8:15 am
by Zoxive

Code: Select all

mysql_select_db("gamersne_mysys", $con) or die('Error Selecting DB: ' . mysql_error()); //DB selection?

Re: why is...

Posted: Wed Mar 05, 2008 11:13 am
by Monotoko
hahahaha, thanks, that helped, it told me access denied, i forgot to put the user in the DB XD