Execut 1 of many scripts

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
javiqq
Forum Newbie
Posts: 17
Joined: Wed Oct 29, 2008 9:15 am

Execut 1 of many scripts

Post by javiqq »

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();
}
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Execut 1 of many scripts

Post by aceconcepts »

you have two conditional statements that execute on the same conditions!!!

Also, use "==" in an if statement.
javiqq
Forum Newbie
Posts: 17
Joined: Wed Oct 29, 2008 9:15 am

Re: Execut 1 of many scripts

Post by javiqq »

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

How can I fix that?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Execut 1 of many scripts

Post by aceconcepts »

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)
mmj
Forum Contributor
Posts: 118
Joined: Fri Oct 31, 2008 4:00 pm

Re: Execut 1 of many scripts

Post by mmj »

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)
Very true but of course there are exceptions. :)
Post Reply