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>
</form>
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">
</form>
And the form action of those two combined will look something like this:
<?php
if($_POST['general'] == 'YEAR'){
?>
<?php echo $_GET["year"]; ?>
<?php
$result2 = mysql_query("SELECT * FROM student
WHERE student.YEAR='$syear'");
?>
<table border='1'>
<tr>
<?php if ( $ShowLastName ) { ?><th>LASTNAME</th><?php } ?>
<?php if ( $ShowFirstName ) { ?><th>FIRSTNAME</th><?php } ?>
</tr>
<?php while ( $row = mysql_fetch_array($result2) ) {
if (!$result2) {
}
?>
<tr>
<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.
Now, there can be occasions where, you need to have HTTP POST forms to get data from users. The question is, can you use GET and POST method together to create different dynamic pages from a single script? The answer is yes!
With Ajax you can send data to a PHP script via GET and POST in the same request. The process is similar to sending data through the POST, it's actually the same, being only applied a "trick".
The method attribute specifies how to send form-data (the form-data is sent to the page specified in the action attribute). The form-data can be sent as URL variables (with method="get" ) or as HTTP post transaction (with method="post" ). Notes on GET: Appends form-data into the URL in name/value pairs.
There are 2 HTTP request methods: GET: Requests data from a specified resource. POST: Submits data to be processed to a specified resource.
You cannot do a GET and POST at the same time.
Combine the two forms into one.
For example combine the forms to one 'post' form. In your code extract whatever you need from $_POST.
And 'YEAR' does not equal 'Year', your sample code also needs work.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With