Nested SQL Not even sure if it's correct...

This code outputs $stat . has been registered to $cat on mytb1 me even when i know the only possible option is on mytbl2

I’m getting very irritated, as I’ve been working on this for about 5 hours with different combinations and iterations.

[php]
$sql=“UPDATE mytbl1 SET $cat=’$stat’, $image=’$file’ WHERE username=’$user’ AND toonname=’$toon’ AND server=’$server’”;
if (mysql_query($sql,$con))
{

										if (file_exists("../upload_img/" . $_FILES["file"]["name"]))
											{
												echo $_FILES["file"]["name"] . " already exists. ";
												echo "<a href='upload.php'><h1>Retry your Upload</h1></a>";
											}	else {
												  move_uploaded_file($_FILES["file"]["tmp_name"],
												  "../upload_img/" . $_FILES["file"]["name"]);
												  echo $stat . " has been registered to " . $cat . " on mytbl1<br />";
												  echo $image . " uploaded: SUCCESS!";
												  echo "<a href='../login/myprofile.php'><h1>Return to My Profile</h1></a>";
												  
											}
									} else {
											$sql="UPDATE mytbl2 SET `$cat`='$stat', `$image`='$file' WHERE username='$user' AND toonname='$toon' AND server='$server'";	
											if (mysql_query($sql,$con)) {
										
												if (file_exists("../upload_img/" . $_FILES["file"]["name"]))
													{
														echo $_FILES["file"]["name"] . " already exists. ";
														echo "<a href='upload.php'><h1>Retry your Upload</h1></a>";
													}	else {
														  move_uploaded_file($_FILES["file"]["tmp_name"],
														  "../upload_img/" . $_FILES["file"]["name"]);
														  echo $stat . " has been registered to " . $cat . " on mytbl2<br />";
														  echo $image . " uploaded: SUCCESS!";
														  echo "<a href='../login/myprofile.php'><h1>Return to My Profile</h1></a>";													  
														}
											} else {											
												echo "<h1>Error</h1>";
												}
										}

[/php]

I want it to search both tables, they are identical but different names (UNION works), then post the information in the unique location based on (WHERE) $user, $toon, and $server

Sponsor our Newsletter | Privacy Policy | Terms of Service