This topic is locked

Saving data to a different table

8/5/2008 10:44:22 AM
PHPRunner General questions
author

Help again,
I'm trying to save data from table a to table b. I'm using the following

//** Save new data in another table ****

global $conn,$strTableName;
$strSQLSave = "INSERT INTO events1 (Code,Price) values (";
$strSQLSave .= $values["Code"].",";

$strSQLSave .= $values["Individual_Amount"];
$strSQLSave .= ")";

db_exec($strSQLSave,$conn);
return true;

// return true if you like to proceed with adding new record


The problem is field "Code" will only except numbers. If I enter numbers it all works great. In the data base the field is set to varchar.
Question: Do I set all the fields to $values when trying to save new data in another table? What is $message and $inline used for? I have Calendar dates that I will have to save in the new table, what do I set those fields to?
Jane if you answer this...you helped me out on another problem and I tried to transfer that knowledge over to this but I'm having some issues. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=9203&image=1&table=forumtopics' class='bbc_emoticon' alt=':(' />
Thank you!!!

J
Jane 8/6/2008

Hi,
add single quotes around text and date fields in the SQL query.

Here is a sample:

insert into TableName (NumberField, TextField, DateField) values (1,'some text','2008-08-06')


$strSQLSave = "INSERT INTO events1 (Code,Price) values ('";

$strSQLSave .= $values["Code"]."',";

$strSQLSave .= $values["Individual_Amount"];
$strSQLSave .= ")";