Click to See Complete Forum and Search --> : if statment driving me MAD


ChrisR23
08-06-2008, 05:01 PM
I am working on a pet project to create a website for managing shared prototype hardware.

I am trying to implement some functionality to send an email to the person currently using a specific piece of hardware.

The website user ticks a checkbox alongside the proto they need and an email should be sent to the person currently in possession of it.

The function to send the email works but it appears an "if" statement never holds true. if($submit){ We never end up in here }

Could one of you save me from beating my head against a wall!

Thanks
Chris
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>ProtoWars - Proto Request</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table align="center">
<tr>
<td>
<img src="Pbryogtboy-goyorgylrey.gif">
<table align="center">
<tr>
<td>
<form action="request.php" method="post">
<input type="text" name="proto_lookup" value="e.g Astro or chrankin" onFocus="if(this.value=='e.g Astro or chrankin')this.value='';">
<input name="lookup" type="submit" id="lookup" value="Proto-oogle Search">
<!--</form>-->
</td>
</tr>
</table>
<?php
INCLUDE 'constants.php';
INCLUDE 'db_connect.php';
INCLUDE '2testmail.php';

connecttodb($servername,$dbname,$dbusername,$dbpassword);

$proto_lookup=$_POST[proto_lookup];
$sql="SELECT * FROM protos WHERE (proto_name LIKE '$proto_lookup%') OR (username LIKE '$proto_lookup%')";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>

<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><!--<form name="form1" method="post" action="">-->
<table align="center" width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td>&nbsp;</td>
<td colspan="4"><strong>Select a proto to request</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="center"><strong>ID</strong></td>
<td align="center"><strong>Proto Name</strong></td>
<td align="center"><strong>Proto Owner</strong></td>
</tr>

<?php
while($rows=mysql_fetch_array($result, MYSQL_ASSOC)){
?>
<tr>
<td align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['proto_id']; ?>"></td>
<td bgcolor="#FFFFFF"><?php echo $rows['proto_id']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['proto_name']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['username']; ?></td>
</tr>
<?php
}
?>



<?php
$submit=$_POST['submit']; // I added this to see if it would help but it does not.
if($submit){ // This apears to never hold true ?!
echo("Mail Sent ###############################################");
$checkbox=$_POST['checkbox'];
for($i=0;$i<count($checkbox);$i++){
$proto_req_id = $checkbox[$i];
$sent =send_request_email($proto_req_id); // This function call does work when tested alone in a separate file
}
}

//if successful refresh
if($sent == true){
echo("Mail Sent ###############################################");
echo "<meta http-equiv=\"refresh\" content=\"0;URL=request.php\">";
}

mysql_close();
?>
<tr>
<td><input name="submit" type="submit" id="submit" value="submit"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

fireblade
08-06-2008, 05:09 PM
Hi chris it seems you are using 2 Submit inputs. Keep only one Submit.

<input name="lookup" type="submit" id="lookup" value="Proto-oogle Search">

<tr>
<td><input name="submit" type="submit" id="submit" value="submit"></td>
</tr>

This will make confusion to the server.
Also one think.. Do not name your element with the type name.. Eg: You input type is name as
name="submit" id="submit"
This also will make confusion if you are using Javascript. These are reserved words.

ChrisR23
08-06-2008, 05:34 PM
Thanks FireBlade

I have now broken the submit inputs up into two forms and renamed the elements.

The send_request_email($proto_req_id); function is still not called though : (

fireblade
08-07-2008, 12:41 AM
hi.. did you check the varibales and its values alone?

use the

isset($_POST['submit'])


$submit=isset($_POST['submit']); // I added this to see if it would help but it does not.
if($submit){ // This apears to never hold true ?!
echo("Mail Sent ###############################################");
$checkbox=$_POST['checkbox'];
for($i=0;$i<count($checkbox);$i++){
$proto_req_id = $checkbox[$i];
$sent =send_request_email($proto_req_id);
}
}


echo the values of $checkbox and check weather it is bringing the value correctly.

print_r($checkbox);

and check all the variable value separate and diagnose.

ChrisR23
08-07-2008, 02:03 PM
I added this and now know for sure that $submit is not not being set. But why not???

if (isset($submit)) {
echo "This var is set so I will print.";
}

fireblade
08-07-2008, 02:54 PM
do the if condition in this way...


if(isset($_POST['post'])) {
echo "Form is posted";
}


Note: better you change the name of these INPUTs. Because some browser are conflicting with this name submit what you have given to the input.

Submit is already a name of one INPUT TYPE