Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can i insert data into a temporary table?

Status
Not open for further replies.

rhodesia

Programmer
Nov 21, 2001
2
GR
i'd like to know if and how i can insert data into a temporary table.

Is it the same way as you insert into a normal table?

This is what i've done.(Using mysql and PHP)


$create="CREATE TEMPORARY TABLE temp_table ( id INT(10),name varchar(50), type varchar(30), category varchar(5) )";

$result_create=mysql_query($create,$conn)


$create_upload="INSERT INTO temp_table (id, name, type, category) VALUES ($id,$name1, $hotel1, $category1)";
$result_upload=mysql_query($create_upload,$conn)

I am pretty sure my syntax is correct.But it shows me an error in the INSERT part.
 
Try this instead:
Code:
$create_upload = "INSERT INTO temp_table";
$create_upload .= " (id, name, type, category)";
$create_upload .= " VALUES (";
$create_upload .= "'".$id."'";
$create_upload .= ",'".mysql_escape_string($name1)."'";
$create_upload .= ",'".mysql_escape_string($hotel1)."'";
$create_upload .= ",'".mysql_escape_string($category1)."'";
$create_upload .= ")";

-Rob
 
Thanks Rob.
My error was i didnt put single quotes around the string values.
 
Don't forget the
Code:
mysql_escape_string
functions, which will prevent errors if you try and insert a string containing one or more single quotes (or other nasties).

-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top