View Full Version : Quick conditional question...

11-06-2003, 10:40 AM
<?php if (isset($_POST['verify1'])) {
$query = "SELECT item_type FROM invtemp WHERE barcode = '$ex1';";
$result = mssql_query ($query);
echo $result;
} elseif (isset ($_POST['model1'])) {
echo $_POST['model1'];
} else {
echo " ";


If $_POST['verify1'] is NOT set, why am I getting an error stating that $ex1 is not defined in the query line? If the IF is not TRUE, then shouldn't that part of the form be bypassed? I know the value of the isset() is returning FALSE...

11-06-2003, 10:49 AM
If you have a form and you simply leave a textbox blank the variable is still submitted and so it is still set. The only form control this is not true for is checkboxes.

I'm guessing that is causing the problem here.

maybe change it to

if($_POST['verify1'] != ""){

11-06-2003, 11:39 AM
What does
!= ""

11-06-2003, 12:06 PM
Does not equal an empty string.

Or perhaps update your first line to:

<?php if (isset($_POST['verify1']) && $_POST['verify1'] != "") {

11-06-2003, 12:59 PM
I think I get that...thanx...

11-06-2003, 01:32 PM
For submit buttons, if there is more than one submit button in a form, is the value of the the buttons sent to be processed regardless of which one is pushed? The verify1 is the value of a submit button. There are 10 identical buttons labeled verify1-10. If I hit one button, it seems that the values of the others are also sent. Is this right?

11-06-2003, 01:36 PM
I've never tested that, but if that is what you're seeing then I guess that is likely the case.

What you can do is make some javascript that changes a value on the fly when one of the buttons is pushed.

11-06-2003, 01:38 PM
Oh geez...as if mastering php isn't hard enough, eh? I guess a little client side knowledge wouldn't hurt, eh? Are you pretty good at javascript? I've heard that it is pretty easy to find free stuff out there...

11-06-2003, 01:57 PM
I'm far from a Javascript expert, and haven't coded it hard core in atleast a year.

Its pretty easy to manipulate form values with javascript and then all you need to do is write a function and access it via an onclick event handler.

So... basically put an onclick event handler with each submit button that executes a function that takes one argument (the name of the button that was clicked) then the function looks at that argument and assigns an appropriate value to a hidden form field.

11-06-2003, 02:04 PM
That makes sense...I'll just have to bone up a bit...well, a lot...on Javascript syntax...

11-06-2003, 02:19 PM
That's an interesting form you've got there. Don't think I've seen one as you describe it.

11-06-2003, 02:50 PM
Yeah, it's a form to mark assets for disposal. To be sure that we are not disposing of the incorrect items, I have put a "Verify" button next to the field that contains the item's identifier (barcode). Upon submittal the page querries the server and returns an item description. I have room on the page for 10 items. Once all is verified by the server, the information is submitted and the item info is marked for destruction. I can print reports so the appropriate parties that are involved in the handling of the items can cross-reference each other and no one gets in trouble later on for having missing equipment...