Page 1 of 1
how to remove slashes in the php code
Posted: Wed Feb 25, 2004 7:01 am
by Rmias
I have a form that displays user details from the database. If one user is selected from the list using radio buttons and click on edit button the selected user is dispalyed in the edit php and its detail can be edited. What the problem I have is when the user displayed in the edit.php it addes \ at the end of each field .e.g. User Id: 1\
First Name : John\
I used stripslashes() function to remove the slash but it does not work
In the display.php
<tr>
<td>User ID : <? echo “$user_id” ?> </td>
</tr>
<tr>
<td>First Name: <? echo “$first_name” ?> </td>
</tr>
the above displays
User Id: 1
First Name : John
The problem occurs when I click submit and details of the user displayed in the edit.php
<tr>
<td>User ID </td>
<td><input type=”text” name “user_id” value =<? echo “$user_id” ?> <td>
</tr>
<tr>
<td>First Name: </td>
<td><input type=”text” name “first_name” value =<? echo “$first_name” ?> <td>
</tr>
this displayed
User Id: 1\
First Name : John\
Please can some one help me on this thanks.
Posted: Wed Feb 25, 2004 7:57 am
by redhair
Quote your values and use a closing tag!
<input type=”text” name “user_id” value ="<? echo “$user_id” ?>">
not:
<input type=”text” name “user_id” value =<? echo “$user_id” ?>
Posted: Wed Feb 25, 2004 8:48 am
by Rmias
thanks redhair, I tried as you suggested and it works now. However for some strange reason if i do the following it does not work
<input type=”text” name “user_id” value ="<? echo “$user_id” ?>">
but I changed the line to
<input type=”text” name “user_id” value ="
<?
echo “$user_id”
?>
">
and it removes the slash.
Thank you for your help
Posted: Wed Feb 25, 2004 8:53 am
by redhair

a ; is still missing
<input type=”text” name “user_id” value ="<? echo “$user_id”; ?>">
Posted: Wed Feb 25, 2004 8:59 am
by Rmias
thanks redhair, I tried as you suggested and it works now. However for some strange reason if i do the following it does not work
<input type=”text” name “user_id” value ="<? echo “$user_id” ?>">
but I changed the line to
<input type=”text” name “user_id” value ="
<?
echo “$user_id”
?>
">
and it removes the slash.
Thank you for your help
Posted: Wed Feb 25, 2004 8:59 am
by patrikG
Or try
Code: Select all
<input type=”text” name “user_id” value ="<?=$user_id?>">
You don't need the quotes around the variable within the PHP <? ?> tags. <?= is short for echo.
Posted: Wed Feb 25, 2004 9:04 am
by redhair
Code: Select all
<input type=”text” name “user_id” value ="<?=$user_id?>">

There is a = missing to
Posted: Wed Feb 25, 2004 2:17 pm
by Meteo
Code: Select all
<?php
echo <<< input
<input type="text" name="user_id" value ="$user_id">
input;
?>
could do that
Posted: Wed Feb 25, 2004 2:20 pm
by redhair
Meteo wrote:Code: Select all
<?php
echo <<< input
<input type="text" name="user_id" value ="$user_id">
input;
?>
could do that
no...
Parse error: parse error, expecting `','' or `';'' in /var/www/html/test.php on line 2
Posted: Wed Feb 25, 2004 2:24 pm
by Meteo
eh, nice and polite of you too.
it always works for me, i'd usually go about it like this though...
<?php
$form = <<< form
<input type="text" name="user_id" value ="$user_id">
form;
echo $form;
?>
Posted: Wed Feb 25, 2004 2:30 pm
by redhair
Meteo wrote:eh, nice and polite of you too.
it always works for me, i'd usually go about it like this though...
<?php
$form = <<< form
<input type="text" name="user_id" value ="$user_id">
form;
echo $form;
?>
That would work if you change <<< form into ", add \ to all " and change form; into ";
Posted: Wed Feb 25, 2004 2:53 pm
by d3ad1ysp0rk
Code: Select all
echo <<<EOT
<tr>
<td>User ID </td>
<td><input type="text" name="user_id" value=$user_id"></td></tr>
<tr>
<td>First Name: </td>
<td><input type="text" name “first_name" value="$first_name"></td>
</tr>
EOT;
The identifier you use (ie. EOT, or in your case, "input", must NOT be used in the rest of the code. That is why you got the parse error. So use something random (EOT, EOM, 4774, etc).
http://www.php.net/manual/en/language.t ... ax.heredoc
I also noticed some of your HTML was messed up (lack of a equals sign, not closing a tag, using the wrong tag to close it (two <td> tags instead of <td></td>), etc.
Check this out:
http://www.w3schools.com/html/default.asp
Posted: Wed Feb 25, 2004 2:55 pm
by d3ad1ysp0rk
redhair wrote:Meteo wrote:eh, nice and polite of you too.
it always works for me, i'd usually go about it like this though...
<?php
$form = <<< form
<input type="text" name="user_id" value ="$user_id">
form;
echo $form;
?>
That would work if you change <<< form into ", add \ to all " and change form; into ";
actually, his would work (this time), just not the original one he posted.
it's called heredoc, don't say it won't work when you don't know what it is

Posted: Wed Feb 25, 2004 3:10 pm
by redhair
LiLpunkSkateR wrote:
it's called heredoc, don't say it won't work when you don't know what it is

Well, I said it didnt work because I actually tested the code (just copy&pasted)...and got a parse error. So it don't work.
But ...I'll admit without shame, that I never seen heredoc before.
(If only the right code was supplied...)
Posted: Wed Feb 25, 2004 3:58 pm
by d3ad1ysp0rk
ya, like i said, the original one didnt work because the word he used (input) could be found inbetween
ie.
$form = <<<form
<form action="whatever">
<input type="text">
<input type="submit">
</form>
form;
wouldnt work