Solved

PHP / SQL TRIM Statement Help Requested

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

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 82

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
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.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now