Problem creating mySQL table with php...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
orbdrums
Forum Commoner
Posts: 82
Joined: Wed Sep 14, 2011 11:42 pm

Problem creating mySQL table with php...

Post 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++;
  }
?>
orbdrums
Forum Commoner
Posts: 82
Joined: Wed Sep 14, 2011 11:42 pm

Re: Problem creating mySQL table with php...

Post 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>
Dodon
Forum Commoner
Posts: 64
Joined: Wed Aug 03, 2011 4:11 am
Location: Netherlands

Re: Problem creating mySQL table with php...

Post 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
Post Reply