I know that one can pass a value in a url when the submit button is clicked like:action= assignastemp.php?value1=a
and then retrieve it in assignastemp file using $query=$_GET['value1'];
so that $query would take the value a.
Now, check out the following:
I have this line of code in my assignastemp file so that i can retrieve the professor id in the variable $query: $query=$_POST['searchprofid'];
In the action field of assignastemp i have put: action= 'sendmail.php?prof_id=$query
' since i want that this same professor id be passed to my next form sendmail.php so that i can also display and use it in sendmail.php. But it is not passing the value. Please tell me the correct syntax.
Here's my search.php file (it works fine and gives me proper results, but does not pass prof_id to assignastemp.php):
<?php
include('connectionfile.php');
$query=$_POST['searchprofid'];
$query1 = $_POST['searchprofname'];
$query2=$_POST['searchprofdesignation'];
$query3=$_POST['searchprofexperience'];
$query4=$_POST['searchprofemail'];
$query5=$_POST['searchprofcolg'];
$query6=$_POST['searchprofsubject'];
echo "<br><p>";
$raw_results = mysql_query("SELECT * FROM professor WHERE (`prof_id` LIKE '%".$query."%') AND (`prof_name` LIKE '%".$query1."%') AND (`designation` LIKE '%".$query2."%') AND (`experience` LIKE '%".$query3."%') AND (`prof_email_id` LIKE '%".$query4."%') AND (`college_name` LIKE '%".$query5."%') AND (`subject_name` LIKE '%".$query6."%') ") OR die(mysql_error());
$number= mysql_num_rows($raw_results);
echo "<br>No. of results returned: ";
echo "$number";
if($number > 0)
{
echo ( "<form id='assign' action= 'assignastemp.php?prof_id=$query' method='post'> <table border='1' cellpadding='8' cellspacing= '6' bgcolor= 'white' bordercolor='158bee' align='center' >" ) ;
while($results = mysql_fetch_array($raw_results))
{
echo ("<tr><td><p>".$results['prof_id']."</td><td>".$results['prof_name']."</td><td>".$results['designation']."</td><td>".$results['experience']."</td><td>".$results['prof_email_id']."</td><td>".$results['college_name']."</td><td>".$results['subject_name']."</td> ");
echo(" <td><center><input type= 'submit' name='assign' value= 'Assign' /> </td>");
/* echo(" <td><center><input type= 'hidden' name='prof_id' value='prof_id' /> </td>"); */
echo("</p></tr>");
}
echo("</table></form>");
}
else
{
echo "<br> No matches found.";
}
mysql_close($id_link);
?>
Here's **assignastemp.php**:<?php
include('connectionfile.php');
$prof_id= $_POST['prof_id'];
echo("</p> Professor ID: $prof_id");
mysql_close($id_link);
?>
Attaching parameters at the end of your url like: ?prof_id=$query
sends them through GET
, and thus you can only access the value through $_GET['prof_id']
or $_REQUEST['prof_id']
; There's a difference between POST
And GET
, as shown in this question.
You need to have some kind of a way (form) in HTML to submit data through, using POST
method, in order to be able to fetch the data entered by using $_POST[...]
.