Trouble creating multiple tables using a loops PHP/SQL DB
I want to know how to create multiple tables using a for loop in php code on a local sql db
i tried using this kind of code which is not working
$sql="CREATE TABLE Hi_$i" (FirstName CHAR(30),LastName CHAR(30),Age INT)";
// Execute query
echo "Table persons created successfully";
echo "Error creating table: " . mysqli_error($con);
Thanks in advance
You are trying to create your table 5 times? Why? Once is sufficient and I'm sure that happened. You could add a 'die' clause to your query and output MySQL_error() when you do to see the error you are getting, but I think you want to re-think what you are doing here.
Oops - didn't notice the variable $I was in the table name. My bad.
Anyway - the die clause would have helped you out. You should look at an example of a query execution to see how it s/b implemented in your querying.
That said - your query statement is bad. Actually if you turn on php error checking (another thing you should always do) it would have pointed you at the query line which has too many double quotes in it.
Well, with the query the way you are showing it, it CANNOT execute. So - if you have made a change AND you have turned on error checking, show us the new code and the exact error message(s) you are receiving.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread