Hello,
I'm new at this forum.The problem is that my footer is gone when i click the submit botton because of the die function in my php script. I want it to prompt for empty fields and if not empty, it will insert values into my database. I found prompt empty field code in this website and use it to mine, and that's the time that problem occurs.
This is the code:
<?php
if(isset($_POST['signup'])){
if(empty($_POST['name']) && empty($_POST['email'])) {
    die('<div id="error"><img src="img/wrong.png" width="25px"height="17px"/>Name and email field was empty</div>');
}
if(empty($_POST['name'])) {
die('<div id="error"><img src="img/wrong.png" width="25px"height="17px"/>Name field was empty</div>');
}
if(empty($_POST['email'])) {
die('<div id="error"><img src="img/wrong.png" width="25px"height="17px"/>Email field was empty</div>');
}
if(empty($_POST['pass'])) {
die('<div id="error"><img src="img/wrong.png" width="25px"height="17px"/>Password field was empty</div>');
}

if($_POST['cpass'] == $_POST['pass']){
$query = mysql_query("INSERT INTO members(name,email,password) values('{$_POST['name']}','{$_POST['email']}','{$_POST['pass']}')");
if($query){
echo '<div id="good"><img src="img/right.png" width="25px"height="17px"/>Successful</div>';
}
else{
echo '<div id="error"><img src="img/wrong.png" width="25px"height="17px"/>Invalid! Sign Up Again</div>';
}
}
else{
echo '<div id="error"><img src="img/wrong.png" width="25px"height="17px"/>Password did not match</div>';
}
}
mysql_close();
?>
Please help me through this. and sorry for my bad english. Hoping for your quick reply.

can you post an image about your problem???

Thank you for the quick reply. this is the pictures. Also the slideshow is gone too. I think it's because of the die function in line 3-14.

in your div id "error" what is the style of it???

i think the size of your div id error complicates your footer...

This is the code:

#good{
color:green;
font-size:11px;
}

#error {
color:red;
font-size:11px;
}

It's the same font size as the form font size. When i try to remove the die in my php script, the footer and the slideshow remains but it sends null into my database. All i want is to check if their is an empty fields, and if their is no empty fields it sends values to my database table.

I think that there is probably a problem with the code somewhere else, the error checking above seems to be fine, can you post the rest of the code including the bit that includes the footer that disappears?

Yeah sure, here it is.

                <div id="right">
                    <center>
                    <br><br><br>
                        <p style="font-family:arial;font-size:20px" class="title">Please Register</p>
                    <br>
                        <form action="" method="POST">
                            <table style="width:30%;">
                                <tr>
                                    <td>Full Name:</td>
                                    <td>
                                    <input type="text" name="name" /></td>
                                </tr>
                                <tr>
                                    <td>Email:</td>
                                    <td>
                                    <input type="text" name="email" /></td>
                                </tr>
                                <tr>
                                    <td>Password:</td>
                                    <td>
                                    <input type="password" name="pass" /></td>
                                </tr>
                                <tr>
                                    <td>Confirm:</td>
                                    <td>
                                    <input type="password" name="cpass" /></td>
                                </tr>
                                <tr>
                                    <td>
                                    <br><input type="submit" id="sbotton" name="signup" value="Sign Up"/></td>
                                </tr>
                            </table>
                        </form>


                                <?php
                                if(isset($_POST['signup'])){

                                    if($_POST['cpass'] == $_POST['pass']){




                                                        if(empty($_POST['name']) && empty($_POST['email'])) {
                                                        die('<div id="error"><img src="img/wrong.png" width="25px"height="17px"/>Name and email field was empty</div>');
                                                        }
                                                        if(empty($_POST['name'])) {
                                                        die('<div id="error"><img src="img/wrong.png" width="25px"height="17px"/>Name field was empty</div>');
                                                        }
                                                        if(empty($_POST['email'])) {
                                                        die('<div id="error"><img src="img/wrong.png" width="25px"height="17px"/>Email field was empty</div>');
                                                        }
                                                        if(empty($_POST['pass'])) {
                                                        die('<div id="error"><img src="img/wrong.png" width="25px"height="17px"/>Password field was empty</div>');
                                                        }




                                        $query = mysql_query("INSERT INTO members(name,email,password) values('{$_POST['name']}','{$_POST['email']}','{$_POST['pass']}')");
                                        if($query){
                                            echo '<div id="good"><img src="img/right.png" width="25px"height="17px"/>Successful</div>';
                                        }
                                        else{
                                            echo '<div id="error"><img src="img/wrong.png" width="25px"height="17px"/>Invalid! Sign Up Again</div>';
                                        }
                                    }
                                    else{
                                        echo '<div id="error"><img src="img/wrong.png" width="25px"height="17px"/>Password did not match</div>';
                                    }
                                }
                                mysql_close();
                                ?>
                            </center>
                </div>

            <div id="slideshow">
                       <div>
                         <img src="img/1.jpg" width="300px" height="190px">
                       </div>
                       <div>
                         <img src="img/2.jpg" width="300px" height="190px">
                       </div>
                       <div>
                         <img src="img/3.jpg" width="300px" height="190px">
                       </div>
                       <div>
                         <img src="img/4.jpg" width="300px" height="190px">
                       </div>
                       <div>
                         <center>
                         <br><br><br><br>
                         <b style="font-size:3em;font-family:Times New Roman;">KNYWEB</b><br>
                         Designed for you...
                       </div>
                       <img src="img/corner_ribbon.png" class="ribbon" width="100px" height="100px"/>
                </div>

        </div>
    <div id="footer">
        <center><p>
        <b>KNYWEB &copy; 2012</b><br>
        All Rights Reserved.</p></center>
    </div>

</div>

</body>
</html>

Still trying to solve this but the problem is i'm new to php. i tried to find some answers from another source but can't find one. I was hoping that i can find answers here.

die() stops the script, so if any HTML you need is somewhere after that line, it will never be outputted.

I am not an expert with php so others may correct this but I Would do it this way:

<?php
if(isset($_POST['signup'])){

if(!empty($_POST['name']) && !empty($_POST['email'])) {

if(!empty($_POST['name'])) {

if(!empty($_POST['email'])) {

if(!empty($_POST['pass'])) {

if($_POST['cpass'] == $_POST['pass']){

$query = mysql_query("INSERT INTO members(name,email,password) values('{$_POST['name']}','{$_POST['email']}','{$_POST['pass']}')");
if($query) {
echo '<div id="good"><img src="img/right.png" width="25px"height="17px"/>Successful</div>';
}   
}
else{
echo '<div id="error"><img src="img/wrong.png" width="25px"height="17px"/>Passwords do not match</div>';
}
}
else{
echo '<div id="error"><img src="img/wrong.png" width="25px"height="17px"/>Password field is empty</div>';
}
}
else{
echo '<div id="error"><img src="img/wrong.png" width="25px"height="17px"/>Email field is empty</div>';
}
}
else{
echo '<div id="error"><img src="img/wrong.png" width="25px"height="17px"/>Name field is empty</div>';
}
}
else{
echo '<div id="error"><img src="img/wrong.png" width="25px"height="17px"/>Name and email fields are empty</div>';
}
}
else{
echo '<div id="error"><img src="img/wrong.png" width="25px"height="17px"/>Invalid! Sign Up Again</div>';
}
mysql_close();
?>

I'll try this one. Thanks for the reply. Maybe i'll post later if it gives an error. :)

It gives an error directly when i refresh the page. And even if the password's not match it post different error. Maybe can give me some new code or link? I really need it for my project.

sir pritaeas : Thanks for directing in this forum. really appreciate it. Is there any way to do it? I don't have the knowledge to solve this problem. lol

Yes. Make sure your code is not using die() at all, because that is causing the problem. You may have to restructure your ifs and elses to get it working properly.

i tried to use this code:

if(empty($_POST['name'])) {
echo 'Name field was empty';
exit();
}

but i figured that its the same fuction as die(). I dont have much background in php.

sir pritaeas, thanks for your reply and hints. I solved it by putting it in the bottom inside my container under my footer, put the position to relative and adjust the left and bottom. Your reply gives me hint on what to do, maybe i will solve this one sooner or later, but i'll keep it this way for now for my project. Thanks to all who replied. But still counting on your answers and suggestions. Daniweb rocks! Forums are powerful! Keep safe.

Oh, i thought i finally solved it. Still got an error. When i click the botton it displays the prompt of the empty fields, but if i fill it all the Successful message won't display.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.