Computer ForumsComputers  

Go Back   Computer Forums > Programmers Lounge > Programming Discussions

Reply
 
LinkBack Thread Tools Display Modes
Old 08-22-2008, 06:20 AM   #1 (permalink)
Newb Techie
 
Join Date: Jan 2008
Posts: 15
Question PHP / MySQL (Die)

Hi,

Could anyone help?!

I have some code that checks to see if some fields are filled in and then if they are it adds them to a database, if not display a message and kill the command (die).

But it gets to die and it doesn't write the rest of the page.

This is some of the code:

PHP Code:
if(isset($_POST['join'])){
   
/* Make sure fields are entered */
   
if(!$_POST['firstname'] || !$_POST['surname']){
      die(
'You haven\'t filled in all the fields!');
   } 
But when the page is generated this is what happens:

HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Registration Page</title> </head> <body> <h1>Register</h1>
You haven't filled in all the fields!
And it doesn't write the rest of the page.

I could make it write the rest of the page in the IF statement but I don't want to do that because the content could change and there is a lot to come after it.

Please suggest something!

Thanks

Dave
! Whitey ! is offline   Reply With Quote
Old 08-22-2008, 07:35 AM   #2 (permalink)
Every Kudo = 1 Puppy Dead
 
zedman3d's Avatar
 
Join Date: Oct 2007
Posts: 1,192
Default Re: PHP / MySQL (Die)

Does it do it if you change die to echo?
__________________


My pick up line is: I know Vernong.
Trotter: "Ask all the questions you want... whatever we don't know, we'll make
up something that sounds pretty good."

zedman3d is offline   Reply With Quote
Old 08-22-2008, 08:01 AM   #3 (permalink)
Newb Techie
 
Join Date: Jan 2008
Posts: 15
Default Re: PHP / MySQL (Die)

Hi,

If I change it to echo it will work, but then it will add to the database, when I don't want it to because it doesn't end the query.
! Whitey ! is offline   Reply With Quote
Old 08-22-2008, 08:42 AM   #4 (permalink)
Every Kudo = 1 Puppy Dead
 
zedman3d's Avatar
 
Join Date: Oct 2007
Posts: 1,192
Default Re: PHP / MySQL (Die)

Sorry im not following why you dont want to use an IF statement. Its late and its hard to understand. Haha.

Die pretty much means, end the entire page from that point, just if you where wondering. Explain a bit more and ill try to help. Thanks.
__________________


My pick up line is: I know Vernong.
Trotter: "Ask all the questions you want... whatever we don't know, we'll make
up something that sounds pretty good."

zedman3d is offline   Reply With Quote
Old 08-22-2008, 09:14 AM   #5 (permalink)
Newb Techie
 
Join Date: Jan 2008
Posts: 15
Default Re: PHP / MySQL (Die)

Ok,

I will rephrase what I want it to do I'm probably not explaining it properly.

I want the IF statement, I got it to check if the fields are filled in. If they are then I want it to insert it into the database, if not I want it to end the query so it doesn't insert into the database and display a message in the page.

Hope this is a better explanation?!

Thanks for your help!
! Whitey ! is offline   Reply With Quote
Old 08-22-2008, 04:28 PM   #6 (permalink)
Master Techie
 
CrazeD's Avatar
 
Join Date: Feb 2006
Location: Maine
Posts: 2,941
Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: PHP / MySQL (Die)

PHP Code:
<?php

if (isset($_POST['join'])) {
    
$firstname $_POST['firstname'];
    
$surname   $_POST['surname'];
    
    if(empty (
$firstname) || empty ($surname)) {
        echo 
'You haven\'t filled in all the fields!';
    } else {
        
$sql mysql_query ("INSERT INTO table (firstname,surname) VALUES ('".$firstname."','".$surname."')");
        echo 
'Your entry has been saved to the database!';
    }
} else {
    
// get form
}

?>

__________________

Need website help? PM me!
CrazeD is online now   Reply With Quote
Old 08-22-2008, 08:10 PM   #7 (permalink)
Every Kudo = 1 Puppy Dead
 
zedman3d's Avatar
 
Join Date: Oct 2007
Posts: 1,192
Default Re: PHP / MySQL (Die)

^ Exactly.
__________________


My pick up line is: I know Vernong.
Trotter: "Ask all the questions you want... whatever we don't know, we'll make
up something that sounds pretty good."

zedman3d is offline   Reply With Quote
Old 08-26-2008, 04:22 AM   #8 (permalink)
Newb Techie
 
Join Date: Jan 2008
Posts: 15
Default Re: PHP / MySQL (Die)

Thanks,

I kinda knew that and needed pushing in the right direction I was being dumb!
! Whitey ! is offline   Reply With Quote
Reply

Tags
die, mysql, php

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
connecting mysql database with php linux1880 Programming Discussions 5 04-27-2008 08:41 AM
Calling all PHP and MySql experts murdocsvan Programming Discussions 4 04-17-2008 01:51 PM
Restoring my forum from a MySQL backup, I need help! White_Wolf Web Site Hosting / ISP Q & A 2 01-24-2008 07:28 PM
Mysql and PHP on windows. Driving me mental. dakta Web Site Hosting / ISP Q & A 2 11-07-2007 05:38 AM
New Site Project - Flash + PHP + MySQL + CSS theone_trent Web Graphics, design, digital images 2 06-30-2007 01:12 PM


All times are GMT -5. The time now is 10:01 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0