Why is it not working?

Discussions of secure PHP coding. Security in software is important, so don't be afraid to ask. And when answering: be anal. Nitpick. No security vulnerability is too small.

Moderator: General Moderators

Post Reply
ashish.s.chhabria
Forum Newbie
Posts: 3
Joined: Thu Jul 16, 2009 12:03 pm

Why is it not working?

Post 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);
?>
waxtonmax
Forum Newbie
Posts: 7
Joined: Thu Jun 12, 2008 7:25 pm
Contact:

Re: Why is it not working?

Post by waxtonmax »

Actual what error you are getting.?
ashish.s.chhabria
Forum Newbie
Posts: 3
Joined: Thu Jul 16, 2009 12:03 pm

Re: Why is it not working?

Post 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
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Why is it not working?

Post by jackpf »

A server error means there's something wrong with the server, not your PHP.
ashish.s.chhabria
Forum Newbie
Posts: 3
Joined: Thu Jul 16, 2009 12:03 pm

Re: Why is it not working?

Post by ashish.s.chhabria »

any idea how i can rectify that
i am a student with not much knowledge of PHP..
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Why is it not working?

Post by jackpf »

What OS do you have?
Do you have any htaccess files?

It's hard to say without the necessary information.
waxtonmax
Forum Newbie
Posts: 7
Joined: Thu Jun 12, 2008 7:25 pm
Contact:

Re: Why is it not working?

Post 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.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Why is it not working?

Post 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?
Post Reply