开发者

Approve/Deny in PHP, with some minor javascript

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


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


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&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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜