Jump to content

Random Numbers Changing


Twister1004

Recommended Posts

Ello Everyone!

 

Ok, well I'm making a script with a file uploading thingy, and well, I'm also using a random number to generate a number they must write on a paper and upload it.

 

Issue: I'm experiencing a slight issue with the random numbers though. Once the user uploads their photo with the numbers, I'll send it to my MySQL database. When it gets to that point the random numbers changes, and the numbers will change. I can not find a way to keep it as is, without it changing until the numbers have been placed into the database.

 

//Top part

$array = array();
for($i = 0; $i<5; $i++){
$array[$i] = rand(0,20);
}

$randNum = implode($array);

//HTML part
<form method="post" action="" enctype="multipart/form-data">
				<table>
					<tr>
						<td>
							Generated Number:
						</td>
						<td>
							<h2>
								<?php echo $randNum ?>
							</h2>
						</td>
					</tr>
					<tr>
						<td>
							Group Name:
						</td>
						<td>
							<input type="text" name="group" maxlength="15" />
						</td>
					</tr>
					<tr>
						<td>
							Photo Taken:
						</td>
						<td>
							<input type="file" name="image"/>
						</td>
					</tr>
					<tr>
						<th colspan="2">
							<input name="submit" type="submit" value="Register As An Artist"/>
						</th>
					</tr>
				</table>
			</form>

//SQL Part
if($copied){			
			$createArtist = mysql_query("INSERT INTO `artistregister` (user_id, groupname, photo, randomnum) 
				VALUES ('".$_SESSION['id']."', '".$groupName."', '".$filePath."', '".$thisRandom."')");
			$resetArtist = mysql_query("UPDATE `accounts` SET `isArtist` = '1' WHERE `user_id` = '{$_SESSION['id']}'");
			if($createArtist){
				if($resetArtist){
					echo "Your account is now pending for Artist Access. This could take upto a week.";
					$_SESSION['isArtist'] = 1;
				}
				else{
					echo "There was an error, and it had been recorded. Please try again later.";
					sendError(mysql_error(), $_SERVER['REQUEST_URI']);
				}
			}
			else{
				echo "There was an error, and it had been recorded. Please try again later.";
				sendError(mysql_error(), $_SERVER['REQUEST_URI']);
			}
		}
		elseif(!$copied){
			echo "There was an error, and it has been recorded. Please try again later.";
			sendError("Line 98", $_SERVER['REQUEST_URI']);
		}

 

I've tried looking for different functions, and such, but I'm either not looking in the right place or I'm just making some stupid logical error.

 

Thank you for looking.

Link to comment
Share on other sites

from what I see all you need to do is either pass the random number through the form (probably a bad idea for security reasons it would basically be pointless) or you could save it in a session. Then before the QUERYS do a check to see if the form was submitted and if the number exists in the session, then compare against that. I can tell I'm not seeing all of your code so I'm assuming this is your issue.

Link to comment
Share on other sites

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.