Page 1 of 1

Help with a bit of PHP

Posted: Sat Apr 27, 2019 3:01 am
by netmaestro
I'm trying to call a php script with 3 parameters. I'm trying to do it like this:
echo "<form method='post' action='newsale.php?cost='.$cost.'&id='.$id.'&details='.$details>";
and it just dies. Doesn't do anything. I was once quite strong in this stuff but I haven't seen it for four years now and I'm rusty. And confused. Seems to me this ought to work. Can someone tell me:

a) why it fails
b) am I even going about it in the right manner
c) how the (*!!??%%) am I going to pass these 3 parameters to the script with no fuckups

Anyone who can shed light or help with this, I will be in your debt. I've been on these boards for 14 years and I know one thing above all: some of the brightest lights on the planet are right here. So I'll relax knowing that someone will point me in the right direction. Thanks so much.

Re: Help with a bit of PHP

Posted: Sat Apr 27, 2019 4:12 am
by RASHAD
Hi NM,

You were actually closing off the attribute instead of the entire echo before appending your vars. This should fix it:

Code: Select all

echo "<form method='post' action='newsale.php?cost=".$cost."&id=".$id."&details=".$details."'>";
You could instead opt for using a header call instead of echoing out a form, depending on what it is exactly you're trying to do:

Code: Select all

header("Location:newsale.php?cost=$cost&id=$id&details=$details");

Rashad Junior.

Re: Help with a bit of PHP

Posted: Sat Apr 27, 2019 4:40 am
by netmaestro
Thank you so much RASHAD. In a few hours I'll be where I can test. What is your rank on these boards? If it's less than 'Expert' I'll speak with Fred.

Re: Help with a bit of PHP

Posted: Sat Apr 27, 2019 8:39 am
by #NULL
There is still a ." missing in RASHAD's first snippet, must be $details."'>";
But I would rather use input fields for all parameters. You can use hidden fields, too.

Code: Select all

$id = 111;
$cost = 2.22;
$details = "Our whole wheat bread has a rich wheat flavour with a hint of molasses.";

print '<pre>$_POST:' . print_r($_POST, true) . '</pre>';
print '<pre>$_GET:' . print_r($_GET, true) . '</pre>';

echo "<form method='post' action='test.php'>";
echo "<input type='hidden' name='id' value='".$id."' />";
echo "<input type='text' name='cost' value='".$cost."' />";
echo "<input type='text' name='details' value='".$details."' />";
echo "<input type='submit' name='submit' />";
echo "</form>";