Jump to content

mySQL Hates Me Can't Insert Into Table


munchigum
 Share

Recommended Posts

I'm trying to insert two variables into a table, but the first field always ends up empty, while the second one turns out correct. 

 

The entire script goes:

<?php

$id = $_POST['id'];

mysql_connect("localhost", "*****", "******") or die(mysql_error());
mysql_select_db("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());


$key = rand(1,146);

$x=1;
while($x<95){

$result = mysql_query("SELECT * FROM Letters");
$row = mysql_fetch_array($result);
$entry =$row['letters'];

$queryb = "SELECT * FROM Permutations WHERE Number=$key";
$resultb = mysql_query($queryb) or die(mysql_error());
$rowb = mysql_fetch_array($resultb) or die(mysql_error());
$entryb = $rowb['Permutations'];

$queryc="INSERT INTO $id(letter,code) VALUES ('$entry','$entryb')";
mysql_query($queryc)or die(mysql_error());

$x=$x+1;
$key = $key+1;
}

?>

The column "letter" is always empty, but I'm sure that $entry has values in it!

 

Please help, this is for a science fair project that's due in two days.

Link to comment
Share on other sites

This thread is more than a year old.

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

  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.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.