RE: [PHP] Help with SQL Query String
| From: | Jay Blanchard | Date: | Thu, 31 Mar 2005 15:30:00 +0000 |
| Subject: | RE: [PHP] Help with SQL Query String | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-211965@lists.php.net to get a copy of this message | ||
[snip]
You should not just give him the code but rather tell him why.
1. trim() is a php function. MySQL does not know what to do with it. You
need to place it 'outside' of the sql. You can also do something like
this:
$userid = trim($row['USERID']);
Then use $userid in your sql.
2. Items in arrays must be in quotes.
[/snip]
Ya'll bitch when I make them RTFM, ya'll bitch when I do code....what's
a guy to do? j/k
Actually http://dev.mysql.com/doc/mysql/en/string-functions.html
shows
that MySQL also has a trim function which could be applied thusly;
$sql = "INSERT INTO tblname (USERID,FULLNAME,SSN,STARTDATE) ";
$sql .= "VALUES ( ";
$sql .= "TRIM('" . $row['USERID'] . "'), ";
$sql .= "TRIM('" . $row['FULLNAME'] . "'), ";
$sql .= "TRIM('" . $row['SSNO'] . "'), ";
$sql .= "TRIM('" . $row['STARTDATE'] . "') ";
$sql .= ") ";