how to remove slashes in the php code
Moderator: General Moderators
how to remove slashes in the php code
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.
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.
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
<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
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
<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
Or try
You don't need the quotes around the variable within the PHP <? ?> tags. <?= is short for echo.
Code: Select all
<input type=”text” name “user_id” value ="<?=$user_id?>">- redhair
- Forum Contributor
- Posts: 300
- Joined: Fri May 30, 2003 4:36 pm
- Location: 53.23N-6.57E
- Contact:
Code: Select all
<input type=”text” name “user_id” value ="<?=$user_id?>">Code: Select all
<?php
echo <<< input
<input type="text" name="user_id" value ="$user_id">
input;
?>- redhair
- Forum Contributor
- Posts: 300
- Joined: Fri May 30, 2003 4:36 pm
- Location: 53.23N-6.57E
- Contact:
no...Meteo wrote:could do thatCode: Select all
<?php echo <<< input <input type="text" name="user_id" value ="$user_id"> input; ?>
Parse error: parse error, expecting `','' or `';'' in /var/www/html/test.php on line 2
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
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;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
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
actually, his would work (this time), just not the original one he posted.redhair wrote:That would work if you change <<< form into ", add \ to all " and change form; into ";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;
?>
it's called heredoc, don't say it won't work when you don't know what it is
- redhair
- Forum Contributor
- Posts: 300
- Joined: Fri May 30, 2003 4:36 pm
- Location: 53.23N-6.57E
- Contact:
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.LiLpunkSkateR wrote: it's called heredoc, don't say it won't work when you don't know what it is
But ...I'll admit without shame, that I never seen heredoc before.
(If only the right code was supplied...)
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA