Jump to content

mySQL Hates Me Can't Insert Into Table


munchigum

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
https://forums.phpfreaks.com/topic/284615-mysql-hates-me-cant-insert-into-table/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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