Jump to content

Whats wrong with this code?


melting_dog

Recommended Posts

Hi all,

 

Yeah just a fresh pair of eyes needed. It just wont insert into the table and the alert returns a blank. Only thing I can think is thats its posting variables from two different queries...but that shouldnt make a difference...

 

Cheers

 

FORM PAGE*************************

//*****************************LOGGED CHECKER*********************

$sql = "SELECT * FROM users WHERE firstName= '$logged'";

if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
   if ($row = mysql_fetch_assoc($result)) {


//**************QUESTION FORM*****************************
$sql2 = "SELECT * FROM questions WHERE questionID= '$orderCounter'";

if ($result2 = mysql_query($sql2)) {
    if (mysql_num_rows($result2)) {
   if ($row2 = mysql_fetch_assoc($result2)) {

echo "<p>" . $row2['questionText'] . "</p>";

echo '<form name="form1" method="post" action="questionProcess.php">';	
echo   '<input type="radio" name="q1" value="' . $row2['answer1'] . '" />' . $row2['answer1'] . '<br />';
echo	'<input type="radio" name="q1" value="' . $row2['answer2'] . '" />' . $row2['answer2'] . '<br />';
echo    '<input type="radio" name="q1" value="' . $row2['answer3'] . '" />' . $row2['answer3'] . '<br />';
echo     '<input type="radio" name="q1" value="' . $row2['answer4'] . '" />' . $row2['answer4'] . '<br />';     
echo    '<input type="hidden" name="userid" value="' . $row['userid'] . '" />';
echo    '<input type="hidden" name="orderCounter" value="' . $row['orderCounter'] . '" />'   
echo    '<input type="submit" name="Submit" id="Submit" value="Next" />';
echo     '</label>';
echo    '</form>';


}
}
}

}
}
}
?> 

PROCESSING PAGE****************************************

$q1=$_POST['q1'];
$userid=$_POST['userid'];
$orderCounter=$_POST['orderCounter'];
// To protect MySQL injection 
$q1 = stripslashes($q1);
$userid = stripslashes($userid);
$orderCounter = stripslashes($orderCounter);

$q1 = mysql_real_escape_string($q1);
$userid = mysql_real_escape_string($userid);
$orderCounter = mysql_real_escape_string($orderCounter);

//ALERT CHECKER
function confirm($msg)
{
echo "<script langauge=\"javascript\">alert(\"".$msg."\");</script>";
}
$msg = $userid;
confirm($msg);
//ALERT CHECKER

if
($q1 == "" ) {
$wrong = '<div id="blackText"><p>Please Answer the Question<p></div>';
}

else {
$sql="INSERT INTO $tbl_name (userid, value, orderCounter) VALUES ('$userid', '$q1', '$orderCounter')";
$result=mysql_query($sql);
}

ob_end_flush();
?>

Link to comment
Share on other sites

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.