Reputation: 572
I'm using PHP to create a dynamic table in my database and store some data in it.
Sometimes when i run the query the table is created and data query is executed but then again if i refresh the query or refresh my page, it shows Error saying table doesn't exist and again if i refresh my page it will load data in 2 or 3 tries.
I'm creating table dynamically and then perform operation on it and at the end I'm dropping the table. Here is my code
<?php
$droptable = "DROP TABLE IF EXISTS temp_post";
if(!mysql_query($droptable))
{echo msql_error();}
$sqlcreatetable = "CREATE TABLE temp_post(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
seq_id INT (6),
name VARCHAR(64) NOT NULL)";
if(!mysql_query($sqlcreatetable))
{
echo " ERROR CREATING TABLE --> ".mysql_error();
}
else{
//query here
}
$sqldel = "DROP TABLE temp_post";
if(!mysql_query($sqldel)){
echo "ERROR DELETING TABLE --> ".mysql_error();
}
?>
I've gone through some other posts and tried the solutions but still its not working properly.Help!!.. CHEERS
Upvotes: 3
Views: 1304
Reputation: 387
Why create and drop anyway?
Use CREATE TEMPORARY TABLE
or just TRUNCATE
the table after use
Upvotes: 1
Reputation: 5679
May be conflicts.. 2 simultaneous requests, so one request can drop table that is used by another request
Try to change CREATE TABLE
to CREATE TEMPORARY TABLE
Upvotes: 1