Need help in inserting into database

Hi again guys. Im having this problem inserting into my database… here is my code

<?php
$connect=mysql_connect("localhost","root","");

mysql_select_db("database",$connect);


if(isset($_REQUEST['register']))
{
$message="";


$fname=$_REQUEST['fname'];
$lname=$_REQUEST['Lastname'];
$mname=$_REQUEST['mname'];
$DoB=$_REQUEST['DoB'];
$age=$_REQUEST['age'];
$CivilStatus=$_REQUEST['CivilStatus'];
$BagAddress=$_REQUEST['BagAddress'];
$Designation=$_REQUEST['Designation'];
$department=$_REQUEST['department'];
$course=$_REQUEST['course'];
$year=$_REQUEST['year'];
$eName=$_REQUEST['eName'];
$emName=$_REQUEST['emName'];
$eaddress=$_REQUEST['eaddress'];
$emAddress=$_REQUEST['emAddress'];
$eTellNo=$_REQUEST['eTellNo'];
$emTellNo=$_REQUEST['emTellNo'];
$eRelationship=$_REQUEST['eRelationship'];
$emRelationship=$_REQUEST['emRelationship'];
$idnum=$_REQUEST['IdNumber'];



$myquery="INSERT INTO patient  (IDNO,FNAME,LNAME,MNAME,DOB,AGE,CIVILSTATUS,BAGADDRESS,DESIGNATION,DEPARTMENT,COURSE,YEAR,ENAME,EMNAME,EADDRESS,EMADDRESS,ETELLNO,EMTELLNO,ERELATIONSHIP,EMRELATIONSHIP,) VALUES ('$idnum','$fname','$ln  ame','$mname','$DoB','$age','$CivilStatus','$BagAddress','$Designation','$department','$course','$year','$eName','$emName','$eaddress','$emAddress','$eTellNo','$emTellNo','$eRelationship','$emRelationship')";

mysql_query($myquery);

$count=mysql_affected_rows();

if($count==1){
  $message="Inserted Successfully";

}else
  $message="Error";
  
}

?>

<html>
<head>
<title>register</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php

  if(isset($_REQUEST['register']))
  {
    echo "$message";
  }
?>

<div id="regdiv2">
  <h3>Medical Record</h3>
  <form name="reg1" method="get" action = "reg1.php">
    <p>First Name
      <input type="text" name="fname"/>
      Last Name
      <input type="text" name="Lastname"/>
      MI
      <input type="text" name="mname"/>
    </p>
    <p>Date Of Birth
      <input type="text" name="DoB"/>
Age
<input type="text" name="age"size = "5"/>
Civil Status
<input type="text" name="CivilStatus"/>
    </p>
    <p>Baguio Address
      <input type="text" name="BagAddress"size = "80"/>
    </p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>Designation: <select name="Designation">
  <option value="Student">student</option>
  <option value="Ants">ants</option>
  <option value="Dependent">dependent</option>
  <option value="Faculty">faculty</option>
</select>
    </p>
    <p>Department
      <input type="text" name="department" size = "50"/>
    </p>
    <p>If Student: Course
      <input type="text" name="course"/>
    Year:
    <input type="text" name="year"/>
    </p>
    <p>Contact Persion in case of emergency:</p>
    <p>A. Name
      <input type="text" name="Ename"/> 
      B. 
      <input type="text" name="emName"/>
</p>
    <p>Adress
      <input type="text" name="eaddress"/> 
      <input type="text" name="emAddress"/>
    </p>
    <p>Tell No.
      <input type="text" name="eTellNo"/>
      <input type="text" name="emTellNo"/>
    </p>
    <p>Relationship
      <input type="text" name="eRelationship"  />
      <input type="text" name="emRelationship" />
    </p>
    <p>ID Number
      <input type="text" name="IdNumber">
    </p>
  </form>
  </div>
 
<div id="apDiv4">
  <input type="submit" name="register" value="Submit">
</div>
<div id="regdiv1">
<img src="image/register.jpg"/></div>
</body>
</html>

the thing is, i used the $fname = $_REQUEST[‘fname’] (but not all) into my other projects… and it worked. now i dont know what to do because its not working :frowning: its not inserting into a database… any sugestions please?

Your form says your method is get.

Try changing your form method to ‘post’ and the change all the $_REQUEST to $_POST

‘$ln ame’,

That space doesn’t look right in your code, maybe that will fix it!

Also:

INSERT INTO patient (IDNO,FNAME,LNAME,MNAME,DOB,AGE,CIVILSTATUS,BAGADDRESS,DESIGNATION,DEPARTMENT,COURSE,YEAR,ENAME,EMNAME,EADDRESS,EMADDRESS,ETELLNO,EMTELLNO,ERELATIONSHIP,EMRELATIONSHIP)

These might work better in COLUMN

Sponsor our Newsletter | Privacy Policy | Terms of Service