EDIT
I am now getting an error:
Warning: mysql_num_rows() expects parameter 1 to be resource, null given in /home/jahedhus/public_html/system/vote.php on line 126
My php code is as follows:
<?php
$id = $_GET['election'];
$result = mysql_query("SELECT * FROM votes WHERE election_id = '$id' AND ni = '". $_SESSION['ni']."'" )
or die(mysql_error());
if (mysql_num_rows($result) == 0) {
$sql="SELECT * FROM elections WHERE status = 'in_progress' AND election_id = '$id'";
$result1=mysql_query($sql);
$options="";
$party2="";
$party3="";
while ($row=mysql_fetch_array($result1)) {
echo "<tr>";
echo "<td><h5>" . $row['name_of_election']. "</h5><hr></td>";
echo "</td>";
$idd=$row["party1"];
$thing=$row["party1"];
$options.="<OPTION VALUE=\"$idd\">".$thing;
$idd=$row["party2"];
$thing=$row["party2"];
$party2.="<OPTION VALUE=\"$idd\">".$thing;
$idd=$row["party3"];
$thing=$row["party3"];
$party3.="<OPTION VALUE=\"$idd\">".$thing;
}
}
?>
<?php if (mysql_num_rows($result1) == 0) : ?>
<form action="votecasted.php?election=<?php echo $id; ?>" method="post">
<span id="spryselect1">
<label for="vote">Vote</label>
<select size=1" name="vote" id="vote">
<option selected="selected">Select Your Desired Party</option>
<?=$options?>
<?=$party2?>
<?=$party3?>
</select>
<span class="selectRequiredMsg">*</span></span><br />
<br /> <input name="" type="submit" value="Vote" />
</form>
<?php else : ?>
You cannot post vote anymore.
<?php endif; ?>
Line 126 is where it says:
<?php if (mysql_num_rows($result1) == 0) : ?>
Its weird becuase once a user has voted, it shows the error message whereby if the user hasnt voted, it says ‘You cannot post vote anymore’.
If I correctly understand the question, you just have to check
$resultto be different fromfalse. I’d suggest you to use the following syntax for embedded PHP:In your case, with some more SQL Injection checks: