Jump to content

Help correcting this.


iamnottheend

Recommended Posts

I am pretty sure it works. I just think i have my if statements wrong. I am not very good with forms and this is the first time i have used radio buttons and well something is going wrong.

 

Form

 

<form action="{$currentpage}" method="post">
<input type="radio" name="availible" value="Availible"> Availible <br />			
<input type="radio" name="availible" value="NotAvailible"> Not Avilible
<input type="submit" name="AvailibleSubmit" value="submit" />
</form>

 

php

if ($_POST['AvailibleSubmit']) {
if ($_POST['availible'] = "Availible") {
	$sql="UPDATE `designer_status` SET `amavailible` = '1' WHERE `designer_status`.`amavailible` =1 LIMIT 1";
	$result = mysql_query($sql);
	if ($result) {
		echo "database changes have been made. Press <a href=\"admin.php\">back</a> to continue.";
	} else {
		echo "database changes failed, please try again";
	}
}
if ($_POST['availible'] = "NotAvailible") {
	$sql="UPDATE `designer_status` SET `amavailible` = '0' WHERE `designer_status`.`amavailible` =1 LIMIT 1";
	$result = mysql_query($sql);
	if ($result) {
		echo "database changes have been made. Press <a href=\"admin.php\">back</a> to continue.";
	} else {
		echo "database changes failed, please try again";
	}
}
}

 

Output

database changes have been made. Press back to continue.database changes have been made. Press back to continue.

 

What i believe is happening is that both if statements are running, this means that they are wrong. Could someone correct them for me so i can see where i am going wrong.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/42685-help-correcting-this/
Share on other sites

if (isset($_POST['AvailibleSubmit'])) {
if (isset($_POST['availible'])) {
	$sql="UPDATE `designer_status` SET `amavailible` = '1' WHERE `designer_status`.`amavailible` =1 LIMIT 1";
	$result = mysql_query($sql);
	if ($result) {
		echo "database changes have been made. Press <a href=\"admin.php\">back</a> to continue.";
	} else {
		echo "database changes failed, please try again";
	}
} else {
	$sql="UPDATE `designer_status` SET `amavailible` = '0' WHERE `designer_status`.`amavailible` =1 LIMIT 1";
	$result = mysql_query($sql);
	if ($result) {
		echo "database changes have been made. Press <a href=\"admin.php\">back</a> to continue.";
	} else {
		echo "database changes failed, please try again";
	}
}
}

 

Changed a few lines just to make it check if the variable isset or not, this is causing it to do one or the other, noth both. Is this what you were looking for?

Link to comment
https://forums.phpfreaks.com/topic/42685-help-correcting-this/#findComment-207096
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.