Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP / SQL TRIM Statement Help Requested

Posted on 2013-01-30
3
Medium Priority
?
334 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 2000 total points
ID: 38837099
Try this:

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

Open in new window

0
 
LVL 84

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

664 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