Jump to content

Inserting data


jo

Recommended Posts

Hi everyone, I'm not sure where to post this post as I can't find a relevant place to post it. I'm doing an online form and want to save the data into the MS Access databse. However I can't insert any data as it would give me a HTTP 500 internal error. Can anyone help me out on this ? Here are the codes for the form and data submitting.

Form:

 

<?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="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 {
?>
<form action="datasubmit.php" enctype="multipart/form-data" method="post">
<?php

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">
</form>
</p>
  <p>
    <input name="button" type=button onClick=window.history.back() value=Back back>
  </p>
  </div>
  <?php }?>
  
</body>
</html>

and here is the data submitting codes:

<?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'];
?>
<?php

$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>

Link to comment
https://forums.phpfreaks.com/topic/112898-inserting-data/
Share on other sites

"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");"

 

make that to

 

"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');"

Link to comment
https://forums.phpfreaks.com/topic/112898-inserting-data/#findComment-579888
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.