My main page looks into a db to see if the current user has voted.
<?php
include 'db.php';
$con;
$dbname;
$mydb;
mysql_select_db($dbname) or die(mysql_error());
$result = mysql_query("SELECT date, user FROM users");
if (mysql_num_rows($result) == 0 ){
include 'Pollform.php';
mysql_close($con);
exit();
}
else {
while($arow = mysql_fetch_array( $result )){
$date=$arow['date'];
$user= $arow['user'];
}
include 'results.php';
exit();
}
?>
Problem is that when I refresh the main page, it automatically puts the user name into the database without me calling an insert. Here is the db script.
<?php
$con=mysql_connect('localhost', 'xxxxxx_xxxxx', 'xxxxx');
$dbname = 'xxxxxxx_xxxxxx';
$mydb= mysql_select_db($dbname,$con);
$sql2 = mysql_query("SELECT date,user FROM users");
$result=mysql_query($sql2);
$myinsert2=mysql_query("INSERT INTO users (date,user) VALUE (CURDATE(),'$pUser')")or die (mysql_error());
?>
Here is the page it's calling:
<?php
error_reporting(E_ALL);
?>
<!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>Topten Current Results</title>
<style type="text/css">
<!--
body {
font: 100% Verdana, Arial, Helvetica, sans-serif;
background: #666666;
margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
padding: 0;
text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
color: #000000;
}
.oneColElsCtr #container {
width: 46em;
background: #FFFFFF;
margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
border: 1px solid #000000;
text-align: left; /* this overrides the text-align: center on the body element. */
}
.oneColElsCtr #mainContent {
padding: 0 20px; /* remember that padding is the space inside the div box and margin is the space outside the div box */
}
-->
</style></head>
<body class="oneColElsCtr">
<div id="container">
<div id="mainContent">
<h1> Current survey results </h1>
<p><?php
echo $user.' ,you already filled this form on '. $date. '<br />';
mysql_close($con);
?></p>
<p><?php
include 'function.php';
mydb::fetchdata();
?></p>
<!-- end #mainContent -->Copyright: </div>
<!-- end #container --></div>
</body>
</html>
mydb::fetchdata(); works fine because it gives me undefined error since it is pulling from a blank db.
Thanks in advance.