Page 5 of 6 FirstFirst ... 3456 LastLast
Results 41 to 50 of 60

Thread: A new user to php.

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

    Default

    Thanks for the code. It seems that it works but once I start trying to connect to the database, it gives me internal error 500. This is the code that I've used
    [CODE<?php
    $FName = $_POST['FName']
    $odbc = odbc_connect('FYP', '', '') or die('Could not connect to ODBC database!');
    $start = "INSERT INTO babel (Name) Values ('$FName')";
    $insert = odbc_exec($start,$odbc);

    ?>[/CODE]
    Last edited by jolicious; 07-02-2008 at 01:22 AM.

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

    Default

    $FName = $_POST['FName'] should be $FName = $_POST['FName'];
    This could be interfering with the next line therefore causeing the error...
    -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. #43
    Join Date
    May 2008
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the input but the problem still remains. I've tried checking for permission and everything seems to be in order. The database IDs are also identical to those in the code. I'm not sure what is wrong with my program.

  4. #44
    Join Date
    Jul 2007
    Location
    Azerbaijan, Baku
    Posts
    144
    Thanks
    11
    Thanked 27 Times in 25 Posts

    Default

    jolicious, Can you copy your full code?

    And i think you know, form method must be post. I mean:
    Code:
    <form method="post">
    <input type="text" name="FName"/>
    </form>

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

    Default

    Sure. After clicking submit on the confirmation page, it would show page cannot be display when it is actually suppose to insert the data into the database.
    this is the form's code:

    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']; ?>" method="post">
        <p align="center">Name:
          <input type="text" name="username" />
    </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">
      <option value="ECC">ECC</option>
    </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 {
    ?>
    <form action="datasubmit.php"  method="post">
    <?php
    
    echo'<div align="center">';
    echo '<p>Name:  '.$_POST["username"].' <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">
    	</form>
    </p>
      <p>
        <input name="button" type=button onClick=window.history.back() value=Back back>
      </p>
      </div>
      <?php }?>
      
    </body>
    </html>


    This is the data submittion codes:

    Code:
    <!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
    $username = $_POST['username'];
    $admin = $_POST['admin'];
    $gender = $_POST['gender'];
    $address = $_POST['address'];
    $phone = $_POST['hometel'];
    $hp = $_POST['hp'];
    $email = $_POST['email'];
    $course = $_POST['course'];
    $year = $_POST['year'];
    $path = $_POST['path'];
    $title = $_POST['title'];
    $supervisor = $_POST['supervisor'];
    echo "Data has been submitted";
    
    function Enter_New_Entry($username,$admin) {
    
      
        $cnx = odbc_connect( 'FYP' , 'root', '' );
        if (!$cnx) {
            Error_handler( "Error in odbc_connect" , $cnx );
        }
        $SQL_Exec_String = "Insert Into fyp (name, admin, gender, address, hometel, hp, email, course, year, path, title, supervisor )
                Values ('$username', '$admin', '$gender', '$address', '$phone', '$hp', '$email', '$course', '$year', '$path', '$title', '$supervisor')";
    
        $cur= odbc_exec( $cnx, $SQL_Exec_String );
        if (!$cur) {
            Error_handler( "Error in odbc_exec( no cursor returned ) " , $cnx );
        }
    
        odbc_close( $cnx);
    }
    Enter_New_Entry($username,$admin);
    ?>
    
    </body>
    </html>

  6. #46
    Join Date
    Jul 2007
    Location
    Azerbaijan, Baku
    Posts
    144
    Thanks
    11
    Thanked 27 Times in 25 Posts

    Default

    Can you copy the error here too

    I think your problem is in your db connection... But copy error here first

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

    Default

    Is there a way to get an error report from IE ? After running the script, I get HTTP 500 internal server error. I heard there is a way to get a more detailed report but I don't know how.

  8. #48
    Join Date
    Jul 2007
    Location
    Azerbaijan, Baku
    Posts
    144
    Thanks
    11
    Thanked 27 Times in 25 Posts

    Default

    Does the script works? or no?

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

    Default

    The codes for the form works but the code in for data submitting do not work. It would display "The page cannot be displayed and HTTP 500 - Internal server error ".

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

    Default

    Try using the die(); function to show errors. Like:
    Code:
    if(!$cnx = odbc_connect( 'FYP' , 'root', '' ))die("error with connection");
    And allahverdi, he is using a local enviorment, so there could be some local interference.
    And jolicious, I would EXTREAMLY RECOMEND uploading your page to a free php hosting service. Also a free MS SQL hosting. For php hosting, I recomend AwardSpace. As for MS SQL, Biz Host Net or just google it and see what more you can find...
    -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
  •