Page 1 of 1

Why is it not working?

Posted: Thu Jul 16, 2009 12:17 pm
by ashish.s.chhabria
// i have to display a question and 4 options . the user who has logged in can then answer.
// his answer is then compared with the right answer and then inserted in the table.
// after this when he relogs in we dont show the question again. but display a message
// but this code is giving me errors ...PLS HELP

<?php

$con = mysql_connect("localhost","","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("168084",$con);
$result=mysql_query("SELECT * from tbl_twqmaster");
$row=mysql_fetch_array($result);

$result3=mysqli_query("SELECT * from tbl_twquser");
$row3=mysql_fetch_array($result3);

$displaya=0;
while($row3)
{
// to test if the user has already answered this weeks question
while($row)
{
if ($row3['twqId']==$row['id'])//also put same user condition
{
$displaya=1;
break;
}
else
$displaya=0;
}
}

if($displaya==0)
{


?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>This Weeks Question</title>
<meta name="" content="">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body>

<form action="twq.php" method="post">
<?php
while($row)
{
echo $row['question'];

?>
<br>
<input type="radio" value="a" name="option"><?php { echo($row['opt1']); } ?></input> <br>
<input type="radio" value="b" name="option"><?php {echo($row['opt2']);} ?></input> <br>
<input type="radio" value="c" name="option"><?php {echo($row['opt3']);} ?></input> <br>
<input type="radio" value="d" name="option"><?php {echo($row['opt4']);}

}// end of while
?></input> <br>

<?php
mysql_close($con);

?>
<input type="submit" name="Submit">

</form>
</body>
</html>


<?php
$con = mysql_connect("localhost","168084","fecomps");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
echo("User Answer is :");
echo $_POST["option"];
mysql_select_db("168084", $con);



$option=$_POST["option"] ;

$result2=mysql_query("SELECT * from tbl_twqmaster");
while($row1 = mysql_fetch_array($result2))
{


if(strcmp($option,$row1['answer'])==0)
{


$ans=1;
echo "<br />";
echo "<br />";
echo "<br />";

echo "good... its a rite answer";

}
else $ans=0;}

mysql_query("INSERT INTO tbl_twquser (twqId,userId,answer)
VALUES (1,1,$ans)");

}//end of if displaya
else
{
echo("You have already answered this time question");
}
mysql_close($con);
?>

Re: Why is it not working?

Posted: Thu Jul 16, 2009 12:41 pm
by waxtonmax
Actual what error you are getting.?

Re: Why is it not working?

Posted: Thu Jul 16, 2009 12:51 pm
by ashish.s.chhabria
the error is basically a internal server error .
i have checked all the tables- they are fine.
i have implemented the initial case of displaying the question, but i am having problem with the if case where in i have to display an announcement, incase the user has already answered

Re: Why is it not working?

Posted: Thu Jul 16, 2009 1:10 pm
by jackpf
A server error means there's something wrong with the server, not your PHP.

Re: Why is it not working?

Posted: Thu Jul 16, 2009 1:15 pm
by ashish.s.chhabria
any idea how i can rectify that
i am a student with not much knowledge of PHP..

Re: Why is it not working?

Posted: Thu Jul 16, 2009 4:32 pm
by jackpf
What OS do you have?
Do you have any htaccess files?

It's hard to say without the necessary information.

Re: Why is it not working?

Posted: Mon Jul 27, 2009 6:22 am
by waxtonmax
Hi jackpf,

I won't agree your point, because many time during app error and deployment error we use to get this message.
A server error means there's something wrong with the server, not your PHP.

Hi,
Have you checked your logs. What does the log says, most of the information should be available in the logs.

Re: Why is it not working?

Posted: Mon Jul 27, 2009 8:44 am
by jackpf
Hi waxtonmax,
Oh right...well I've never encountered a 500 internal server error caused by code, only something apache related like a dodgy htaccess file.

May I ask what sort of programming error would cause a 500 internal server error?