PHP and passing variables
Hello ppl, I'm kind of new to PHP and I've run into a problem with my slashes.
I have a script (newarticle.php) which accepts input for 5 values, then passes those values to itself, prints the contents and asks for confirmation, then calls itself again with those variables and inserts the new values into a MySQL database 'furycms'.
My problem lies with passing the variables across the last time. The piece of code that is being a problem in particular is this form, where I dump the variables as hidden form values so the user can confirm the values and either pass them along or cancel.
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
printf("<input type=\"hidden\" name=\"category\" value=\"%s\">", $category);
printf("<input type=\"hidden\" name=\"type\" value=\"%s\">", $type);
printf("<input type=\"hidden\" name=\"title\" value=\"%s\">", $title);
printf("<input type=\"hidden\" name=\"description\" value=\"%s\">", $description);
printf("<input type=\"hidden\" name=\"filename\" value=\"%s\">", $filename);
?>
<input type="hidden" name="confirmed" value="yes">
<input type="submit" name="submit" value="Add article to database">
</form>
<form action="newarticle.php" method="post">
<input type="submit" name="submit" value="Cancel">
</form>
The problem is, anytime I put a value into the printf() function I lose everythign in quotes. I have tried every combo of stripslashes()/addslashes() but I think it's just a problem with the method itself.
Would it be best to implement a session to get this done? How would you approach this, maybe by making new values equal to the ones passed along, or if I simply create a session will form-submitted values be persistent?
Thank you in advance, I hope this made sense :rolleyes: