Solved

PHP / SQL TRIM Statement Help Requested

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
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.

726 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