why is...

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

why is...

Post 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";
 
 
?>
 
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: why is...

Post by Christopher »

You should check for errors and print the MySQL error messages after each call.
(#10850)
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: why is...

Post by Zoxive »

Code: Select all

mysql_select_db("gamersne_mysys", $con) or die('Error Selecting DB: ' . mysql_error()); //DB selection?
Monotoko
Forum Commoner
Posts: 64
Joined: Fri Oct 26, 2007 4:24 pm

Re: why is...

Post by Monotoko »

hahahaha, thanks, that helped, it told me access denied, i forgot to put the user in the DB XD
Post Reply