Page 4 of 6 FirstFirst ... 23456 LastLast
Results 31 to 40 of 60

Thread: A new user to php.

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

    Default

    This is my current code including the email verification codes
    Code:
    <?php
    
    function checkphone()    {
    global $tel;
    $phone = $_POST['hometel'];
      if (!preg_match('/^[0-9]{8}$/', $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){
    ?>
    
    <?php
    
    
    function checkemail()	{
    global $mail;
    $email = $_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){
    	?>
    <!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="project4.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" />
    <?php echo $mail; ?>
    </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="Mr. Stephen Liew K C" selected>Mr. Stephen Liew K C</option>
      <option value="Mr. Steven 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 }?>
      <?php }?>
    </body>
    </html>

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

    Default

    Here, try this:
    Code:
    <?php
    
    function checkphone()    {
    global $tel;
    $phone = $_POST['hometel'];
      if (!preg_match('/^[0-9]{8}$/', $phone)) {
    $tel = '<font color="red"><b>Your telephone number is invalad</b></font>';
      $GLOBALS['tel'] = $tel;       }
     else{
         $GLOBALS['showtel'] = "true";
      }
    }
    
    
     function checkemail()	{
    global $mail;
    $email = $_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>';
    
    	$GLOBALS['mail'] = $mail; }
      else
      {
        $GLOBALS['showmail'] = "true";
      }
    	}
    
     if($_POST['submit'])
    {
    checkphone();
    checkemail();
     }
     	if(!$showtel||!$showmail){
    	?>
    <!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="<?php echo $_SERVER['PHP_SELF']; ?>" 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" /> <br>
    <?php echo $mail; ?>
    </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="Mr. Stephen Liew K C" selected>Mr. Stephen Liew K C</option>
      <option value="Mr. Steven 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>
    -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*

  3. #33
    Join Date
    May 2008
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the code and sorry for the slow reply. I would like to ask whats the difference between Globals and SuperGlobals and what do they do. Thanks

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

    Default

    Globals are variables that are universal throughout the script. So if $var was set inside a function, it could not be accessed by the outside script unless it was a global variable (or vica versa).
    SuperGlobals are variables set by PHP itself. A SuperGlobal variable is something like $_SESSION['var']; or $_SERVER['PHP_SELF'];. You cannot create any new superglobals, but you can set them, like: $_COOKIE['time'] = "November 5 1985";. All superglobals start with $_ to Identify them as superglobals and not any ol' user defined variable.
    Any other 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*

  5. #35
    Join Date
    May 2008
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thank you for your wonderful explanation on globals and superglobals. I would like to ask afew questions. Can php and javascript work properly together ? And is there a function or way to retrieve the data after clicking the submit button when there is an invalid input ? I'm asking those questions as my supervisor suggested that I can use java to solve the problem but as I'm new to programming it would take quite awhile to learn java. I would like to know how to retrieve data from MS access via php too. I've been searching the web for quite awhile now but most of them I've found are using Visual Basic. Some websites states that ODBC connections are required to make a connection. What is the ODBC connections that is stated and how can I get them ?

    Update:I've just came back from my oversea project attachment and now I'm doing my project on another computer with IIS installed into it. I'm manage to setup the IIS and dreamweaver to work together via internet tutorials. However a PHP notice is shown below the form when I run the form. This is the notice : PHP Notice: Undefined index: submit in C:\Inetpub\wwwroot\project5.php on line 28 PHP Notice: Undefined variable: showtel in C:\Inetpub\wwwroot\project5.php on line 33 PHP Notice: Undefined variable: tel in C:\Inetpub\wwwroot\project5.php on line 62 PHP Notice: Undefined variable: mail in C:\Inetpub\wwwroot\project5.php on line 69. No codes were add nor changed during this transition. Thank you for helping me out.
    I've temperarily solved the above problem by using error_reporting(E_ALL ^ E_NOTICE). But is there any other way to solve it ?
    Last edited by jolicious; 06-25-2008 at 01:29 AM.

  6. #36
    Join Date
    May 2008
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Hi, I've managed to connect to MS Access via ODBC. However a new problem has occured. After clicking on the submit button on the confirmation page, the data from the form are supposed to be saved to the database. But each time I click on the submit button, an internal error 500 would occur. I've tried looking for the error and I feel that it could be due to the code not being able to caputure the data from the form.
    Here is the code for the form:

    Code:
    <?php
    error_reporting(E_ALL ^ E_NOTICE);
    ?>
    <?php
    
    function checkphone()    {
    global $tel;
    $phone = $_POST['hometel'];
      if (!preg_match('/^[0-9]{8}$/', $phone)) {
    $tel = '<font color="red"><b>Your telephone number is invalad</b></font>';
      $GLOBALS['tel'] = $tel;       }
     else{
         $GLOBALS['showtel'] = "true";
      }
    }
    
    
     function checkemail()	{
    global $mail;
    $email = $_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>';
    
    	$GLOBALS['mail'] = $mail; }
      else
      {
        $GLOBALS['showmail'] = "true";
      }
    	}
    
     if($_POST['submit'])
    {
    checkphone();
    checkemail();
     }
     	if(!$showtel||!$showmail){
    	?>
    <!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="<?php echo $_SERVER['PHP_SELF']; ?>" 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" /> <br>
    <?php echo $mail; ?>
    </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="Mr. Stephen Liew K C" selected>Mr. Stephen Liew K C</option>
      <option value="Mr. Steven 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 />';
    ?>
    <form action="databaseupdatingtestrun.php" enctype="multipart/form-data" method= "post">
    
    <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 }?>
      </form
      
    
    
    </body>
    </html>
    And here is the code for submitting into the database:
    Code:
    <?php
    error_reporting(E_ALL ^ E_NOTICE);
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <?php
    $name = $_POST['name'];
    $admin = $_POST['admin'];
    $gender = $_POST['gender'];
    $address = $_POST['address'];
    $hometel = $_POST['hometel'];
    $hp = $_POST['hp'];
    $email = $_POST['email'];
    $course = $_POST['course'];
    $year = $_POST['year'];
    $path = $_POST['path'];
    $title = $_POST['title'];
    $supervisor = $_POST['supervisor'];
    $odbc = odbc_connect('FYP', '', '') or die('Could not connect to ODBC database!');
    $query = "INSERT INTO fyp (Name, AdminNumber, Gender, Address, Hometelephone, MobilePhone, Email, AcadCourse, Year, Path ,Projecttitle, ProjectSupervisor) VALUES ("$name", "$admin", "$gender", "$address", "$hometel", "$hp", "$email", "$course", "$year", "$path", "$title", "$supervisor")";
    $result = odbc_exec($odbc, $query) or die (odbc_errormsg());
    odbc_close($odbc);
    ?>
    </body>
    </html>

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

    Default

    I've found the code thats producing the error its in the database submittion codes. The code thats give an error is :
    Code:
    <?php
    error_reporting(E_ALL ^ E_NOTICE);
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    <?php
    echo "Your data is successfully submitted";
    ?>
    <?php
    $name = $_POST['name'];
    $admin = $_POST['admin'];
    $gender = $_POST['gender'];
    $address = $_POST['address'];
    $hometel = $_POST['hometel'];
    $hp = $_POST['hp'];
    $email = $_POST['email'];
    $course = $_POST['course'];
    $year = $_POST['year'];
    $path = $_POST['path'];
    $title = $_POST['title'];
    $supervisor = $_POST['supervisor'];
    $odbc = odbc_connect('FYP', '', '') or die('Could not connect to ODBC database!');
    $input = "INSERT INTO fyp (Name, AdminNumber, Gender, Address, Hometelephone, MobilePhone, Email, AcadCourse, Year, Path ,Projecttitle, ProjectSupervisor) VALUES ("$name", "$admin", "$gender", "$address", "$hometel", "$hp", "$email", "$course", "$year", "$path", "$title", "$supervisor")";
    $result = odbc_exec($odbc, $input) or die (odbc_errormsg());
    odbc_close($odbc);
    ?>
    </body>
    </html>
    If i change the " to ', it will submit an empty data input to my database. It seems it can't retreive the data from the form. Can anyone help me out on this code ?
    Last edited by jolicious; 06-30-2008 at 09:44 AM.

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

    Default

    O.K. I am so sorry that I have not replyed to any of your posts this past week. I am currently on vacation right now and will be come for a few days but then I will be away again for about two more weeks. I am writing to you from a public library, so please do not take this personal . I may be able to reply to your upcoming posts, but it may take a while.
    -----
    POST 1:
    Can php and javascript work properly together ?
    Yes, very well, it all depends on what your goal that your trying to reach
    --
    And is there a function or way to retrieve the data after clicking the submit button when there is an invalid input ? I'm asking those questions as my supervisor suggested that I can use java to solve the problem but as I'm new to programming it would take quite awhile to learn java. I would like to know how to retrieve data from MS access via php too. I've been searching the web for quite awhile now but most of them I've found are using Visual Basic. Some websites states that ODBC connections are required to make a connection. What is the ODBC connections that is stated and how can I get them ?
    I am sorry that I cannot really help you with this part, I ownly know 1 database language and that's MySQL.
    --
    However a PHP notice is shown below the form when I run the form. This is the notice : PHP Notice: Undefined index: submit in C:\Inetpub\wwwroot\project5.php on line 28 PHP Notice: Undefined variable: showtel in C:\Inetpub\wwwroot\project5.php on line 33 PHP Notice: Undefined variable: tel in C:\Inetpub\wwwroot\project5.php on line 62 PHP Notice: Undefined variable: mail in C:\Inetpub\wwwroot\project5.php on line 69. No codes were add nor changed during this transition. Thank you for helping me out.
    I've temperarily solved the above problem by using error_reporting(E_ALL ^ E_NOTICE). But is there any other way to solve it ?
    Try using echo phpinfo(); in both enviorments and compare them and see what you need to switch on or off for this to work correctly.

    ----
    POST 2\3:

    In your second post you have one error that could be causing everything to mess up:
    <form action="databaseupdatingtestrun.php" enctype="multipart/form-data" method= "post">

    That should be this
    <form action="databaseupdatingtestrun.php" enctype="multipart/form-data" method="post">

    Try that and maybe that might solve the question on your Third post
    Any more 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*

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

    Default

    Sorry for disturbing you on your vacation. I've tried deleting the empty space but the error is still there. I've tried using a simple code to test if the data can be captured but it still display as a black space.
    This is the code :
    Code:
    <?php
    echo "Your data is successfully submitted";
    ?>
    <?php
    
    echo '<p>Name:  '.$_POST['name'].' <br />';
    
    ?>
    Its ok if you are too busy. You have been really helpful and I thank you from the bottom of my heart.

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

    Default

    This:

    echo '<p>Name: '.$_POST['name'].' <br />';

    Should be this:

    echo '<p>Name: '.$_POST["name"].' <br />';

    or even:

    echo "<p>Name: $_POST['name'] <br />";

    Did this solve your problem?
    -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
  •