Jump to content

Recommended Posts

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 ;

Link to comment
https://forums.phpfreaks.com/topic/169827-solved-input-into-db-wont-work/
Share on other sites

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.

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

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.