dayp Posted February 8, 2007 Share Posted February 8, 2007 hey ive been having some problems with this code where I try insert a new row of data into a mysql table <?php $name1=$_POST['name1']; $dbhost="localhost"; $dbusername="goa"; $dbpassword="jo"; $dbname="goatla"; $connect = mysql_connect($dbhost, $dbusername, $dbpassword); $s_db = mysql_select_db($dbname,$connect) or die ("Could not select database"); $query = "INSERT INTO `user` ( `name`, `score`) VALUES ( '" . $_POST['name1'] . "' , '"0"');"; $result = @mysql_query($sql) or die ("Query failed"); ?> I wanted to add $_POST['name1'] and 0 to the bottom of my table users but it does nothing doesnt even add a new row but it goes back no errors. could anyone help me? Link to comment https://forums.phpfreaks.com/topic/37593-insert-row/ Share on other sites More sharing options...
Temple Posted February 8, 2007 Share Posted February 8, 2007 Well, from what I can tell in your script, you're asking mysql to execute a blank query because the variable $sql was never set. Change this line: $result = @mysql_query($sql) or die ("Query failed"); Into this: $result = @mysql_query($query) or die ("Query failed"); Link to comment https://forums.phpfreaks.com/topic/37593-insert-row/#findComment-179752 Share on other sites More sharing options...
dayp Posted February 8, 2007 Author Share Posted February 8, 2007 it still does nothing all i want to do is insert a new row with theres 2 values am i doing something wrong? ive connected to the database and then done a query telling it to insert these values into a row Link to comment https://forums.phpfreaks.com/topic/37593-insert-row/#findComment-179756 Share on other sites More sharing options...
fiddy Posted February 8, 2007 Share Posted February 8, 2007 if you add @ before mysql_ query it will suppress the error. I guess there is some thing wrong with your query near 0. try removing the double quotes in 0 and use only single quotes. Link to comment https://forums.phpfreaks.com/topic/37593-insert-row/#findComment-179759 Share on other sites More sharing options...
dayp Posted February 8, 2007 Author Share Posted February 8, 2007 haha u lifesaver! it works!!!!!!!! genious Link to comment https://forums.phpfreaks.com/topic/37593-insert-row/#findComment-179764 Share on other sites More sharing options...
dayp Posted February 8, 2007 Author Share Posted February 8, 2007 sorry but Ive come across another problem from the code above this line $query = "INSERT INTO `here` ( `name`, `score`) VALUES ( '" . $name1 . "' , '0');"; I need to put in this variable $school where it says here ive tried a feqw things but none worked anyone have any idea? Link to comment https://forums.phpfreaks.com/topic/37593-insert-row/#findComment-179782 Share on other sites More sharing options...
fiddy Posted February 8, 2007 Share Posted February 8, 2007 $query = "INSERT INTO `".$school."` ( `name`, `score`) VALUES ( '" . $name1 . "' , '0');"; Pls try this Link to comment https://forums.phpfreaks.com/topic/37593-insert-row/#findComment-179785 Share on other sites More sharing options...
dayp Posted February 9, 2007 Author Share Posted February 9, 2007 thankyou it works fine now!!! Link to comment https://forums.phpfreaks.com/topic/37593-insert-row/#findComment-180473 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.