/    Sign up×
Community /Pin to ProfileBookmark

Anyone seen anything like this variable values?

So I have a textarea. The page is getting processed in itself. This is what I put in the textarea

[quote]

This is a demo thing blah blah bhalhjsdlfjlasdfjlasdhf;lkjasdf.js.dvnlasndvlasndf;.lnsa.nfclasjThis is a demo thing blah blah bhalhjsdlfjlasdfjlasdhf;lkjasdf.js.dvnlasndvlasndf;.lnsa.nfclasjThis is a demo thing blah blah bhalhjsdlfjlasdfjlasdhf;lkjasdf.js.dvnlasndvlasndf;.lnsa.nfclasj
.<>,./!@#$!@%#&^$&

[/quote]

exactly as you see it.

I have this code running

[code=php]
printf(“artdescrips: “.$_POST[‘artdescrip’].”<br />n”);
printf(“Hi mom!”);
[/code]

and i see

[quote]

artdescrips:
Hi mom!

[/quote]

when nothing is posted to the page and I only see

[quote]

Hi mom!

[/quote]

when soemthing gets posted to the page.

Below are my escape function and how i generate my textarea. Does anyone know what’s going on the value of the this field when i submit the page? I’m stumped, it works fine without: “.<>,./!@#$!@%#&^$&” but does this with it.

[code=php]
printf(”
<form action=”index.php” method=”post”>n
<label for=”title”>Title:</label><input type=”text” name=”title” size=”25″ maxlength=”150″ value=””.stripslashes($_POST[‘title’]).”” /><br />n
<label for=”pages”>Number of Pages:</label><input type=”text” name=”pages” size=”3″ maxlength=”3″ value=””.stripslashes($_POST[‘pages’]).”” /><br />n
<label for=”artdescrip”>Brief Description:</label><textarea name=”artdescrip” rows=”3″ cols=”80″ wrap=”soft”>”);
printf($_POST[‘artdescrip’]);
printf(“</textarea><br />n
<input type=”submit” name=”add_art” value=”begin adding article” /><input type=”reset” name=”reset” value=”reset”>n
</form>
“);

function escape($text){
if (get_magic_quotes_gpc()){
$text=stripslashes($text);
}
return mysql_real_escape_string($text);
}
[/code]

escape appears at the top of the page, btw, and no, the $_POST[‘artdescrip’] doesn’t populate in the textarea as I want it to.

And to clarify, in summary.

When I post to this page, with the string above, it seems that the value of $_POST[‘artdescrip’] is somehow interfering with functions using it.

Edit: and now when i think of it, the escape function is completely irrelevant to the situation.

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@SpectreReturnsDec 20.2005 — Do a dump of $_POST and see what it brings up. We'll work from there.
Copy linkTweet thisAlerts:
@NogDogDec 20.2005 — Try using this function instead of stripslashes() when outputting post vars:
[code=php]
function output_post($text)
{
if(get_magic_quotes_gpc())
{
$text = stripslashes($text);
}
return(htmlentities($text));
}
[/code]
Copy linkTweet thisAlerts:
@chazzyauthorDec 20.2005 — sorry NogDog that didn't work.

here's var_dump($_POST)
<i>
</i>array(4) {
["title"]=&gt;
string(26) "asdfljsalkfjalsdjfljsdflkj"
["pages"]=&gt;
string(1) "2"
["artdescrip"]=&gt;
string(354) "sadlfjkalsdjr/wkej@#$@!#%!$#@^Q#$%^A$WEZTRZDS&lt;&gt;
This is a demo thing blah blah bhalhjsdlfjlasdfjlasdhf;lkjasdf.js.dvnlasndvlasndf;.lnsa.nfclasjThis is a demo thing blah blah bhalhjsdlfjlasdfjlasdhf;lkjasdf.js.dvnlasndvlasndf;.lnsa.nfclasjThis is a demo thing blah blah bhalhjsdlfjlasdfjlasdhf;lkjasdf.js.dvnlasndvlasndf;.lnsa.nfclasj
.&lt;&gt;,./!@#$!@%#&amp;^$&amp;"
["add_art"]=&gt;
string(20) "begin adding article"
}


which is exactly what i thought it would be. it seems to be a problem with pulling up the actually data.
Copy linkTweet thisAlerts:
@NogDogDec 20.2005 — Hmmm....this worked OK for me, a few stylistic changes - maybe you'll see something different?
[code=php]
function output_post($text)
{
if(get_magic_quotes_gpc())
{
$text = stripslashes($text);
}
return(htmlentities($text));
}
printf("
<form action='index.php' method='post'>n
<label for='title'>Title:</label><input type='text' name='title' size='25' maxlength='150' value='%s' /><br />n
<label for='pages'>Number of Pages:</label><input type='text' name='pages' size='3' maxlength='3' value='%s' /><br />n
<label for='artdescrip'>Brief Description:</label><textarea name='artdescrip' rows='3' cols='80' wrap='soft'>%s</textarea><br />n
<input type='submit' name='add_art' value='begin adding article' /><input type='reset' name='reset' value='reset'>n
</form>",
output_post($_POST['title']),
output_post($_POST['pages']),
output_post($_POST['artdescrip'])
);
[/code]
Copy linkTweet thisAlerts:
@chazzyauthorDec 20.2005 — hmmm

that works.

then again I'm not familiar with the %s replace syntax and how it works, so I guess my question is why does it work?

but thanks for the pointer.

Edit: ok

this doesn't work.
[code=php]
$descrip = output_post($_POST['artdescrip']);
printf($descrip);[/code]
Copy linkTweet thisAlerts:
@NogDogDec 20.2005 — Any difference if you just use echo or print instead of printf?
Copy linkTweet thisAlerts:
@chazzyauthorDec 20.2005 — yeah actually echo and print seem to have worked fine.

the only thing i can guess, based off of the info in sprintf (http://php.net/manual/en/function.sprintf.php) is that my input somehow meets some formatting guideline, and it's waiting for the variables, gets none so ntohing is printed.
Copy linkTweet thisAlerts:
@NogDogDec 20.2005 — I suppose if there's some reason to use printf(), then just do:
[code=php]
printf("%s", $variable);
[/code]

But there's really no reason to use it unless you're going to use the formatting string capabilities.
Copy linkTweet thisAlerts:
@chazzyauthorDec 20.2005 — I suppose if there's some reason to use printf(), then just do:
[code=php]
printf("%s", $variable);
[/code]

But there's really no reason to use it unless you're going to use the formatting string capabilities.[/QUOTE]


yeah. it's just been one of those quirks i've always had, i just always use printf, not sure why, it was probably the first function i saw that printed and stuck with it.

probably the same reason why when i'm writing servlets I always write System.out.println() even when I know it's wrong. oh well, thanks for the pointers.
×

Success!

Help @chazzy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...