Reputation: 338
Hi all Im haveing a small problem with MySql, basically I'm pulling in a variable from a table entitled addressone which is varchar 255! that thing I am trying to achieve is replace the space between the words with a + but for some reason it's not doing that! I have 2 pages one called path.php and another called thanks on my path I have this...
$notokinarray = array(' ');
$okinarray = array('+');
$addressone = $row["addressone"];
$addressone = str_replace($notokinarray, $okinarray, $addressone);
Then I have this in my html of that page
<select name="somesite" id="somesite">
<option value="">Please Choose</option>
<option value="yes">Yes</option>
<option value="no">No</option></select>
http://www.somesite.com/post.php?&field4=<?php echo '$addressone';?>
with a submit button that goes to thanks.php
on my thanks.php page I have this...
$somesite = $_POST['somesite'];
$sql = mysql_query("SELECT * FROM myMembers WHERE id='$id' LIMIT 1");
while($row = mysql_fetch_array($sql)){
$addressone = $row["addressone"];
}
if ($somesite == "yes") {
$somesite = '<iframe src="http://www.somesite.com/post.php?&field4=<?php echo '$addressone';?> width="1" height="1"></iframe>';
} else {
$somesite = '';
}
echo
' . $somesite . '
http://www.somesite.com/post.php?&field4=<?php echo '$addressone';?>
exit();
?>
As far as I am concered all my spaces should be replaces with a + symbol but for some reason its not, can anyone help?
Regards, Phillip
UPDATE
I am going a different tact now and trying to place the + when a User registers but its still no good! check this out.....
$sql = mysql_query("UPDATE myMembers SET field = REPLACE(field, ' ', '+'");
$sql = mysql_query("INSERT INTO myMembers (title, firstname, lastname,username, gender, birthday, email, password, housenumber, addressone, addresstwo, county, city, country, postcode, phone, ipaddress, sign_up_date)
VALUES('$title','$firstname','$lastname','$username','$gender','$full_birthday','$email1','$db_password', '$housenumber','$addressone','$addresstwo', '$county', '$city', '$country','$postcode','$phone','$ipaddress', now())")
or die (mysql_error());
Upvotes: 0
Views: 97
Reputation: 324790
Variables are not interpolated into strings delimited by single quotes. Besides, it is redundant to put it in a string if it is already a string. Just drop the quotes from around echo $addressone
entirely.
That aside, urlencode()
will correctly encode the string for you.
Upvotes: 3