SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 49 of 49
  1. #26
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    if there are no errors, you don't define the $message variable. To avoid the error, just put the next line before you start checking the form data:

    $message = "";

  2. #27
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    dbconn.inc


    PHP Code:
    <?php 
    $link
    ;
    $link what?

    If you want to define it, write

    PHP Code:
    $link ""

  3. #28
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, thanks

    How about the button 'Undefined Index' message? It is this that must be causing the page not to be redirected.

  4. #29
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Oracle,
    I have simplified the code a bit. You can add your error functions and cleanMemberSession in as you like.

    PHP Code:
    <?
    # put your connections into a normal php page and include them....
        #$link = mysql_connect("localhost","root","quiksilver"); 

    # incoming link from previous page. Defined as 'action'
    # Use either text link or graphical button, if you do use a form set the method to GET
    # set the links like <a href="formpage.php?action=page_1">link</a>

    if(isset($_GET['action'])) {
    if(
    $_GET['action'] == 'page1') {
    $redirect "redirect_page_1.php";

    if(
    $_GET['action'] == 'page2') {
    $redirect "redirect_page_2.php";

    if(
    $_GET['action'] == 'page3') {
    $redirect "redirect_page_3.php";

    if(
    $_GET['action'] == 'page4') {
    $redirect "redirect_page_4.php";

    }
    if(isset(
    $_POST['formsubmit'])) {
    $error_header "The following errors occurred, please correct them<br>";
    #put in your error checking
    if(!$_POST['email']) {
    $error_msg "Please Fill in the email field<br>";
    }
    if(!
    $_POST['password']) {
    # note the .= bit.
    $error_msg .= "Please fill in the password field<br>";
    }
    if(!
    $error_msg) {
    mysql_select_db($dbase$link);
    $result=mysql_query("insert into user_details (username, password) 
                            values('
    $login', '$pass')") or die(mysql_error()); 
                            
        
    header("Location: ".$redirect);
    }
    ?>
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <? if(isset($error_msg)) { 
        echo 
    $error_header."<br>"$error_msg;
        } 
    ?>
    <form action="<? $_SERVER['PHP_SELF']; ?>" method="post" name="email">
      <input type="text" name="email">
      email<br>
      <input type="password" name="password">
      password <br>
      <input type="submit" name="Submit" value="Submit">
      <input type="reset" name="reset" value="Reset">
    </form>
    </body>
    </html>
    Should work but I haven't tested it.

    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #30
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SpikeZ,

    Thanks very much for your help, but there appears to be bits missing (other than what you have specified).

    Mainly, the GetRow function which checks against the database and stops duplicate rows being added.

    I'm also not that clear on what I need to include. Do I keep my original dbconn.inc file and funclib.inc file.

    Also, on the redirects at the top, should I still use SID, and if so what exactly does this do (some kind of Session thing??).

    Sorry, but as I am quite new to PHP it kinda makes a bit harder to decipher someone elses code.

    Many thanks

  6. #31
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Oracle,
    SID is the Session Id and is useful for tracking purposes.
    Below is the revised code
    create a php page with the first part called link.php
    PHP Code:
    # link.php
    <?php
    $hostname_pdb_conn 
    "host";
    $database_pdb_conn "database";
    $username_pdb_conn "username";
    $password_pdb_conn "password";
    $link mysql_pconnect($hostname_pdb_conn$username_pdb_conn$password_pdb_conn) or trigger_error(mysql_error(),E_USER_ERROR); 
    ?>




    <?
    require_once('link.php');
    include(
    "includes/funclib.inc"); 
    # put your connections into a normal php page and include them....
        #$link = mysql_connect("localhost","root","quiksilver"); 

    # incoming link from previous page. Defined as 'action'
    # Use either text link or graphical button, if you do use a form set the method to GET
    # set the links like <a href="formpage.php?action=page_1">link</a>

    if(isset($_GET['action'])) {
    if(
    $_GET['action'] == 'page1') {
    $redirect "redirect_page_1.php";

    if(
    $_GET['action'] == 'page2') {
    $redirect "redirect_page_2.php";

    if(
    $_GET['action'] == 'page3') {
    $redirect "redirect_page_3.php";

    if(
    $_GET['action'] == 'page4') {
    $redirect "redirect_page_4.php";

    }
    if(isset(
    $_POST['formsubmit'])) {
    $error_header "The following errors occurred, please correct them<br>";
    #put in your error checking
    if(!$_POST['email']) {
    $error_msg "Please Fill in the email field<br>";
    }
    if(!
    $_POST['password']) {
    # note the .= bit.
    $error_msg .= "Please fill in the password field<br>";
    }
    if(
    strlen($password) > 8
            
    $error_msg .= "Your password must be less than 8 characters<br>"
    if (!
    preg_match('/^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/',$login)) 
            
    $error_msg .= "Please enter a valid email address<br>" 
        
    # check for duplicate rows etc
    $rowCheck mysql_query("select username from user_details where username = ".$_POST['username']);
    if(
    mysql_num_rows($rowCheck >0) {
    $error_msg .= "The username/ email already exists, please select another one";
    }
    ###########
    if(!$error_msg) {
    # your function #
       
    cleanMemberSession($id$login$password); 
    ##
    mysql_select_db($database_pdb_conn$link);
    $result=mysql_query("insert into user_details (username, password) 
                            values('
    $login', '$pass')") or die(mysql_error()); 
                            
        
    header("Location: ".$redirect);
    }
    ?>
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <? if(isset($error_msg)) { 
        echo 
    $error_header."<br>"$error_msg;
        } 
    ?>
    <form action="<? $_SERVER['PHP_SELF']; ?>" method="post" name="email">
      <input type="text" name="email">
      email<br>
      <input type="password" name="password">
      password <br>
      <input type="submit" name="Submit" value="Submit">
      <input type="reset" name="reset" value="Reset">
    </form>
    </body>
    </html>
    Functions are vital for things that you will be using time and time again, however if you are just using it once like the checkRows here, just do a basic select check.

    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  7. #32
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey SpikeZ,

    Did you also miss out a hidden field or something for the 'formsubmit' variable? And the form should have 2 password fields. Not sure if that makes a difference to your code?

    Is the $dbase variable supposed to be a mysql_select_db in one of the includes?

  8. #33
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Yep, missed out the hidden field, just checking you were paying attention!

    I also missed out mysql_select_db($database_pdb_conn, $link); before the duplicate check and yes, this is the link to $link.php

    For the two passwords, simply put back the bit of code from your original script that reads
    PHP Code:
    if($password!=$password2) {
            
    $message .= "<span class='style32'>Your passwords did not match<BR></span> \n"

    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  9. #34
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi SpikeZ, I had to fiddle with the syntax a little (FEW ERRORS), BUT i GOT IT TO DISPLAY THE FORM, AND NOW WHEN i ENTER SOMETHING i GET:

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\phpWeb\Right-Track\authtest.php on line 50

    This is the line:

    PHP Code:
    if(mysql_num_rows($rowCheck 0)) 
    Any ideas?

  10. #35
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SpikeZ,

    I also tried changing it to:
    PHP Code:
    $rowCheckResult mysql_num_rows($rowCheck);
    if(
    $rowCheckResult 0
    but I still get the same error

  11. #36
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    OK, change this bit
    PHP Code:
    $rowCheck mysql_query("select username from user_details where username = ".$_POST['username']); 
    to
    PHP Code:
    $rowCheck mysql_query("select username from user_details where username = ".$_POST['username']) or die(mysql_error()); 
    This will give you the error code and give you a clue what's going on.

    Just passing through BTW so will only be online for 30minutes or so!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  12. #37
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I get this when running the script:

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

  13. #38
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I fixed that error.

    Only problem I have now is that even if I put in a valid email address it comes up with, please enter a valid email address. Every time!!!!

  14. #39
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Sorry was a bit tired yesterday,
    this line
    PHP Code:
    if(mysql_num_rows($rowCheck >0) { 
    should have read...
    PHP Code:
    if(mysql_num_rows($rowCheck 0) { 
    so that if the result is 0, add to the error message.

    Sorry bud, my bad

    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  15. #40
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi SpikeZ,

    Thanks. I did try that ,but it wasn't even getting that far. The error was in the select. The $_POST['username'] should have read = ' ".$_POST['username']" ' ")

    This seemed to stop the error occuring. Although, as per my previous post, it just says 'Please enter a valid email address' all the time now (once data is submitted) even if it is a valid email address!

    Any ideas?

  16. #41
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    THis is the code as it now stands:

    PHP Code:
    <?php
    ob_start
    ();
    require_once(
    'includes/link.php'); 
    include(
    "includes/funclib.inc"); 

    # incoming link from previous page. Defined as 'action' 
    # Use either text link or graphical button, if you do use a form set the method to GET 
    # set the links like <a href="formpage.php?action=page_1">link</a> 

    if(isset($_GET['action']))     //variable set by URL on index.php

        if(
    $_GET['action'] == 'page_1'
        { 
        
    $redirect "redirect_page_1.php"
        } 
        if(
    $_GET['action'] == 'page_2'
        { 
        
    $redirect "redirect_page_2.php"
        } 
        if(
    $_GET['action'] == 'page_3'
        { 
        
    $redirect "redirect_page_3.php"
        } 
        if(
    $_GET['action'] == 'page_4'
        { 
        
    $redirect "redirect_page_4.php"
        } 

    if(isset(
    $_POST['formsubmit']))  //run when form submitted

        
    $error_header "The following errors occurred, please correct them<br>"

        if(!
    $_POST['email']) 
        { 
        
    $error_msg "Please Fill in the email field<br>"
        } 
        if(!
    $_POST['password']) 
        { 
        
    $error_msg .= "Please fill in the password field<br>"
        } 
        if(
    $_POST['password']!=$_POST['password2'])
        { 
        
    $message .= "<span class='style32'>Your passwords did not match<BR></span> \n"
        }
        if(
    strlen($password) > 8)
        { 
        
    $error_msg .= "Your password must be less than 8 characters<br>"
        }
        if (!
    preg_match('/^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/',$login)) 
        {
        
    $error_msg .= "Please enter a valid email address<br>" 
        } 
        
    $rowCheck mysql_query("select username from user_details where username = '".$_POST['username']."'")  or die(mysql_error());      // check for duplicate rows
        
    if (mysql_num_rows($rowCheck) > 0)
        {
        
    $error_msg .= "This email address has already been used, If you would like to make another application, please contact us by telephone";
        }
        if(!
    $error_msg)     // run this if no errors
        

        
    cleanMemberSession($id$login$password);  //set session variables
        
    mysql_select_db($database_pdb_conn$link); 
        
    $result=mysql_query("insert into user_details (username, password) 
                            values('
    $login', '$pass')") or die(mysql_error()); 
        
    header("Location: ".$redirect); 
        }

    ?>

  17. #42
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I figured it out. The error checking for the email address is still looking for the $login variable which has changed to $_POST['email'], and also the select is trying to find &_POST['username'] instead of $_POST['email']. I have now changed both of these, but I think there is an error in the syntax somewhere becasue when I submit the form now I get:

    Duplicate entry '' for key 2

    Any ideas?

  18. #43
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    OK, so now we have got past all the error checking etc and are up to the insert query.

    Check that the variables $login and $pass are correct and exist. Also check your database table settings to see if there are any unecessary line entries.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  19. #44
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thankyou sooo much for all your help SpikeZ

    I changed the insert statement to read:

    PHP Code:
    $result=mysql_query("insert into user_details (username, password) 
                            values('"
    .$_POST['email']."', '".$_POST['password']."')") or die(mysql_error()); 
    And I then checked in phpMyAdmin and it had inserted the correct data into the table and redirected me to the specified page.

    I have now checked all of the error checking aswell, and the only bit that doesn't work is the following:

    PHP Code:
    if($_POST['password']!=$_POST['password2'])
        { 
        
    $message .= "<span class='style32'>Your passwords did not match<BR></span> \n"
        } 
    Is it a syntax thing again? It just accepts the values and redirects.

  20. #45
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, ignore me, I hadn't changed the variable from $message to $error_msg

    D'oh!

    Thanks again SpikeZ. I'm sure I'll need to call on you for help again!

  21. #46
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    No problem Oracle,

    Good luck with the rest of it!

    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  22. #47
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Haha, I knew it was too good to be true. Not really.

    Just a quick one. What is the value of adding .SID after .$redirect i.e. .$redirect.SID

    I still wasn't sure what it did?

  23. #48
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    SID is the unique id of the generated session you are currently using. It's is good for monitoring users and also for security if you use the session id as your session name.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  24. #49
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, so is it supposed to show up at the end of the URL when they are redirected, or is it hidden?


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
  •