View Full Version : can use POST and GET methods at same time?
JaeSun
11-17-2004, 12:20 AM
you can do that in forms right?
like, you have:
page1.php?module=home
which contains a form that calls itself ... and has a text box named "name"
and in the form, uses the GET method
so in the php
you can $_REQUEST['module'] and $_REQUEST['name']
?
IKLOP
11-17-2004, 01:17 AM
Yep, you can do that:
<form action="page1.php?module=home" method="POST">
<input type="text" name="name">
<input type="submit" name="submit" value="submit">
</form>
scoutt
11-18-2004, 08:52 AM
but it is not suggested.
it can bring in problems. you should be all POST or ALL GET, not both.
also you should not be using $_REQUEST. that leaves you open to hacking. _REQUEST also holds POST, GET, FILES, and COOKIE. but since version 4.3 FILES has been taken out.
JaeSun
11-18-2004, 12:00 PM
oh, cuz the setup i have is:
you have a page which lists all the list of stuff that you can view, edit, delete, add, etc.
if you click on edit, the link is like this:
edit.php?name=Whatever&id=24
i have various sections, and they all use this same thing (so in edit.php, i have some if statements to check which section it is (name=) and which particular thing you want to edit (id=)
but first of all, it asks you to confirm it first, and thats what the hidden variable in the form is ....yes and no .... so from there, it calls itself (edit.php?name=Whatever&id=24 and along with the POST variable of yes and no) and does what it needs to do ....
i read somewhere that you should keep anything thats editing the actual database to the POST method, and if your just viewing stuff, then to use GET ...
so thats why i did it that way ...
also so people just cant type that address in and accidentally delete it right away?
and ill change all my _REQUEST then in the meantime ...
but i didnt really wnat to create multiple pages to do a few things when i thought i could just use the same page for everything?
scoutt
11-18-2004, 12:05 PM
yes you can use the samepage for everything.
instead of this
edit.php?name=Whatever&id=24
you add that to the hideen input only if they edit. if they view then sure, keep it in the url. but IE does bug out with a mix.
JaeSun
11-18-2004, 12:23 PM
ok. grr, gotta do some recoding, lol ...
thanks
JaeSun
11-18-2004, 06:16 PM
ok, so i would change this: (my current code)
<?php
echo '<p class="bold">Delete a News Item</p>' . "\n";
$deleteID = $_REQUEST['id'];
$deleteFROM = $_REQUEST['name'];
if ($_REQUEST['confirm'] == 'yes')
{
$query = "DELETE FROM satNews WHERE (newsID='$deleteID')";
$result = mysql_query($query) or die("Delete failed because of: " . mysql_error());
if ($ifDelete = mysql_affected_rows())
{
if ($ifDelete == 1)
{
echo '<p>Delete was successful.</p>';
echo '<p>If you would like to delete another news bit, <a href="module.php?name=news">click here</a><br />';
echo 'otherwise, go back to the <a href="main.php">Administration Home Page</a></p>';
}
else if ($ifDelete > 1 || $ifDelete < 1)
{
echo '<p>Deleting the news bit was <span class="bold">NOT</span> successful.<br />';
echo 'Please try again (hit the back button, or start over by <a href="module.php?name=news">clicking here</a></p>';
echo $ifDelete;
}
}
else
{
echo '<p>Nothing Happened?</p>';
echo $ifDelete;
}
}
else if ($_REQUEST['confirm'] == 'no')
{
echo '<p>The News Bit was <span class="bold">NOT</span> Deleted.';
echo '<p>If you would like to delete another news bit, <a href="module.php?name=news">click here</a><br />';
echo 'otherwise, go back to the <a href="main.php">Administration Home Page</a></p>';
}
else
{
print <<<endConfirm
<form method="post" action="delete.php?name=news&id=$deleteID">
<p>Are you sure you want to delete this news bit ?</p>
<input type="submit" class="form" name="confirm" id="confirm" value="yes" /> <input type="submit" class="form" name="confirm" id="confirm" value="no" />
</form>
endConfirm;
}
?>
to this:
<?php
echo '<p class="bold">Delete a News Item</p>' . "\n";
$deleteID = $_REQUEST['id'];
$deleteFROM = $_REQUEST['name'];
if ($_POST['confirm'] == 'yes')
{
$query = "DELETE FROM satNews WHERE (newsID='$deleteID')";
$result = mysql_query($query) or die("Delete failed because of: " . mysql_error());
if ($ifDelete = mysql_affected_rows())
{
if ($ifDelete == 1)
{
echo '<p>Delete was successful.</p>';
echo '<p>If you would like to delete another news bit, <a href="module.php?name=news">click here</a><br />';
echo 'otherwise, go back to the <a href="main.php">Administration Home Page</a></p>';
}
else if ($ifDelete > 1 || $ifDelete < 1)
{
echo '<p>Deleting the news bit was <span class="bold">NOT</span> successful.<br />';
echo 'Please try again (hit the back button, or start over by <a href="module.php?name=news">clicking here</a></p>';
echo $ifDelete;
}
}
else
{
echo '<p>Nothing Happened?</p>';
echo $ifDelete;
}
}
else if ($_POST['confirm'] == 'no')
{
echo '<p>The News Bit was <span class="bold">NOT</span> Deleted.';
echo '<p>If you would like to delete another news bit, <a href="module.php?name=news">click here</a><br />';
echo 'otherwise, go back to the <a href="main.php">Administration Home Page</a></p>';
}
else
{
print <<<endConfirm
<form method="post" action="delete.php">
<p>Are you sure you want to delete this news bit ?</p>
<input type="hidden" name="name" value="news" />
<input type="hidden" name="id" value="$deleteID" />
<input type="submit" class="form" name="confirm" id="confirm" value="yes" /> <input type="submit" class="form" name="confirm" id="confirm" value="no" />
</form>
endConfirm;
}
?>
of course, the rest of the _REQUEST would be changed to their respective POST/GET ....
scoutt
11-18-2004, 06:27 PM
looks good to me except this part
else if ($ifDelete > 1 || $ifDelete < 1)
if $ifDelete is > 1 than it was successful. it just means it deleted more than 1. which means you had multiple ids the same which means your db is messed up.
I wouldn't worry about it.
JaeSun
11-18-2004, 06:32 PM
yea, i know ... there shouldnt be more than one id, as it is auto incrementing ... i just wanted it there just in case ...
ok, wasnt that much coding like i thought ... hehe
vBulletin® v3.6.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.