allin44 Posted August 11, 2009 Share Posted August 11, 2009 Im down to my last nerve.. can somebody explain to me why NONE of this data will enter into the table.. <? $qno = $_GET['qno']; $quizno = $_GET['quizno']; $answera = $_POST['answera']; $answerb = $_POST['answerb']; $answerc = $_POST['answerc']; $answerd = $_POST['answerd']; $question = $_POST['question']; $answer = $_POST['answer']; include("../Register/functions/db_info.php"); $con = mysql_connect($server,$db,$pw); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("$db", $con); $insert_qno = $qno -1;//NUMBER TO INSERT AS QUESTION ID //IF THIS ISNT THE FIRST PAGE if($qno > 1) { echo $answera . " <br>"; echo $answerb . " <br>"; echo $answerc . " <br>"; echo $answerd . " <br>"; mysql_query("INSERT INTO trivia (quizid, questid, question, optiona, optionb, optionc, optiond) VALUES ('$quizno','$insert_qno', '$question', '$answera', '$answerb', '$answerc', '$answerd')"); mysql_close($con); } $qno++; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="newtrivia.php?qno=<? echo $qno; ?>&&quizno=<? echo $quizno; ?>" method="post"> <p> <h2>Question</h2> <label for = "q">Question </label><input type="text" size = "50" name="question" /><br /> <label for = "a">A) </label><input type="text" name="answera" /><br /> <label for = "b">B) </label><input type="text" name="answerb" /><br /> <label for = "c">C) </label><input type="text" name="answerc" /><br /> <label for = "d">D) </label><input type="text" name="answerd" /><br /> <label for = "answer">Answer </label><input type="text" name="answer" size='2' /><br /> </p> <p> <input type='submit' /> </p> </form> </body> </html> table structure CREATE TABLE `trivia` ( `num` int(11) NOT NULL auto_increment, `quizid` int(11) NOT NULL, `questid` int(11) NOT NULL, `optiona` varchar(100) NOT NULL, `optionb` varchar(100) NOT NULL, `optionc` varchar(100) NOT NULL, `optiond` varchar(100) NOT NULL, PRIMARY KEY (`num`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; Quote Link to comment https://forums.phpfreaks.com/topic/169827-solved-input-into-db-wont-work/ Share on other sites More sharing options...
guyfromfl Posted August 11, 2009 Share Posted August 11, 2009 I know there are better ways to catch errors but try changing your mysql_query statement to mysql_query("INSERT INTO trivia (quizid, questid, question, optiona, optionb, optionc, optiond) VALUES ('$quizno','$insert_qno', '$question', '$answera', '$answerb', '$answerc', '$answerd')") or die(mysql_error()); This might tell you what mysql doesn't like about what you are trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/169827-solved-input-into-db-wont-work/#findComment-895936 Share on other sites More sharing options...
Maq Posted August 11, 2009 Share Posted August 11, 2009 1) Don't use quotes for code... Use tags. 2) Don't use shorthand php tags, use <?php. 3) Echo out '$qno' and '$quizno', I don't see where they are initialized or declared. Quote Link to comment https://forums.phpfreaks.com/topic/169827-solved-input-into-db-wont-work/#findComment-895938 Share on other sites More sharing options...
allin44 Posted August 11, 2009 Author Share Posted August 11, 2009 1) Don't use quotes for code... Use [nobc] [/nobbc] tags. 2) Don't use shorthand php tags, use <?php. 3) Echo out '$qno' and '$quizno', I don't see where they are initialized or declared. They are declared on the page that starts the trivia creation.. all quizno does is dig into the DB to get the current quiz number, it works fine. Thanks for the heads up on the proper syntax to use in posting here, wasnt sure Quote Link to comment https://forums.phpfreaks.com/topic/169827-solved-input-into-db-wont-work/#findComment-895940 Share on other sites More sharing options...
allin44 Posted August 11, 2009 Author Share Posted August 11, 2009 I know there are better ways to catch errors but try changing your mysql_query statement to mysql_query("INSERT INTO trivia (quizid, questid, question, optiona, optionb, optionc, optiond) VALUES ('$quizno','$insert_qno', '$question', '$answera', '$answerb', '$answerc', '$answerd')") or die(mysql_error()); This might tell you what mysql doesn't like about what you are trying to do. Doh.. I was dinking around early and dropped the table and recreated it and forgot to put the QUESTION field in.. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/169827-solved-input-into-db-wont-work/#findComment-895944 Share on other sites More sharing options...
Maq Posted August 11, 2009 Share Posted August 11, 2009 Yep, that'll do it. Quote Link to comment https://forums.phpfreaks.com/topic/169827-solved-input-into-db-wont-work/#findComment-895945 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.