If someone clicks on link for a page that contains more then one script, like below, how can you make sure it only runs the script being called??
Right now I have links setup on left nav as:
<a class="sm_textlightblue" href="scripts.php?admin_util=update_grade=1">Upgrade</a>
<a href="scripts.php?admin_util=add_chapter">Add a Chapter</a>
and it's suppose to run the second script you see below, however, when you click on it "Add a chapter", the first and second script are executed (below).
How can I make it more specific so it only runs the script the link is calling??? Please help!
scripts.php
//first script
//first script
//Beginning of enter/update queries for various options
if ($update_grade = 1){
mysql_query("UPDATE students SET re_status_id_fk = 3 WHERE re_grade_id_fk = 12");
echo "<p> Congratulations, the 12th graders have been marked as graduated successfully!</p>";
}else {
echo "<p>We aplogize for the incovenience but there was an error in marking the 12th graders as graduates. Please run the query again. If you continue to receive this error contact your website administrator.</p>";
mysql_close();
include ('templates/footer.inc');
ob_end_flush();
exit();
}
if ($update_grade = 1){
mysql_query("UPDATE students SET re_grade_id_fk = re_grade_id_fk+1 WHERE re_grade_id_fk < 12");
echo "<p>The grade for all REBEL members have been updated.</p>";
}else {
echo "<p>There was an error in updating the grades. Please run the query again. If you continue to receive this error contact your website administrator.</p>";
mysql_close();
include ('templates/footer.inc');
ob_end_flush();
exit();
}
//second script
//If entering a new chapter
if (isset($_POST['enter_chapter'])){
$query = "INSERT INTO chapter (ch_option) VALUES ('{$_POST['inputbox']}')";
$result = @mysql_query($query);
if($result){
echo "<p>{$_POST['inputbox']} has been added as a new chapter!!!</p>";
}else {
echo "<p>Uh oh, this isn't supposed to happen! Please try again. Stupid error 6.</p><p>".mysql_error() ."</p>";
}
mysql_close();
include ('templates/footer.inc');
ob_end_flush();
exit();
}
Execut 1 of many scripts
Moderator: General Moderators
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Execut 1 of many scripts
you have two conditional statements that execute on the same conditions!!!
Also, use "==" in an if statement.
Also, use "==" in an if statement.
Re: Execut 1 of many scripts
aceconcepts wrote:you have two conditional statements that execute on the same conditions!!!
Also, use "==" in an if statement.
It looks a stupid move on my part, but I'm fairly new to PHP programming so it looks ok to me
How can I fix that?
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Execut 1 of many scripts
I don't know what you want to do with the queries but whenever you use the equals operator in an if statement, use two of them e.g.
Code: Select all
if($var==1)Re: Execut 1 of many scripts
Very true but of course there are exceptions.aceconcepts wrote:I don't know what you want to do with the queries but whenever you use the equals operator in an if statement, use two of them e.g.
Code: Select all
if($var==1)