Page 1 of 1

Switch Statements and Form Variables

Posted: Sun Jun 29, 2003 4:28 pm
by rprins
Ok, so I have a few switch statements set up to do various things. These things include updating the DB, deleting something from the DB, and viewing a list of items in the DB.

Code: Select all

<?php
if($a){
    switch($a){
        case "update":
               //some code
        break;
        case "delete":
              //some code
        break;
        // etc
    }
}
?>
Now, I can get it from the list to the screen to update beacuse that is done via a link, but on the update screen there are 2 form buttons.

Code: Select all

&lt;input name="update" type="submit" value="Update"&gt;
&lt;input name="delete" type="submit" value="Delete from DB"&gt;
The beginning of the form looks like:

Code: Select all

&lt;form name="addrecord" method="post" action="&lt;?php echo"$PHP_SELF?a=$name"; ?&gt;"&gt;
The problem that I run into is that I cannot pass the var from the buttons to the address bar to trigger my switch statements. Any idea on how to do this?

Posted: Sun Jun 29, 2003 4:43 pm
by AVATAr
use
<?php
<form name="addrecord" method="get" action="<?php echo"$PHP_SELF?a=$name"; ?>">
?>

Posted: Sun Jun 29, 2003 4:43 pm
by qartis
Sorry, double post.

Posted: Sun Jun 29, 2003 4:47 pm
by qartis
The form you have, wouldn't set the variable $a.

Code: Select all

&lt;form name="addrecord" method="post" action="&lt;?php echo"$PHP_SELF?a=$name"; ?&gt;"&gt;
&lt;input name="update" type="submit" value="Update"&gt;
&lt;input name="delete" type="submit" value="Delete from DB"&gt;
So, if you clicked "Update", you would be sent to $PHP_SELF?a=$name, with $_POST['update'] equal to "Update". Perhaps you wanted something like this:


HTML

Code: Select all

&lt;form name="addrecord" method="post" action="action.php"&gt;
&lt;input name="action" type="submit" value="Update"&gt;
&lt;input name="action" type="submit" value="Delete from DB"&gt;

action.php:

Code: Select all

<?
switch ($_POST['action']){
	case "Update":
		update()
		break;
	case "Delete from DB":
		delete();
		break;
}
?>