Re: [PHP-DB] Two troublesome fields not inserting

[email protected] (David Robley)
Newsgroups php.db
Message-ID <[email protected]>
Chris wrote:

> Terion Miller wrote:
>> Hi all, I seem to be having a problem with getting two fields to insert
>> into a table, the other fields insert but not these two
>> its from a form that is a duplicate, basically I have a workorder that I
>> want to make a copy of, I call it from the db, populate a form in case
>> changes want to be made, and insert with a new unique ID as a new record,
>> it's working great except Two fields will NOT insert and I'm at a loss
>> for why ...
>> the code is big so I will post snippets that I think may be the trouble
>> spots
>> 
>> Here is the insert:
>>     $sql = "INSERT INTO workorders (CreatedDate, Location, WorkOrderName,
>> AdminID, FormName, Status, Notes) VALUES (";
>>     $sql .= "Now(), '$Location', '$WorkOrderName', '$AdminID',
>>     'WorkOrder',
>> 'New Order', '$Notes')";
>>     mysql_query($sql);
>>     $WorkOrderID = mysql_insert_id();
> 
> My immediate guess is either a single quote or a new line is causing the
> problem.
> 
> You need to escape your data (use mysql_real_escape_string).
> 
And don't forget debugging tools: echo the query and use mysql_error()



Cheers
-- 
David Robley

"I love hot dogs," said Tom with relish.
Today is Sweetmorn, the 51st day of Chaos in the YOLD 3175.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.