Hi all,
I am currently having a syntax error problem with a bit of php code I made with a for loop. I have the tables in my database: class1, class2, class3,..., class10. On one page I have 10 textfields for each class of games users want to see, and when they submit, it should store their text into c1_classname, c2_classname, ..., c10_classname.
Here is my code, it's a simple for loop, it's just I don't know how to incorporate the $x into my syntax:
// check if class exists
for ($x=1; $x<=10; $x++)
{
$query = "SELECT c$x_id from class$x WHERE c$x_id = " . $idiot["id"];
$result = mysql_query($query);
if ($tmp = mysql_fetch_row($result)) // class exists, update it
{
$query = 'UPDATE class$x
SET c$x_id = '.$idiot['id'].',
c$x_username = "'.$_SESSION['username'].'",
c$x_classname = "'.$_POST['c$x'].'"
WHERE
c$x_id = '.$idiot['id'].'';
mysql_query($query) or die(mysql_error());
}
else // class does not exist, add new class
{
$query = 'INSERT INTO class$x(
c$x_id,
c$x_username,
c$x_classname)
VALUES (
'.$idiot['id'].',
"'.$_SESSION['username'].'",
"'.$_POST['c$x'].'")';
}
mysql_query($query) or die(mysql_error());
}
Thanks a ton!
-influx.