Results 1 to 7 of 7

Thread: little issue php script

  1. #1
    Join Date
    Jul 2010
    Posts
    64
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Default little issue php script

    Hello everyone,
    Okay, I tried to write this little script in php. I am obviously doing something wrong. I get the following error messages:

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/rosalie/public_html/email.php on line 7

    Warning: Cannot modify header information - headers already sent by (output started at /home/rosalie/public_html/email.php:7) in /home/rosalie/public_html/email.php on line 10


    I want my script first to check whether the entered email address already excists in the database. When this isn't the case it should be added.

    This is my script:

    PHP Code:
    <?php

    include('confform.php');

       
    $query1="SELECT * FROM mailinglist WHERE email ='$email'";
       
    $result1=mysql_query($query1);
       
    $num1=mysql_num_rows($result1);
       
       if(
    $num1 != 0); {
       
    header("Location:notregistered.html");
       }
       
     
       if(
    $num1 == 0); {
       
    $query2="INSERT INTO mailinglist SET email='$email'";
       
    $result2=mysql_query($query2);
       } 
                   
                      if(
    $result2) {
                      
    header("Location:thankyou.html");
                      }
       
    ?>
    Thanks in advance,
    I hope to learn from it.

  2. #2
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    Do this and see if it gives you any other errors, your code looks good to me.
    PHP Code:
    $result1=mysql_query($query1) or die(mysql_error()); 

  3. The Following User Says Thank You to fastsol1 For This Useful Post:

    Rosalie (10-05-2010)

  4. #3
    Join Date
    Jul 2010
    Posts
    64
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by fastsol1 View Post
    Do this and see if it gives you any other errors, your code looks good to me.
    PHP Code:
    $result1=mysql_query($query1) or die(mysql_error()); 
    Thank you for taking the time to help me fastsol1. I don't have any error messages anymore and I can succesfully insert an email address.

    However, I am still able to insert twice the same email address while this shouldn't be possible because of:

    PHP Code:
       if($num1 != 0); { 
       
    header("Location:notregistered.html"); 
       } 
    Does anyone know how I can solve this??

    Thanks in advance

  5. #4
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    actually I am surprised the code didn't throw more errors cause of this but you have ; right after your if() blocks which will end that line and not run the code under it. Take those out and it should work. Sorry I didn't catch that before I was only focused on the num_rows area.

  6. The Following User Says Thank You to fastsol1 For This Useful Post:

    Rosalie (10-05-2010)

  7. #5
    Join Date
    Jul 2010
    Posts
    64
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by fastsol1 View Post
    actually I am surprised the code didn't throw more errors cause of this but you have ; right after your if() blocks which will end that line and not run the code under it. Take those out and it should work. Sorry I didn't catch that before I was only focused on the num_rows area.
    Thanks a lot!! I didn't knew that you shouldn't put ;. I really learned from this

  8. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    the semicolon ends your line of code. so, if($num1 != 0); literally means "if num1 is not 0, do nothing."

  9. The Following User Says Thank You to traq For This Useful Post:

    Rosalie (10-05-2010)

  10. #7
    Join Date
    Jul 2010
    Posts
    64
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by traq View Post
    the semicolon ends your line of code. so, if($num1 != 0); literally means "if num1 is not 0, do nothing."
    Thanks Adrien! I didn't knew that. I thought you had to place ; after every script line

    I made almost all my php scripts with the help of tutorials. The problem is that I often don't really know what everything precisely means. Also when I want to change something it often takes me hours to figure out what causes errors. It is much better to be able to understand the script so that I know what I'm doing.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •