tags:

views:

83

answers:

3

Hi again. Another lame question

So, I have a site that displays several students' requests to change advisors, with an Approve and Deny button for each student. Then I have a Javascript pop-up that confirms the decision when clicked on either button, and it will also e-mail the student about this decision. This should all be on one page as well.

How do I specify which student I will update and e-mail to? I know the query will be like $query = "UPDATE student set current_advisor = ".$requested_advisor." where SID = ".$sid, but how do I specify which student I'm doing this for?

I have only worked with php forms, where you have the user type in the information, but in this case, all the data is there already...

A: 

i'm not sure if this is what you want exactly, but if you wanted a list of advisors and the option to approve or deny each you could do for each advisor

<?php foreach($advisors as $advisor): ?>
<form method="post" action="somewhere">
     <input type="hidden" name="id" value="<?php echo $advisor['id']; ?>" />
     <input type="submit" name="result" value="Approve" onclick="return confirm('Are you sure you want to approve this advisor?')" />
     <input type="submit" name="result" value="Deny" onclick="return confirm('Are you sure you wish to deny this advisor?')" />
</form>
<?php endforeach; ?>

Then that sends to your script a post array which should contain whether it was approved or denied, then you can handle it from there using the id variable to identify your record against your primary key.

Hope this helps :)

Rob
The alert won't actually prevent the form being submitted.. try `onclick="return confirm('Are you sure?');"`
Matt
Ahh yeah, thanks my javascript is a bit rusty!
Rob
Also my example is out of context, i read the answer differently, my apologies. Just replace advisors with students :)
Rob
A: 

You have a couple options for doing something like this.

If you want to do it with actual <form>s, then you'd do this by putting the information you need in "hidden" form fields. For example, you can have something like this in each form:

<input type="hidden" name="SID" value="4" />

And use PHP to fill in the value for each hidden field when you're generating the HTML.

Another option is to just have the buttons open a link, instead of submitting a form. In that case, you can pass the values you need as "GET" parameters on the URL, like this:

http://yoursite.com/change_advisor.php?SID=4&amp;new_advisor=18

And then have the change_advisor.php file use the variables $_GET['SID'] and $_GET['new_advisor'] to do the query you need.

Chad Birch
Thank you! I used the several form method. I did not know that one could do input=hidden. I tried something like that actually, where I gave input the class="hidden", ahaha..
yuudachi
A: 

$sid is the id of the student you want to update... It depends how you're building the page. You can either insert a form for each student, as follows:

// for each student
<form method="post">
  <input type="hidden" value="the-sid" name="SID"/>
  <input type="submit" value="confirm" name="type" onclick="return confirm('Sure?');"/>
  <input type="submit" value="deny" name="type" onclick="return confirm('Sure?');"/>
</form>
// end for each

Then when the user clicks either approve or deny, you're $_POST array in PHP will be filled with:

array("SID"=> $theSID, "type" => "confirm or deny");
Matt
Thank you! This helped immensely. I wasn't sure if making multiple forms would work.
yuudachi