Page 3 of 6 FirstFirst 12345 ... LastLast
Results 21 to 30 of 60

Thread: A new user to php.

  1. #21
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    So Sorry for the late post, I was busy these past couple days...
    --
    I combined your form page and conformation page into one, this now works without session varables and it's easier to understand, and it will be easier to implicate MySQL in the furture.
    Code:
    <?php
    
    function checkphone()    {
    global $tel;
    $phone = $_POST['hometel'];
      if (!preg_match('/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/', $phone)) {
    $tel = '<font color="red"><b>Your telephone number is invalad</b></font>';
    
    }
    else
    {
      
      $GLOBALS['message'] = "true";
      
    }
    $GLOBALS['tel'] = $tel;
    }
    
    if($_POST['submit'])
    {
    checkphone();
     }
     if(!$message){
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>FYP</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    <form action="button.php" enctype="multipart/form-data" method= "post">
        <p align="center">Name:
          <input type="text" name="name" />
    </p>
    <p align="center">Admin No.:
    
      <input type="text" name="admin" />
    </p>
    <p align="center">Gender:
      <select name="gender">
        <option value="male" selected>Male</option>
        <option value="female">Female</option>
          </select>
    </p>
    <p align="center">Address:
      <textarea name="address" cols="40"></textarea />
    </p>
    <p align="center">Home Phone:
    <input type="text" name="hometel" />  <br>
    <?php echo $tel; ?>
    </p>
    <p align="center">Mobile Phone:
    <input type="text" name="hp" />
    </p>
    <p align="center">Contact Email:
    <input type="text" name="email" />
    </p>
    <p align="center">Course:
    <select name="course"></select>
    </p>
    <p align="center">Acad Year:
    <input type="text" name="year" />
    </p>
    <p align="center">Path:
    <select name="path">
      <option value="1">B1</option>
      <option value="2">B2</option>
      <option value="3">B3</option>
    </select>
    </p>
    <p align="center">Project Title:
      <textarea name="title" cols="40"></textarea>
    </p>
    <p align="center">Project Supervisor:
    <select name="supervisor">
      <option value="KC" selected>Mr. Stephen Liew K C</option>
      <option value="ng">Mr. Steven Ng</option>
    </select>
    </p>
    <p align="center">
    <input name="submit" type="submit" />
    </p>
    </form>
    <?php
    } else {
    
    echo'<div align="center">';
    echo '<p>Name:  '.$_POST["name"].' <br />';
    echo 'Admin No.:  '.$_POST["admin"].' <br />';
    echo 'Gender:  '.$_POST["gender"].' <br />';
    echo 'Address: '.$_POST["address"].' <br />';
    echo 'Home Phone:  '.$_POST["hometel"].' <br />';
    echo 'Handphone: '.$_POST["hp"].' <br />';
    echo 'Contact Email:  '.$_POST["email"].' <br />';
    echo 'Course: '.$_POST["course"].' <br />';
    echo 'Acad Year: '.$_POST["year"].' <br />';
    echo 'Path: '.$_POST["path"].' <br />';
    echo 'Project title:'.$_POST["title"].' <br />';
    echo 'Project Supervisor: '.$_POST["supervisor"].' <br />';
    ?>
    <p>
        <input type="submit" name="Submit" value="Submit">
    </p>
      <p>
        <input name="button" type=button onClick=window.history.back() value=Back back>
      </p>
      </div>
      <?php }?>
    </body>
    </html>
    Have any Questions?
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  2. #22
    Join Date
    May 2008
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Sorry for disturbing you when you are so busy. There are several questions I would like to ask about the code you have provided. First would be the <?php }?> located somewhere at the bottom of the code. I would like to know about the function about that. Second would be that the confirmation does not show up after clicking submit. I've tried changing it to a confirmation page I've done using $_post to get the input from the form and it works but the telephone verification does not work when I do this. Could it be due to me using firefox ? Lastly are there any good websites for learning php beside w3school? I feeling kinda bad asking you all this questions when you are busy.

  3. #23
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    Hi, I was just away for a while, and did not get your post, thats what I meant by "busy"
    --
    First would be the <?php }?> located somewhere at the bottom of the code. I would like to know about the function about that.
    You can include html output outside of <?php ?> as long as whatever was started, so somthimge like:
    Code:
    <?php
    if($var == "true")
    {
    ?>
    Some HTML to show is $var is equal to "true"
    <?php
    }
    ?>
    This would be valid.
    ---
    Second would be that the confirmation does not show up after clicking submit.
    It everything works fine on my webserver. http://klein-onlineblog.com/dynamicd...php/button.php See if it works for you there. It should not have anything to do with firefox or IE, because php is serer-side. Can you provide a link to your page online, and what version of php do you have?
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  4. #24
    Join Date
    May 2008
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I'm using php version 5.2.6 and apache version 2.2. I've tried the form on your page and it works well but is there a confirmation page on your website ? I've tried filling out and it gives me invalid phone number. Also I do not know how to bring my form online. I'm using local host and dreamweaver to test out the codes. I need to use MS SQL
    as the database. I'm now learning how to use MS SQL and connecting to the form.

  5. #25
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    Not sure by what you mean "Confirmation". After you enter a corrrect phone number (Ex: 555-555-5555), It will submit the page and all the values will appear. Thats the confirmation page code that you suppliped me with earlier. You could put somthing like: "Please confirm that this info is true, if not, please go back to the form and correct it." Or do you mean somthing like a confirmation email that confirms that the user is human. (you could use CAPTCHA). So what exactly do you mean.
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

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

    jolicious (06-06-2008)

  7. #26
    Join Date
    May 2008
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Oh. Sorry for not being clear. Apparently I was typing in the wrong type of phone number. Thus I was not able to view the page where it ask you to check i f the information you have given was correct. The codes are working fine. Edit: I've changed to function code alittle so that it accepts phone number from my country. Also I also try creating a function for checking email from the code you have gave me. Will the following code work in my program ?
    PHP Code:
    [CODE] <?php


    function checkemail()    {
    global 
    $mail;
    $elmail $_POST['email'];
        if (!
    preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" $email)) {
        
    $mail '<font color="red"><b>Your Email is invalid</b></font>';
        
        }
        else
        {
        
    $GLOBALS['message'] = "true";
        }
        
    $GLOBALS['mail'] = $mail;
        }
        
        if(
    $_POST['submit'])
        {
        
    checkmail();
        }
        if(!
    $message){
        
    ?>[/CODE]
    Last edited by jolicious; 06-06-2008 at 05:54 AM.

  8. #27
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    Hi, sorry for the phone number mix-up but I can see one error with your code:
    $elmail = $_POST['email']; should be $email = $_POST['email'];.
    Also, your preg_match should look like:
    “/^([a-zA-Z0-9])+([a-zA-Z0-9\.\\+=_-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/” - not tested
    This is not totally fool-prof. Something like 1@1.qqq would pass through. You would need to go a lot more complex to catch stuff like that.
    --
    Your original post stated something like "Why doesn't it work on my local machine". Local machine can't do everything, they are not designed to be a web server. Find a free online php hosting site and test it online.
    --
    A couple posts ago you mechined the database "MS SQL". This is not the best database to work with. "My SQL" is much much much easier to work with, and it is free, and versitile. I also recomend getting "phpMySQL" , a free My SQL Management software...
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  9. #28
    Join Date
    May 2008
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Sorry for the slow reply, my internet was down for a few days. Thanks for the correction. For the database, I'm not sure if I'm allowed to use MySQL or any other. I've just send an email to my supervisor asking him if I can use MySQL for my project. I'll try hosting my project online after I'm done with the problem above regrading the database. For the email verification, I'll upgrade it while doing the project and as I learn more about PHP.

  10. #29
    Join Date
    May 2008
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I would like to ask about the following codes :
    PHP Code:
    $email $_POST['email']; 
    Would it cause an error if both of them have the same name ?
    Also is there any other codes I need to add if I were to include the email and telephone verification codes in my form ? I've tried adding both of them into my code and it would not show the confirmation page. After removing the email verification codes, the form would work perfectly fine. Also my supervisor sent me a reply. Due to a typo error, I need to use MS Access instead of MS SQL or MySQL
    Last edited by jolicious; 06-11-2008 at 06:32 AM.

  11. #30
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    Sorry, my email server was down and did not know you replied until now...
    --
    I would like to ask about the following codes :
    PHP Code:
    $email = $_POST['email'];

    Would it cause an error if both of them have the same name ?
    For one, $email = $_POST['email']; does not cause an error because you are setting the local variable $email to the previously posted variable email on the previous page, therefore $email on one page could be totally different on another.
    --
    Also is there any other codes I need to add if I were to include the email and telephone verification codes in my form ? I've tried adding both of them into my code and it would not show the confirmation page. After removing the email verification codes, the form would work perfectly fine.
    Post your code online, and maybe I could debug it, and find out why it's not accepting your functions.
    --
    Also my supervisor sent me a reply. Due to a typo error, I need to use MS Access instead of MS SQL or MySQL
    I am not quite sure about how to use MS Access with php documents, you could do a google search or whatever...
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

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
  •