Page 2 of 6 FirstFirst 1234 ... LastLast
Results 11 to 20 of 60

Thread: A new user to php.

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

    Default

    This is farily easy to do, I could show you how, but is your form's html already done? Or do you need to start from scatch?
    -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. #12
    Join Date
    May 2008
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I've already done the form codes. Its quite messy but it will do fine for now. If you want I could post the codes here. Thanks for your help.

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

    Default

    Yea, please. Also have you made any php emailing script to process your form?
    -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. #14
    Join Date
    May 2008
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    <!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="confirmation.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" />
    </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>
    </body>
    </html>

    There are the codes for my form. There is a confirmation page but that is not finish yet. For the emailing scripts, I don't need them for now as I need to show my supervisor the confirmation page shows up after submitting. I have not connect to the database yet as I have yet to install MS SQL. After all this is done I might have to integrate them into Joomla.

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

    Default

    Try this:
    Code:
    <?php
    session_start();
    function checkphone()    {
    $phone = $_POST['hometel'];
      if (!preg_match('/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/', $phone)) {
    echo '<font color="red"><b>Your telephone number is invalad</b></font>';
    }
    else
    {
      foreach($_POST as $variable => $value)
      {
        $_SESSION[$variable] = $value;
      }
      header("location: conformation.php");
    }
    
       }
    ?>
    <!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 checkphone();?>
    </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>
    </body>
    </html>
    --Just change your form action to whatever the page that it is on.
    --You can custimize the looks later, this is just a basic framework of it.
    --Change all of your $_POST[...]; on your confrimation page to $_SESSION[...]; and add session_start(); to it too.
    -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. #16
    Join Date
    May 2008
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the code. Could you teach me how the following code works as i would like to learn more about it. I tried using your code but after applying the code, the words your telephone number is invalid shows up before the form is submitted. Also I would like to know about session_start() too.
    Code:
    function checkphone()    {
    $phone = $_POST['hometel'];
      if (!preg_match('/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/', $phone)) {
    echo '<font color="red"><b>Your telephone number is invalid</b></font>';
    }
    else
    {
      foreach($_POST as $variable => $value)
      {
        $_SESSION[$variable] = $value;
      }
      header("location: conformation.php");
    }
    I've also create a confirmation page. But using the echo $_session, I can't get it to display anything. When i try it gives me a blank page. If its too much please tell me as I won't mind. I'm very new to this as this is my first time touching php, dreamweaver adn MS SQL.
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>confirmation page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    <?php
    session_start();
    
    
    
    <div align="center">
     
      <p>Name: echo $_SESSION["name"] <br />
    Admin No.: echo $_SESSION["admin"] <br />
    Gender: echo $_SESSION["gender"] <br />
    Address: echo $_SESSION["address"] <br />
    Home Phone: echo $_SESSION["hometel"] <br />
    Handphone: echo $_SESSION["hp"] <br />
    Contact Email: echo $_SESSION["email"] <br />
    Course: echo $_SESSION["course"] <br />
    Acad Year: echo $_SESSION["year"] <br />
    Path: echo $_SESSION["path"] <br />
    Project title: echo $_SESSION["title"] <br />
    Project Supervisor: echo $_SESSION["supervisor"] <br />
    
    </p>
    
      <p>
        <input type="submit" name="Submit" value="Submit">
    </p>
      <p>
        <input name="button" type=button onClick=window.history.back() value=Back back>
      </p>
      
      
    </div>
    ?>
    
    </body>
    </html>
    Last edited by jolicious; 05-29-2008 at 02:08 AM.

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

    Default

    Ok I will break it down for you:
    function checkphone() { is the start of a function called checkphone.

    $phone = $_POST['hometel']; this is assigning $phone to the hometel value just submitted.
    if (!preg_match('/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/', $phone)) { this is the hard part to get, the stuff inside preg_match is a pattern.:
    ^: is the start of the line, [0-9] are optional characters, {3} is the amount it is repeated. etc... and the "!" before means "if it is not equal to".

    echo '<font color="red"><b>Your telephone number is invalid</b></font>'; } is the code that is outputed when it is invalid.
    else { foreach($_POST as $variable => $value) { is stating that if the phone nuber is valid, then turn all of the posted variables into varibales.
    $_SESSION[$variable] = $value; this sets each variable to a session.
    header("location: conformation.php"); this relocates you to conformation.php.
    ---
    session_start() is how you introduce a page to a session. put this on each page the requires $_SESSION, like conformation.php. if you want to end a session and destroy all session varibles use session_destroy();
    ---
    You can't put html in php on your conformation page
    Try this
    :
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>confirmation page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    <?php
    session_start();
    
    
    
    <div align="center">
     
    echo '<p>Name:  '.$_SESSION["name"].' <br />';
    echo 'Admin No.:  '.$_SESSION["admin"].' <br />';
    echo 'Gender:  '.$_SESSION["gender"].' <br />';
    echo 'Address: '.$_SESSION["address"].' <br />';
    echo 'Home Phone:  '.$_SESSION["hometel"].' <br />';
    echo 'Handphone: '.$_SESSION["hp"].' <br />';
    echo 'Contact Email:  '.$_SESSION["email"].' <br />';
    echo 'Course: '.$_SESSION["course"].' <br />';
    echo 'Acad Year: '.$_SESSION["year"].' <br />';
    echo 'Path: '.$_SESSION["path"].' <br />';
    echo 'Project title:'.$_SESSION["title"].' <br />';
    echo 'Project Supervisor: '.$_SESSION["supervisor"].' <br />';
    echo '
    </p>
    
      <p>
        <input type="submit" name="Submit" value="Submit">
    </p>
      <p>
        <input name="button" type=button onClick=window.history.back() value=Back back>
      </p>
      
      
    </div>';
    ?>
    
    </body>
    </html>
    There could be a problem, try it out and tell me what happens.
    -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*

  8. #18
    Join Date
    May 2008
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Sorry for the late reply. I've tried the code you've gave me but also gives me an error where nothing shows up.

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

    Default

    Sorry, I missed two key errors:
    1. session_start(); should be before any outputted text...
    2. <div align="center"> should be echo '<div align="center">';
    Full code:
    Code:
    <?php
    session_start();
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>confirmation page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    <?php
    
    
    
    echo'<div align="center">';
    
    echo '<p>Name:  '.$_SESSION["name"].' <br />';
    echo 'Admin No.:  '.$_SESSION["admin"].' <br />';
    echo 'Gender:  '.$_SESSION["gender"].' <br />';
    echo 'Address: '.$_SESSION["address"].' <br />';
    echo 'Home Phone:  '.$_SESSION["hometel"].' <br />';
    echo 'Handphone: '.$_SESSION["hp"].' <br />';
    echo 'Contact Email:  '.$_SESSION["email"].' <br />';
    echo 'Course: '.$_SESSION["course"].' <br />';
    echo 'Acad Year: '.$_SESSION["year"].' <br />';
    echo 'Path: '.$_SESSION["path"].' <br />';
    echo 'Project title:'.$_SESSION["title"].' <br />';
    echo 'Project Supervisor: '.$_SESSION["supervisor"].' <br />';
    echo '
    </p>
    
      <p>
        <input type="submit" name="Submit" value="Submit">
    </p>
      <p>
        <input name="button" type=button onClick=window.history.back() value=Back back>
      </p>
    
    
    </div>';
    ?>
    
    </body>
    </html>
    -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*

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

    Default

    Thanks you for the code. I've would like to ask if I left 1 option for the form blank as I don't know what I should include inside the option, would it disrupt the confirmation page? Because I've tried your code and it displays the words like Name:, Gender:, etc but it does not show the information typed into the form. I'm grateful for all of your help.

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
  •