garydt Posted January 24, 2008 Share Posted January 24, 2008 I get the variable - $chek from an array at random- while ($row_Recordset7 = mysql_fetch_assoc($result)) { $pics[$c] = $row_Recordset7['image']; $num[$c] = $row_Recordset7['number']; $cod[$c] = $row_Recordset7['code']; $c = $c +1; } $totalRows_Recordset7 = mysql_num_rows($Recordset7); $n = rand(0, $c-1); $chek = $cod[$n]; When I echo $chek is has a stored variable. Then when I submit a form and I compare $chek with another variable $chek is empty and I've got no idea why. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $cd = $_POST['code']; echo $chek; if ($cd!=$chek) { header("Location: code.php?nm=$cd&em=$ema&user=$user&ps=$chek"); exit(); } else { $insertSQL = sprintf("INSERT INTO userinformation (fname, email, password, usernm) VALUES ('$name', '$ema', '$user', '$pass');"); mysql_select_db($database_scopedbconect, $scopedbconect); $Result1 = mysql_query($insertSQL, $scopedbconect) or die(mysql_error()); // *** Validate request to login to this site. if (!isset($_SESSION)) { session_start(); } Any help would be great. Quote Link to comment https://forums.phpfreaks.com/topic/87534-variable-becomes-empty/ Share on other sites More sharing options...
trq Posted January 24, 2008 Share Posted January 24, 2008 Is $chek defined within the same script? We need to see your code in clearer context. Quote Link to comment https://forums.phpfreaks.com/topic/87534-variable-becomes-empty/#findComment-447715 Share on other sites More sharing options...
garydt Posted January 24, 2008 Author Share Posted January 24, 2008 Yes, it's in the same script. $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $cd = $_POST['code']; echo $chek; if ($cd!=$chek) { header("Location: code.php?nm=$cd&em=$ema&user=$user&ps=$chek"); exit(); } else { $insertSQL = sprintf("INSERT INTO userinformation (fname, email, password, usernm) VALUES ('$name', '$ema', '$user', '$pass');"); mysql_select_db($database_scopedbconect, $scopedbconect); $Result1 = mysql_query($insertSQL, $scopedbconect) or die(mysql_error()); // *** Validate request to login to this site. if (!isset($_SESSION)) { session_start(); } $loginFormAction = $_SERVER['PHP_SELF']; if (isset($_GET['accesscheck'])) { $_SESSION['PrevUrl'] = $_GET['accesscheck']; } if (isset($_POST['username'])) { $loginUsername=$_POST['username']; $password=$_POST['password']; $MM_fldUserAuthorization = ""; $MM_redirectLoginSuccess = "forum.php"; $MM_redirectLoginFailed = "loginfail.php"; $MM_redirecttoReferrer = false; mysql_select_db($database_scopedbconect, $scopedbconect); $LoginRS__query=sprintf("SELECT usernm, password FROM userinformation WHERE usernm=%s AND password=%s", GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); $LoginRS = mysql_query($LoginRS__query, $scopedbconect) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = ""; //declare two session variables and assign them $_SESSION['MM_Username'] = $loginUsername; $_SESSION['MM_UserGroup'] = $loginStrGroup; } } header("Location: forum.php"); } } $c = 0; mysql_select_db($database_scopedbconect, $scopedbconect); $query_Recordset7 = "SELECT * FROM codes"; $Recordset7 = mysql_query($query_Recordset7, $scopedbconect) or die(mysql_error()); $result = mysql_query($query_Recordset7); while ($row_Recordset7 = mysql_fetch_assoc($result)) { $pics[$c] = $row_Recordset7['image']; $num[$c] = $row_Recordset7['number']; $cod[$c] = $row_Recordset7['code']; $c = $c +1; } $totalRows_Recordset7 = mysql_num_rows($Recordset7); $n = rand(0, $c-1); $chek = $cod[$n]; mysql_select_db($database_scopedbconect, $scopedbconect); $query_Recordset6 = "SELECT * FROM codes WHERE number='$n'"; $Recordset6 = mysql_query($query_Recordset6, $scopedbconect) or die(mysql_error()); $row_Recordset6 = mysql_fetch_assoc($Recordset6); $top = $row_Recordset6['image']; $totalRows_Recordset6 = mysql_num_rows($Recordset6); ?> <html> <body> <table width="300" border="0" align="left" cellpadding="0"> <tr> <form action="<?php echo $loginFormAction; ?>" method="POST" name="form1" id="form1"> <td><br /> <img src="<?php print $pics[$n]; ?>" border="0" /> </td> <tr> <td colspan="2"> <input name="code" type="text" id="code" />Enter the above code <tr> <td colspan="2" align="center"><br /> <p align="center"> <label> <input name="Submit" type="submit" value="Submit" /> </label> </p> <input type="hidden" name="MM_insert" value="form1"></td> </tr> </form> Quote Link to comment https://forums.phpfreaks.com/topic/87534-variable-becomes-empty/#findComment-447737 Share on other sites More sharing options...
trq Posted January 24, 2008 Share Posted January 24, 2008 Look at your logic. You try and use $chek near the top of your script while it isn't defined until towards the end. Quote Link to comment https://forums.phpfreaks.com/topic/87534-variable-becomes-empty/#findComment-447742 Share on other sites More sharing options...
garydt Posted January 24, 2008 Author Share Posted January 24, 2008 I only use $chek once the form submitted. Also, I've tried defining $chek at the top of the script and it still becomes empty when the form is submitted. I've also tried making $chek a session variable and I still get the same result. Quote Link to comment https://forums.phpfreaks.com/topic/87534-variable-becomes-empty/#findComment-447763 Share on other sites More sharing options...
trq Posted January 24, 2008 Share Posted January 24, 2008 I only use $chek once the form submitted Yes, but it is still not defined when you try to use it. Variables do not stay in existence over seperate requests. Your logic makes no sense. Quote Link to comment https://forums.phpfreaks.com/topic/87534-variable-becomes-empty/#findComment-447775 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.