开发者

adding arguments to $_POST?

I've been attempting to use $_GET to try and manage my log file of flagged accounts but this new situation it's not exactly working.

if (isset($_GET['marked'])) {
        if ($_GET['marked'] == 'read') {
            if (isset($_POST['mark'])) {
                foreach ($_POST['mark'] as $mark) {
                    mysql_query("UPDATE logged SET status = '1' WHERE timeLogged = $mark");
                    echo "<meta http-equiv='refresh' content='0;url=/admincpanel/flagged.php'>";
                }
            }
        }
        else if ($_GET['marked'] == 'unread') {
            if (isset($_POST['mark'])) {
                foreach ($_POST['mark'] as $mark) {
                    mysql_query("UPDATE logged SET status = '0' WHERE timeLogged = $mark");
                    echo "<meta http-equiv='refresh' content='0;url=/admincpanel/flagged.php'>";
                }
            }
        }
     开发者_运维问答   else if ($_GET['marked'] == 'save') {
            if (isset($_POST['mark'])) {
                foreach ($_POST['mark'] as $mark) {
                    mysql_query("UPDATE logged SET status = '2' WHERE timeLogged = $mark");
                    echo "<meta http-equiv='refresh' content='0;url=/admincpanel/flagged.php'>";
                }
            }
        }
    }

and I have the buttons: Mark as <a href=\"?marked=read\" onclick=\"submitForm();\"><i>read</i></a><a href=\"?marked=unread\" onclick=\"submitForm();\">/unread</a>

I'm using checkboxes to select what rows I want and before with no $_GET the default submitForm(); worked just fine.

This worked: Mark as <a href=\"#\" onclick=\"submitForm();\"><i>read</i></a>

    if (isset($_POST['mark'])) {
        foreach ($_POST['mark'] as $mark) {
            mysql_query("UPDATE logged SET status = '1' WHERE timeLogged = $mark");
            echo "<meta http-equiv='refresh' content='0;url=/admincpanel/flagged.php'>";
        }
    }

How can I get my other markers (read,unread,save) to work? Submitting the form and getting results seems the only work with $_POST so I must need to add more arguments to $_POST right?

if it helps any this is the javascript:

function submitForm() {
    document.logs.submit();
}

To sum it up, I'm trying to make read update status to 1, unread status 0, and save status 2. And using $_GET isn't working--or I'm doing it wrong. So what can I do to make this work?

Thank you.


Hy Try add a hidden field in the form:

<input type="hidden" name="marked" id="marked" value="" />

Then, the buttons:

`Mark as

<a href=\"?marked=read\" onclick=\"submitForm('read');\"><i>read</i></a><a href=\"?marked=unread\" onclick=\"submitForm('unread');\">/unread</a>`

Then the JavaScript function:

function submitForm(mark) {
  document.getElementById('marked').value = mark;
  document.logs.submit();
}`

Then, in the php script use $_REQUEST['marked'] insted of $_GET


The href="?marked=read" is never sent to the server because you're submitting the form instead.

To resolve the problem you could add an argument to your submitForm() function and store this argument as the value of a hidden form input named 'marked'.

Like this:

Mark as <a href="#" onclick="submitForm('read')">read</a>

and

function submitForm(marked) {
  // TODO: Setup hidden input field with the marked argument
  document.logs.submit();
}


Try this for the php code, a bit cleaner and concise:

if (isset($_GET['marked'])) {
    if ($_GET['marked') == 'read')
        $status = 1;
    elseif ($_GET['marked'] == 'unread')
        $status = 0;
    else
        $status = 1;
    }
if (isset($_POST['mark'])) {
    foreach ($_POST['mark'] as $mark) {
        mysql_query("UPDATE logged SET status = $status WHERE timeLogged = $mark");
        echo "<meta http-equiv='refresh' content='0;url=/admincpane/flagged.php'>";
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜