PHP Insert Query Problems
$tSession = session_id();
$query = "INSERT INTO usersession (SessionID) VALUES ('$tSession')";
$result = mysql_query($query) or die ("Couldn't Execute Query 1");
//from index down to } is a while loop that generates 15 unique random numbers, these numbers will then be stored in the database.
$index[0] = "0";
for ($n=1; $n < 16; $n++)
{
$rand = mt_rand(1, 200);
While( array_search($rand, $index) )
$rand = mt_rand(1, 200);
$query = "UPDATE usersession SET $n='$index[$n]' WHERE SessionID='$tSession'";
$result = mysql_query($query) or die ("Couldn't Execute Query 2");
$index[$n] = $rand;
echo "$n: $index[$n]<br>";
}
Ok so I am creating a quiz that will need to ask questions at random while ensuring the random numbers aren't duplicating, this works fine, the probelm I am having is with the UPDATE query.
I have 15 columns lablled 1, 2, 3, 4, 5... 15. So what I want to do is insert the randomly generated unique number into the table, $n='$index[$n]' is where the coding is falling down.
What am I doing wrong? I'm sure its just a simple error involving " or ' missing but I can't find any info on it.
Subject
Written By
Posted
PHP Insert Query Problems
May 24, 2005 05:15AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.