Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
|
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 17th, 2007, 05:54 PM
Registered User
 
Join Date: Jan 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default string replace of variable in database

I have a fields in my database that have spaces in them like "New York"

I want them to be able to be called by

states.php?id=newyork // with no space

Here is what I have so far...it's not working at all though:

<?php
            $name4 = str_replace(" ","", $_REQUEST['id']);
            $query='SELECT * FROM states WHERE
state="'.$name4.'"';
            $result= mysql_query($query);
            $myrow=@mysql_fetch_array($result);
            if($myrow)
            {
                $state=$myrow['state'];

            }
            ?>

I thank you all in advance for any help I can get..this forum is great
 
Old December 17th, 2008, 10:01 PM
Registered User
 
Join Date: Dec 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default urlencode and urldecode

You can use:

PHP Code:
<?php
//Safe url
$url urlencode("New York");
echo (
$url);

//Result for your query
$url urldecode($url);
echo (
$url);
?>
Don't forget to secure your $_REQUEST['id'] for SQL injections!
http://en.wikipedia.org/wiki/SQL_injection





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to replace db column name with Global variable nesrine C# 0 March 5th, 2007 10:06 AM
Help in instruction string-replace hugoscp XML 9 October 20th, 2006 12:07 PM
Replace string with a control shenku ASP.NET 1.0 and 1.1 Professional 3 August 22nd, 2005 09:20 AM
replace string value str33ts XSLT 1 April 22nd, 2005 04:01 AM
how to replace a string with another string/number crmpicco Javascript How-To 4 March 14th, 2005 12:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.