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
Solved

PHP / SQL TRIM Statement Help Requested

Posted on 2013-01-30
3
324 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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
I have a large data set and a SSIS package. How can I load this file in multi threading?
The viewer will learn how to dynamically set the form action using jQuery.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

861 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