Forum Moderators: coopster

Message Too Old, No Replies

Showing error/success messages within template

if else

         

tonynoriega

4:26 pm on May 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Question.... in my page below, the "if else" statement, ... i have a form that a user submits...when they enter at least the first and last names, they get the "successful entry" after the submit the form.

If they do not, they get the "error" postback. BUT, i have it in a "die" statement...and when it does that, the error page shows up in a new blank page, outside of my template...

how can i re-arrange my statement to keep it within the template..? i tried just echo'ing it, but it only showed the error at all times....

************************************************************
if (isset($_POST['submit']))
{
if (!$_POST['fname'] ¦!$_POST['lname'])
{ //show user error
die('<table>
<tr><td>Error, must enter last and first name.</td></tr>
</table>');
}
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$query = "INSERT INTO (.....
VALUES ...'$fname','$lname'...)";

mysql_query($query);

mysql_close();

?>
//Show user successful entry
<table>
<tr><td><h1>Successful Lead Entry</h1></td></tr>
</table>

<?php
}
else
{
?>

<table>
<form>User Form for data entry goes here.
</form>
</table>

<?php
}
?>

henry0

5:43 pm on May 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not tested but should work

<?
if (isset($_POST['submit']))
{
if (!$_POST['fname'] ¦!$_POST['lname'])
{ //show user error
('<table>
<tr><td>Error, must enter last and first name.

<!-- Do not test both in bulk, rather do it one at a time with its pertaining error message -->

</td></tr>
</table>');
exit();
}
else
{
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$query = "INSERT INTO (.....
VALUES ...'$fname','$lname'...)";
mysql_query($query);
mysql_close();
print<<<success
<table>
<tr><td><h1>Successful Lead Entry</h1></td></tr>
</table>
success;
}
?>

<table>
<form>User Form for data entry goes here.
</form>
</table>

tonynoriega

7:57 pm on May 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i am assuming the first "if" statement has to have a closing bracket..}?

Would that go after the closing bracket in the else statement?

henry0

10:18 pm on May 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



this is more like it
<<<<

<?
$fname=$_POST['fname'];
$lname=$_POST['lname']
if (isset($_POST['fname']) &&!empty($_POST['fname']) && isset($_POST['lname']) &&!empty($_POST['lname']) )
{
$query = "INSERT INTO (.....
VALUES ...'$fname','$lname'...)";
mysql_query($query);
mysql_close();
print<<<success
<table>
<tr><td><h1>Successful Lead Entry</h1></td></tr>
</table>
success;
}
else
{
('<table>
<tr><td>
Error, must enter last and first name.
</td></tr>
</table>');
exit();
}
?>

>>>>>