-3

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);


?>
Toretto
  • 4,685
  • 5
  • 25
  • 46
Pals
  • 1
  • 2
  • 5
  • 1
    paste your code here. – Toretto Mar 30 '13 at 08:08
  • Can you post your form html code? Where is the form being generated -- in the same file that it is being submitted to? – Aiias Mar 30 '13 at 08:08
  • You need to POST the data in a form with POST method to read it as $_POST. POST can't be sent in the URL (that's the GET method). – Aram Kocharyan Mar 30 '13 at 08:09
  • Yea post your code, or else we will not know what the problem is – samayo Mar 30 '13 at 08:12
  • okay, i posted the code. it may have errors i don't know of, sorry for that and thank you in advance. Just a beginner. – Pals Mar 30 '13 at 08:29
  • is what i'm asking for possible? Is there any other way i can pass prof_id to a php file without having it taken as input in the previous html form (i mean the form that leads to the current form)? Please help me asap... – Pals Mar 30 '13 at 09:16
  • where is you input field in the form you want to submit? – Toretto Mar 30 '13 at 09:37
  • @Toretto that is what my problem is. I'm not taking it as input, i'm just catching the value of prof_id in search.php and wanted to send it through to assignastemp.php. – Pals Mar 30 '13 at 14:54

2 Answers2

2

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.

Community
  • 1
  • 1
Tushar
  • 7,843
  • 29
  • 38
  • pkay, but i think i also need post there. can i get and post the same value in two different variables and use them differently in the same file? – Pals Mar 30 '13 at 08:52
  • @Pals with the form you have right now (the one with `method=post`), you'll send the `prof_id` through `GET` and the form items through `POST`. Just make the names are different for all of them, and it should work. – Tushar Mar 30 '13 at 16:14
  • Nope, i tried many things, didn't work. Had to finish it asap. So i figured i'd take the prof_id as input again in one of my files. Problem solved! Thanks anyways :) – Pals Mar 31 '13 at 07:54
0

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[...].

M. Suleiman
  • 840
  • 4
  • 22