473,396 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Form field value containing backslash

Hi,

I have recently taken up PHP programming, and I got stuck on the
following.
<?
$p_body = (isset ($_POST['body' ]) && ($_POST['body'] != '')) ?
$_POST['body'] : 'Enter your text here';
$p_name = (isset ($_POST['name' ]) && ($_POST['name'] != '')) ?
$_POST['name'] : 'Enter name';
$p_mail = (isset ($_POST['mail' ]) && ($_POST['mail'] != '')) ?
$_POST['mail'] : 'Enter email';
$output = <<<CODEREH
<form method="POST" action="doform.php">
<p><input type="TEXT" name="name" value="$p_name" /></p>
<p><input type="TEXT" name="email" value="$p_mail" /></p>
<p><input type="TEXT" name="body" value="$p_body" /></p>
<p><input type="SUBMIT" value="Store it!" /></p>
</form>
CODEREH;
$invalid_body=array('','Enter your text here');
$invalid_name=array('','Enter name');
$invalid_mail=array('','Enter email');
if (validate($p_body,$invalid_body) && validate($p_name,$invalid_name)
&& validate($p_mail,$invalid_mail)) // fields not entered correctly
{
//process form data and provide link to continue (or enter another
set of data)
exit;
}
// data not entered correctly
echo "All fields must be entered!";
?>

If either field contains backslashes, they are duplicated when the
form reloads.
Each successive form submission \ becomes \\, \\\\, \\\\\\\\ etc etc

Why does this happen and how do I fix the variables to show the
original data each time?
I know I am a newbie, probably an easy one for this group. Can you
help me out though?

Semi

May 22 '07 #1
2 2353
se*******@inbox.com wrote:
Hi,

I have recently taken up PHP programming, and I got stuck on the
following.
<?
$p_body = (isset ($_POST['body' ]) && ($_POST['body'] != '')) ?
$_POST['body'] : 'Enter your text here';
$p_name = (isset ($_POST['name' ]) && ($_POST['name'] != '')) ?
$_POST['name'] : 'Enter name';
$p_mail = (isset ($_POST['mail' ]) && ($_POST['mail'] != '')) ?
$_POST['mail'] : 'Enter email';
$output = <<<CODEREH
<form method="POST" action="doform.php">
<p><input type="TEXT" name="name" value="$p_name" /></p>
<p><input type="TEXT" name="email" value="$p_mail" /></p>
<p><input type="TEXT" name="body" value="$p_body" /></p>
<p><input type="SUBMIT" value="Store it!" /></p>
</form>
CODEREH;
$invalid_body=array('','Enter your text here');
$invalid_name=array('','Enter name');
$invalid_mail=array('','Enter email');
if (validate($p_body,$invalid_body) && validate($p_name,$invalid_name)
&& validate($p_mail,$invalid_mail)) // fields not entered correctly
{
//process form data and provide link to continue (or enter another
set of data)
exit;
}
// data not entered correctly
echo "All fields must be entered!";
?>

If either field contains backslashes, they are duplicated when the
form reloads.
Each successive form submission \ becomes \\, \\\\, \\\\\\\\ etc etc

Why does this happen and how do I fix the variables to show the
original data each time?
I know I am a newbie, probably an easy one for this group. Can you
help me out though?

Semi
Semi,

You probably have magic_quotes_gpc on in your php.ini file. If so, turn
it off (it defaults to on); it's not good to have.

If this is your hosting company, the first thing I'd recommend is
changing hosting companies. There's no good reason (IMHO) why they
should be running with it on nowadays.

If it is your host and you can't change, to get rid of them, use
stripslashes(). And if you test to see if magic quotes is on, your code
will be more transportable, i.e.

if (get_magic_quotes_gpc())
$body = stripslashes($_POST['body']);

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 23 '07 #2

Simply use this link
http://www.php.net/stripslashes

for stripslashes function.
and access your post-ed data like this:

<input type="text" value="<?php echo stripslashes($p_name); ?>"
name=".... />
satya61229.blogspot.com

semi_e...@inbox.com wrote:
Hi,

I have recently taken up PHP programming, and I got stuck on the
following.
<?
$p_body = (isset ($_POST['body' ]) && ($_POST['body'] != '')) ?
$_POST['body'] : 'Enter your text here';
$p_name = (isset ($_POST['name' ]) && ($_POST['name'] != '')) ?
$_POST['name'] : 'Enter name';
$p_mail = (isset ($_POST['mail' ]) && ($_POST['mail'] != '')) ?
$_POST['mail'] : 'Enter email';
$output = <<<CODEREH
<form method="POST" action="doform.php">
<p><input type="TEXT" name="name" value="$p_name" /></p>
<p><input type="TEXT" name="email" value="$p_mail" /></p>
<p><input type="TEXT" name="body" value="$p_body" /></p>
<p><input type="SUBMIT" value="Store it!" /></p>
</form>
CODEREH;
$invalid_body=array('','Enter your text here');
$invalid_name=array('','Enter name');
$invalid_mail=array('','Enter email');
if (validate($p_body,$invalid_body) && validate($p_name,$invalid_name)
&& validate($p_mail,$invalid_mail)) // fields not entered correctly
{
//process form data and provide link to continue (or enter another
set of data)
exit;
}
// data not entered correctly
echo "All fields must be entered!";
?>

If either field contains backslashes, they are duplicated when the
form reloads.
Each successive form submission \ becomes \\, \\\\, \\\\\\\\ etc etc

Why does this happen and how do I fix the variables to show the
original data each time?
I know I am a newbie, probably an easy one for this group. Can you
help me out though?

Semi
May 25 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Giles | last post by:
If rs("MyString") is Hello "Jim" Lad <input type=text value="<%=rs("MyString")%>"> prints as <input type=text value=" Hello "Jim" Lad"> How can I get double quotes to display in a text box...
3
by: Steve Wright | last post by:
I want to build an email subject containing text and a form field. Have have got so far but all I seem to be able to do is generate another page in the browser with a text string. (code attached)...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
5
by: Raffi | last post by:
Hi folks, I'm new to JavaScript and need some help. I have a form with a select field. Depending on what is selected in this field, I want to display or not display another select field. For...
1
by: googleboy | last post by:
Hi. I am writing up my own web form. I'm a bit of a newb, and read up many different how-tos and examples and documentaion. I finally had it working just great until I decided that I wanted to...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
1
by: longtim | last post by:
I have been having endless difficulty creating reports/queries that set any relevent parameters from controls in forms. I am creating an application under access 2003 but will target access...
4
by: Cerebral Believer | last post by:
Hi I need help! Forgive me I am a PHP newbie. I have a small script that enables me to send a form from an HTML page. I want to use the HTML formatted form because the design of my website is...
4
by: zufie | last post by:
I have a main form containing a command SEND button that prompts an email form to pop up. The email address(es) that are supposed to appear on the email form are those corresponding to the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.