munchigum Posted December 7, 2013 Share Posted December 7, 2013 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. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted December 8, 2013 Share Posted December 8, 2013 Print out some error checking in your while loop... while ($x < 95) { ... print '<pre>'; ...... print '\nrow:\n' . print_r($row, 1); .... print "\n rowb: \n" . print_r($rowb, 1); .... print "\n Final insert query is: \n"; print $queryc Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted December 8, 2013 Share Posted December 8, 2013 (edited) Read what you wrote wrong Edited December 8, 2013 by QuickOldCar Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.