zyra Posted December 6, 2013 Posted December 6, 2013 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!
Ice IT Support Posted December 6, 2013 Posted December 6, 2013 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.
zyra Posted December 6, 2013 Author Posted December 6, 2013 That helped,and now the "code" is being filled,but not completely. The"letter" column is rows of nothing, and it gives this error: Duplicate entry ' -B6' for key 'letter'
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now