Solved

PHP / SQL TRIM Statement Help Requested

Posted on 2013-01-30
3
331 Views
Last Modified: 2013-01-31
I've trying to edit my existing code with the TRIM statement & can't get it to work. I have a form users enter information into & submit it to a MySQL database. One of the fields is last_name. If a user types in O'Reilly or Jiu-Jons as a last name or even has trailing blank spaces at the end, I need the TRIM statement to take out the ' or - or the trailing blank space. I've researched:

http://php.net/manual/en/function.stripslashes.php

and am still as lost as a duck in the desert......could someone help me out?

     $strSQL = "INSERT INTO info
     	(last_name)
     	VALUES
     	( '" . $last_name . "')";

Open in new window

0
Comment
Question by:wantabe2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 500 total points
ID: 38837099
Try this:

$token = array("'", "-");
$replacement = "";
$last_name = trim(str_replace($token, $replacement, $last_name));

Open in new window

0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38837427
This is not really an alternative to the suggestions I gave you on the other question.  'mysql_real_escape_string' is designed to prevent SQL injection as well as escaping special characters.  In addition, you will eventually have to rewrite your code to turn off and get rid of "register_globals".

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28013120.html
0
 
LVL 15

Author Closing Comment

by:wantabe2
ID: 38839578
Thanks
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question