Page 1 of 1

Problem creating mySQL table with php...

Posted: Wed Oct 26, 2011 10:57 pm
by orbdrums
Hi all,
The following code is giving me fits. I'm sure it's my syntax that is incorrect but I don't know where. Any help would be greatly appreciated.

Code: Select all

<?php
$query_users = "SELECT * FROM Users.members";
$result = mysql_query($query_users);

$r_n = 1;
while ($row = mysql_fetch_assoc($result)) 
  {
	$mbr_log = $row[`login`];	
        echo $r_n," ",$row['login'],"<br />";
	[color=red]mysql_query("CREATE TABLE Contacts.'$mbr_log' SELECT * FROM Contacts.AB_Macbook")[/color]
      //echo "&nbsp;&nbsp;";
      //echo "<td>",$row['login_time'];
      //echo "&nbsp;&nbsp;";
        $r_n++;
  }
?>

Re: Problem creating mySQL table with php...

Posted: Wed Oct 26, 2011 11:05 pm
by orbdrums
The span tag in my first post doesn't exist in my code. It was put in by this site when I tried to change the font color of the suspect line of code to red. Here is my code:

Code: Select all

<?php
$query_users = "SELECT * FROM Users.members";
$result = mysql_query($query_users);

$r_n = 1;
while ($row = mysql_fetch_assoc($result)) 
  {
	$mbr_log = $row[`login`];	
        echo $r_n," ",$row['login'],"<br />";
	mysql_query("CREATE TABLE Contacts.'$mbr_log' SELECT * FROM Contacts.AB_Macbook")
      //echo "&nbsp;&nbsp;";
      //echo "<td>",$row['login_time'];
      //echo "&nbsp;&nbsp;";
        $r_n++;
  }
?>

</body>

Re: Problem creating mySQL table with php...

Posted: Thu Oct 27, 2011 8:35 am
by Dodon
Not sure if it matters but

Code: Select all

$mbr_log = $row[`login`];
 
doesn't have proper single quotes.

Second you don't need the single quotes in the query, if I try the query directly in phpmyadmin it complains about the singlequote so try:

Code: Select all

mysql_query("CREATE TABLE Contacts.$mbr_log SELECT * FROM Contacts.AB_Macbook");
 
Also your query was missing a ; at the end of the line