Jump to content

GET form being posted to "index.php" every time / not doing what expected


oz11
Go to solution Solved by mac_gyver,

Recommended Posts

<h1>Search</h1>

<?PHP

    if ($_GET['type'] == "userid"){
        echo "userid";
    }
    if ($_GET['type'] == "userstring"){
        echo "user_string";
    }
    if ($_GET['type'] == "postid"){
        echo "post_id";
    }
    if ($_GET['type'] == "poststring"){
        echo "post_string";
    }

?>

<a href="index.php?page=all_users">View all users</a> // <a href="index.php?page=search&type=all_posts">View all posts</a> <br><br><br>

<form method="GET" action="index.php?page=search">
<h3>User ID</h3>
<label for="lname">Username ID:</label><br>
  <input type="text" id="userid" name="userid" style="background-color: black; border: 1px dashed #39FF14; color: #39FF14;">
  <input type="submit" value="Submit" style="background-color: black; border: 1px dashed #39FF14; color: #39FF14;">
  </form>

  <form method="GET" action="index.php?page=search">
  <h3>User string</h3>
<label for="lname">Username String:</label><br>
  <input type="text" id="userstring" name="userstring" style="background-color: black; border: 1px dashed #39FF14; color: #39FF14;">
  <input type="submit" value="Submit" style="background-color: black; border: 1px dashed #39FF14; color: #39FF14;">
  </form>

  <form method="GET" action="index.php?page=search">
<h3>Post ID</h3>
<label for="lname">Post ID:</label><br>
  <input type="text" id="postid" name="postid" style="background-color: black; border: 1px dashed #39FF14; color: #39FF14;">
  <input type="submit" value="Submit" style="background-color: black; border: 1px dashed #39FF14; color: #39FF14;">
  </form>

  <form method="GET" action="index.php?page=search">
  <h3>Post string: </h3>
<label for="lname">Post String:</label><br>
  <input type="text" id="poststring" name="poststring" style="background-color: black; border: 1px dashed #39FF14; color: #39FF14;">
  <input type="submit" value="Submit" style="background-color: black; border: 1px dashed #39FF14; color: #39FF14;">
  </form>
  

#2

<h1>Search</h1>
<?PHP
    if ($_GET['type'] == "userid"){
        echo "userid";
    }
    if ($_GET['type'] == "userstring"){
        echo "user_string";
    }
    if ($_GET['type'] == "postid"){
        echo "post_id";
    }
    if ($_GET['type'] == "poststring"){
        echo "post_string";
    }
?>

<a href="index.php?page=all_users">View all users</a> // <a href="index.php?page=search&type=all_posts">View all posts</a> <br><br><br>

<form method="GET" action="index.php?page=search&userid=1">
<h3>User ID</h3>
<label for="lname">Username ID:</label><br>
  <input type="text" id="userid" name="userid" style="background-color: black; border: 1px dashed #39FF14; color: #39FF14;">
  <input type="submit" value="Submit" style="background-color: black; border: 1px dashed #39FF14; color: #39FF14;">
  </form>

  <form method="GET" action="index.php?page=search&userstring=1">
  <h3>User string</h3>
<label for="lname">Username String:</label><br>
  <input type="text" id="userstring" name="userstring" style="background-color: black; border: 1px dashed #39FF14; color: #39FF14;">
  <input type="submit" value="Submit" style="background-color: black; border: 1px dashed #39FF14; color: #39FF14;">
  </form>

  <form method="GET" action="index.php?page=search&postid=1">
<h3>Post ID</h3>
<label for="lname">Post ID:</label><br>
  <input type="text" id="postid" name="postid" style="background-color: black; border: 1px dashed #39FF14; color: #39FF14;">
  <input type="submit" value="Submit" style="background-color: black; border: 1px dashed #39FF14; color: #39FF14;">
  </form>

  <form method="GET" action="index.php?page=search&poststring=1">
  <h3>Post string: </h3>
<label for="lname">Post String:</label><br>
  <input type="text" id="poststring" name="poststring" style="background-color: black; border: 1px dashed #39FF14; color: #39FF14;">
  <input type="submit" value="Submit" style="background-color: black; border: 1px dashed #39FF14; color: #39FF14;">
  </form>
  

I've ran both of these codes, anyway.. they are not doing what I expect. Instead of being processed on the page and running the GET data through the conditionals, instead it takes me to "index.php" every time. I've tried numerous "actions", though these never work. The file I'm dealing with is named "index.php?page=search" (it's an "include" used for CMS or somthing similar).

 

Edit: for example, being forwarded to "index.php?postid=1", not "index.php?page=search&postid=1" .

 

Edited by oz11
code edit
Link to comment
Share on other sites

  • Solution

did you not read the reply in the existing thread for this task?

anyways, the form field values for a get method form will replace any get parameters you try to put on the end of the url in the action='...' attribute. to supply 'additional' get parameters, you would need to use hidden form fields.

Link to comment
Share on other sites

Also - I don't see any setting of a parm named 'type'.  You seem to be creating ones named 'page', 'userid', 'userstring', 'postid', 'poststring',  but never do you create 'type'.

And of course you have issues as mac gyver has told you.

Edited by ginerjm
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.