Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/87534-variable-becomes-empty/
Share on other sites

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.