Viewed   69 times

Do you have any suggestions with my problem. I need to use get and post at the same time. Get because I need to output what the user has typed. And post because I need to access the mysql database in relation to that input. It looks something like this:

<form name="x" method="get" action="x.php">
<input name="year" type="text">

<select name="general" id="general">
        <font size="3">
        <option value="YEAR">Year</option>


This will output the contents of mysql depending on what the user will check:

<form name="y" method="post" action"y.php">
<input name="fname" type="checkbox">

And the form action of those two combined will look something like this:


               if($_POST['general'] == 'YEAR'){
                   <?php echo $_GET["year"]; ?>
            $result2 = mysql_query("SELECT * FROM student
    WHERE student.YEAR='$syear'");
    <table border='1'>

                    <?php if ( $ShowLastName ) { ?><th>LASTNAME</th><?php } ?>
                    <?php if ( $ShowFirstName ) { ?><th>FIRSTNAME</th><?php } ?>

    <?php while ( $row = mysql_fetch_array($result2) ) {
        if (!$result2)  { 

                    <td><?php echo $row['IDNO']?> </td>
                    <td><?php echo $row['YEAR'] ?> </td>
     <?php if ( $ShowLastName ) { echo('<td>'.$row['LASTNAME'].'</td>'); } ?></td>
                    <?php if ( $ShowFirstName ) { echo('<td>'.$row['FIRSTNAME'].'</td>'); } ?>

I really get lots of undefined errors when I do this. What can you recommend that I should do in order to get the value inputted by the user together with the mysql data.



You can only have one verb (POST, GET, PUT, ...) when doing an HTTP Request. However, you can do

<form name="y" method="post" action="y.php?foo=bar">

and then PHP will populate $_GET['foo'] as well, although the sent Request was POST'ed.

However, your problem seems to be much more that you are trying to send two forms at once, directed at two different scripts. That is impossible within one Request.

Friday, October 14, 2022

I would say just build it yourself. You can set it up like this:

$query = "INSERT INTO x (a,b,c) VALUES ";
foreach ($arr as $item) {
  $query .= "('".$item[0]."','".$item[1]."','".$item[2]."'),";
$query = rtrim($query,",");//remove the extra comma
//execute query

Don't forget to escape quotes if it's necessary.

Also, be careful that there's not too much data being sent at once. You may have to execute it in chunks instead of all at once.

Saturday, November 5, 2022

The function you're looking for is find_in_set:

 select * from ... where find_in_set($word, pets)

for multi-word queries you'll need to test each word and AND (or OR) the tests:

  where find_in_set($word1, pets) AND find_in_set($word2, pets) etc 
Wednesday, August 17, 2022

You can use get and post at the same time, but you shouldn't. If you want to continue to send the ID this is as simple as:

<form ...
   <input type="submit" ...
   <input type="hidden" name="id"
      value="<?php echo htmlspecialchars($_GET['id'], ENT_QUOTES); ?>" />
Monday, September 19, 2022

Actually I was able to achieve the desired result by mixing Javascript and Codebehind code. So, what I've done is in server side code I've built an entire web page like following:

    var strForm = new StringBuilder();
    strForm.Append("<form id="" + formId + "" name="" + formId + "" action="" + url + queryString +"" method="POST">");
    foreach (string key in data)
        strForm.Append("<input type="hidden" name="" + key + "" value="" + data[key].Replace(""", "&quot;") + "">");

And in addition to this form built on server side, I add a javascript code that submits the form I've just built.

    var strScript = new StringBuilder();
    strScript.Append("<script language='javascript'>");
    strScript.Append("var v" + formId + " = document." + formId + ";");
    strScript.Append("v" + formId + ".submit();");

So, what this code does, is as you see, the form action is an URL with query string parameters attached to it... but since the form method is POST, we submit the values we added as a hidden fields as POST parameters... So we end up submitting both POST and GET parameters.

Hope this solution will help somebody =)

Sunday, August 7, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :