Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
PHP
<?php
$con = mysql_connect("localhost","root","");
   		mysql_select_db("textile");
		if (!$con)
		{
			die('Could not connect: ' . mysql_error());
		}

$temp_table=rand(1000,9999);
$sql="CREATE TABLE $temp_table(FirstName CHAR(30),LastName CHAR(30),Age INT)";

// Execute query
if (mysql_query($con,$con))
  {
  echo "Table persons created successfully";
  }
else
  {
  echo "Error creating table: " . mysqli_error($con);
  }

?>


but not created please help..
Posted
Updated 29-Mar-14 5:12am
v2
Comments
CHill60 29-Mar-14 11:11am    
Any error message?
Peter Leow 29-Mar-14 12:04pm    
Do you understand your code?

1 solution

Why would you do that? why would you create table with random name?

by the way, change your sql like below:
PHP
$sql="CREATE TABLE `".$temp_table."`(FirstName VARCHAR(30),LastName VARCHAR(30),Age INT)";//no unique id??

and correct your mysql_query function like this:


PHP
mysql_query($sql,$con);//you wrote: mysql_query($con,$con)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900