So, I have this following snippet of code:

if (isset($_POST['type1'])) {
            mysql_query("UPDATE table SET status = 1 WHERE id = '". $_GET['repid']."'", $c2) or die(mysql_error());
        }
    if (isset($_POST['type2'])) {
            mysql_query("UPDATE table SET status = 1 WHERE id = '". $_GET['repid']."'", $c2) or die(mysql_error());
        }
    if (isset($_POST['type3'])) {
            mysql_query("UPDATE table SET status = 1 WHERE id = '". $_GET['repid']."'", $c2) or die(mysql_error());
        }
    ?>
    <br />
    <form method="get" action="">
        <input type="hidden" name="pageid" value="plyrmgmt">
        <input type="hidden" name="action" value="changeBan">
        <input type="hidden" name="uid" value="<?php echo $hr_uid; ?>">
        <input type="hidden" name="repid" value="<?php echo $rid; ?>">
        <input type="submit" name="type1" value="Type1">
    </form>
    <form method="get" action="">
        <input type="hidden" name="pageid" value="plyrmgmt">
        <input type="hidden" name="action" value="changeMute">
        <input type="hidden" name="uid" value="<?php echo $hr_uid; ?>">
        <input type="hidden" name="repid" value="<?php echo $rid; ?>">
        <input type="submit" name="type2" value="Type2">
    </form>
    <form method="get" action="">
        <input type="hidden" name="pageid" value="plyrmgmt">
        <input type="hidden" name="action" value="changeLock">
        <input type="hidden" name="uid" value="<?php echo $hr_uid; ?>">
        <input type="hidden" name="repid" value="<?php echo $rid; ?>">
        <input type="submit" name="type3" value="Type3">
    </form>

However, when I click the Submit button for Type1, Type2, or Type3, the query doesn't execute.

Can anyone help?

Thanks,
Mark

Recommended Answers

All 11 Replies

The method of your form is wrong!

In PHP you're working with _POST & _GET and form with_GET.

Change the variable that will run smoothly!

First off i see that you are using double quotes on the id after $_GET. The only time you use get, is when you are passing variable through a URL, in this case you are not.

mysql_query("UPDATE table SET status = 1 WHERE id = '". $_GET['repid']."'", $c2) or die(mysql_error());

Needs to be

mysql_query("UPDATE table SET status = 1 WHERE id = '". $_POST['repid']."',$c2) or die(mysql_error());

And just like bollabr said, change your forms from method="get" to method="post" action="<?php $_SERVER['PHP_SELF'] ?>". Also, what is $c2 for because you are not referencing to a field to update?

$c2 is the connection information.

the connection does not need to go into your update statement, its supposed to go before it.

mysql_query("UPDATE table SET status = 1 WHERE id = '". $_POST['repid']."'",$c2) or die(mysql_error());

missing the closing double quote!

<form method="post">

just change each form's method to post and update the queries like fobos wrote and that should work

You may want to add die(mysql_error($c2)); as if there is one and its not the default connection you won't know

Use method of "POST" type and mark the thread as solved if ur problem is solved.

None of these suggestions worked :(

if (isset($_POST['type1'])) {
echo $_POST['repid'];
        mysql_query("UPDATE table SET status = 1 WHERE id = '". $_POST['repid']."'", $c2) or die(mysql_error());
    }
if (isset($_POST['type2'])) {
 echo $_POST['repid'];
        mysql_query("UPDATE table SET status = 1 WHERE id = '". $_POST['repid']."'", $c2) or die(mysql_error());
    }
if (isset($_POST['type3'])) {
 echo $_POST['repid'];
        mysql_query("UPDATE table SET status = 1 WHERE id = '". $_POST['repid']."'", $c2) or die(mysql_error());
    }
?>
<br />
<form method="POST" action="">
    <input type="hidden" name="pageid" value="plyrmgmt">
    <input type="hidden" name="action" value="changeBan">
    <input type="hidden" name="uid" value="<?php echo $hr_uid; ?>">
    <input type="hidden" name="repid" value="<?php echo $rid; ?>">
    <input type="submit" name="type1" value="Type1">
</form>
<form method="POST" action="">
    <input type="hidden" name="pageid" value="plyrmgmt">
    <input type="hidden" name="action" value="changeMute">
    <input type="hidden" name="uid" value="<?php echo $hr_uid; ?>">
    <input type="hidden" name="repid" value="<?php echo $rid; ?>">
    <input type="submit" name="type2" value="Type2">
</form>
<form method="POST" action="">
    <input type="hidden" name="pageid" value="plyrmgmt">
    <input type="hidden" name="action" value="changeLock">
    <input type="hidden" name="uid" value="<?php echo $hr_uid; ?>">
    <input type="hidden" name="repid" value="<?php echo $rid; ?>">
    <input type="submit" name="type3" value="Type3">
</form>

Check this,if still it is not working let me know what you are getting when echoing $_POST['repid'].
Hope it will solve your problem.You must be consistent in using GET or POST method.Somewhere you are using GET and somewhere POST.

$_POST['repid'] doesn't echo anything out, sadly.

echo $hr_uid

<?php echo $hr_uid; ?

then the problem is here..."echo $hr_uid","echo $hr_uid;"
This doesn't contain anything then.Please check if you have set any value to it or not....

again, why are you using the connection in your update statement!! try changing each form input to pageid1, pageid2, pageid3 and soforth for the rest

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.