/    Sign up×
Community /Pin to ProfileBookmark

if statment driving me MAD

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

[code=php]<!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>
[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@firebladeAug 06.2008 — 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">[/QUOTE]

<tr>

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

</tr>[/QUOTE]


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
[code=html]name="submit" id="submit"[/code]
This also will make confusion if you are using Javascript. These are reserved words.
Copy linkTweet thisAlerts:
@ChrisR23authorAug 06.2008 — 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 : (
Copy linkTweet thisAlerts:
@firebladeAug 07.2008 — hi.. did you check the varibales and its values alone?

use the

[code=php]isset($_POST['submit'])[/code]

[code=php]
$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);
}
}
[/code]


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

[code=php]print_r($checkbox);[/code]

and check all the variable value separate and diagnose.
Copy linkTweet thisAlerts:
@ChrisR23authorAug 07.2008 — 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.";

}
Copy linkTweet thisAlerts:
@firebladeAug 07.2008 — do the if condition in this way...

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


Note: better you change the name of these INPUTs. Because some browser are conflicting with this name [B][COLOR="DarkRed"]submit[/COLOR][/B] what you have given to the input.

Submit is already a name of one INPUT TYPE
×

Success!

Help @ChrisR23 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...