I have several scripts that are used in a lottery system, which i'm currently developing.
Script one:
<?php
session_start();
$page = array();
$page['title'] = 'OpenTheBox | DuffLotto';
$number = 1;
require_once('/home/davespri/hidden/dbcon.php');
include('header.php');
echo '<h1>OpenTheBox - The Original Community Game</h1>';
echo '<center>
Available Numbers
</center>';
$connect = mysql_connect($host, $user, $pass);
if (!$connect) {
die('Unable to connect to Mysql');
}
mysql_select_db('davespri_Gamerecords', $connect);
$result = mysql_query("SELECT * FROM OpenTheBox2");
echo "<center><table border='1'><tr><th>Slot:</th><th>Taken by:</th></tr>";
while ($row = mysql_fetch_array($result)) {
echo "<tr>";
if ($row['Nickname'] = 'NULL') {
$row['Nickname'] = "<center><form action=otbprocess.php method=post>
<input name=slotChosen type=hidden value=" . $row['Slot'] . ">
<input type=submit value=Buy! name=" . $row['Slot'] . ">
</form>";
}
echo "<td>" . $row['Slot'] . "</td>";
echo "<td>" . $row['Nickname'] . "</td>";
echo "</tr>";
}
echo "</center></table></center>";
include('footer.php');
?>
Script 2:
<?php
session_start();
$page = array();
$page['title'] = 'OpenTheBox | DuffLotto';
$slot = $_SESSION['slot'];
$name = 'duffrynmad';
if (!$slot) {
echo 'No slot chosen! '; echo "<a href=otb.php>Click here go back and play again.</a>";
die();
exit();
}
include('header.php');
require_once('/home/davespri/hidden/dbcon.php');
$connect = mysql_connect($host, $user, $pass);
if (!$connect) {
echo 'Failure to connect to Database';
die();
exit();
}
mysql_select_db('davespri_Gamerecords', $connect);
$update = mysql_query("UPDATE OpenTheBox2 SET Nickname = '$name' WHERE Slot = '$slot' ");
if ($update) {
echo 'Transaction successful!';
}
include('footer.php');
?>
The database is being updated correctly, but when you go back to the first page, the slot isnt showing to have been bought by 'duffrynmad', and is still showing as NULL.
Does anyone know why this is happening? Thanks in advance 🙂