I have a PHP-driven HTML form which is supposed to insert a user profile into a database. The weird thing is it appears to be insterting the profiles half the time. Sometimes they add just fine, and sometimes they don't. The other aspects of the if{ } statements are executing just fine.. i.e. if the user is accepted they're supposed to get a "welcome" email and that is being sent out just fine. Also, image files are being copied a-ok.
The loop being used to insert the profiles is shown below. The HTML form which submits to this script has two radio buttons, named $userid so that the form recieves $30 = "accept" or $30="reject" etc when user 30 is processed. (I hope that makes sense? It's basically just a variable variable thing).
Anybody ever dealt with HTML forms that submit only half of the time before? Could it be a SQL hangup?
Anyhow, here's the code:
***
$highestnumquery = mysql_query("SELECT MAX(userid) FROM temp");
$myrow = mysql_fetch_array($highestnumquery);
$highestnum = $myrow["MAX(userid)"];
for ($i=0;$i<=$highestnum;$i++) {
if ($$i){
// ACCEPTED USER: ADDED TO PERMANENT TABLE, REMOVED FROM TEMP TABLE
if($$i == 'accept') {
$result = mysql_query("SELECT * FROM temp WHERE userid=$i");
$myrow = mysql_fetch_array($result);
$username = $myrow["username"];
$gender = $myrow["gender"];
$gendertemp = $gender . "temp";
$password = $myrow["password"];
$location = $myrow["location"];
$email = $myrow["email"];
$aim = $myrow["aim"];
$icq = $myrow["icq"];
$sitelink = $myrow["sitelink"];
$interests = $myrow["interests"];
$addresult = mysql_query ("INSERT INTO users
(gender, username, password, location, email, aim, icq, sitelink, interests)
VALUES ('$gender', '$username', '$password', '$location', '$email', '$aim',
'$icq', '$sitelink', '$interests')");
$deleteresult = mysql_query ("DELETE FROM temp WHERE userid=$i");
echo ("User $i was accepted.");
// MOVES THE USER PICTURE TO THE PERMANENT GALLERY
$move_command=EscapeShellCmd("mv ".$gendertemp."/".$username.".jpg ".
$gender."/".$username.".jpg");
exec($move_command); // move the image
$delete_command=EscapeShellCmd("rm ".$gendertemp."/".$username.".jpg");
exec($delete_command); // move the image
// REJECTED USER: REMOVED FROM TEMP TABLE ONLY
} elseif($ii='reject') {
$result = mysql_query("SELECT * FROM temp WHERE userid=$i");
$myrow = mysql_fetch_array($result);
$username = $myrow["username"];
$gender = $myrow["gender"];
$gendertemp = $gender . "temp";
$deleteresult = mysql_query("DELETE FROM temp WHERE userid=$i");
echo ("User $i was rejected.<br>\n");
$delete_command=EscapeShellCmd("rm ".$gendertemp."/".$username.".jpg");
exec($delete_command); // move the image
// IGNORE: NOTHING DONE
}
}
}
The loop being used to insert the profiles is shown below. The HTML form which submits to this script has two radio buttons, named $userid so that the form recieves $30 = "accept" or $30="reject" etc when user 30 is processed. (I hope that makes sense? It's basically just a variable variable thing).
Anybody ever dealt with HTML forms that submit only half of the time before? Could it be a SQL hangup?
Anyhow, here's the code:
***
$highestnumquery = mysql_query("SELECT MAX(userid) FROM temp");
$myrow = mysql_fetch_array($highestnumquery);
$highestnum = $myrow["MAX(userid)"];
for ($i=0;$i<=$highestnum;$i++) {
if ($$i){
// ACCEPTED USER: ADDED TO PERMANENT TABLE, REMOVED FROM TEMP TABLE
if($$i == 'accept') {
$result = mysql_query("SELECT * FROM temp WHERE userid=$i");
$myrow = mysql_fetch_array($result);
$username = $myrow["username"];
$gender = $myrow["gender"];
$gendertemp = $gender . "temp";
$password = $myrow["password"];
$location = $myrow["location"];
$email = $myrow["email"];
$aim = $myrow["aim"];
$icq = $myrow["icq"];
$sitelink = $myrow["sitelink"];
$interests = $myrow["interests"];
$addresult = mysql_query ("INSERT INTO users
(gender, username, password, location, email, aim, icq, sitelink, interests)
VALUES ('$gender', '$username', '$password', '$location', '$email', '$aim',
'$icq', '$sitelink', '$interests')");
$deleteresult = mysql_query ("DELETE FROM temp WHERE userid=$i");
echo ("User $i was accepted.");
// MOVES THE USER PICTURE TO THE PERMANENT GALLERY
$move_command=EscapeShellCmd("mv ".$gendertemp."/".$username.".jpg ".
$gender."/".$username.".jpg");
exec($move_command); // move the image
$delete_command=EscapeShellCmd("rm ".$gendertemp."/".$username.".jpg");
exec($delete_command); // move the image
// REJECTED USER: REMOVED FROM TEMP TABLE ONLY
} elseif($ii='reject') {
$result = mysql_query("SELECT * FROM temp WHERE userid=$i");
$myrow = mysql_fetch_array($result);
$username = $myrow["username"];
$gender = $myrow["gender"];
$gendertemp = $gender . "temp";
$deleteresult = mysql_query("DELETE FROM temp WHERE userid=$i");
echo ("User $i was rejected.<br>\n");
$delete_command=EscapeShellCmd("rm ".$gendertemp."/".$username.".jpg");
exec($delete_command); // move the image
// IGNORE: NOTHING DONE
}
}
}