Jump to content

Mistake In Mysql Insert Query?!?


zyra

Recommended Posts

I've been trying to insert something into a table, but no matter what I do, it never works. I've been at it for hours. The whole script looks like this:

$id = $_POST['id'];
mysql_connect("localhost", "zyra_*****", "*******") or die(mysql_error());
mysql_select_db("zyra_sciencefair") or die(mysql_error());
mysql_query("CREATE TABLE $id (
letter varchar(1) COLLATE latin1_general_cs NOT NULL,
code varchar(2) COLLATE latin1_general_cs NOT NULL,
UNIQUE KEY letter (letter,code)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs") or die (mysql_error());
echo("Yes");
$query = "SELECT * FROM Letters";
$queryb = "SELECT Permutations FROM Permutations ORDER BY RAND()LIMIT 1";
$queryc="INSERT INTO `zyra_sciencefair`.$id (letter, code) VALUES ('$entry','$entryb')";
$x=1;
while($x<95){
$result = mysql_query($query) or die(mysql_error());
$resultb = mysql_query($queryb) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
$rowb = mysql_fetch_array($resultb) or die(mysql_error());
$entry = $row['letters'];
$entryb = $rowb['Permutations'];
mysql_query($queryc)or die(mysql_error());
$x=$x+1;
}
?>

 

I have a feeling that $entry is empty, and somehow nothing got passed down to it. And everything works fine until you get to the whiole loop. Please help!

Link to comment
Share on other sites

You are correct, the entry variables are empty in this case. There are two ways to go about this, however the easiest would be to simply move the $queryc declaration to inside the while loop right after you declare $entryb.

 

The second option is to declare and call a function. However, that is a lot more trouble than it's worth in this case.

Link to comment
Share on other sites

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.   Paste as plain text instead

  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...