Jump to content

Input Form


munky334

Recommended Posts

Hi there

 

I have created the following HTML form for user input:

 

<html>
<form method="POST" action="new_update_delete.php">
Patient Demographics:<br />
<p>
Identity Number:
<input type="text" id="identitynumber" name="identitynumber" /><br />
First Name:
<input type="text" id="firstname" name="firstname" /><br /> 
Last Name:
<input type="text" id="lastname" name="lastname" /><br />
<p>
<input type="submit" value="New" />
<input type="submit" value="Update" />
<input type="submit" value="Delete" />
</form>

 

The code to save,update,delete information is contained in my new_update_delete.php form.

 

<?php
// Connect to database
$conn = mysql_connect('localhost','root') or trigger_error("SQL", E_USER_ERROR); 
$db = mysql_select_db('patient',$conn) or trigger_error("SQL", E_USER_ERROR); 
// Dump table in an array
$patientlist = array('id','firstname','lastname','identitynumber');
// Insert new patient
if($_POST['patientlist']) {
   // Clean
   $patientlist = mysql_real_escape_string($_POST['patientlist']);
   // Insert new patient record into table
   $sql = "INSERT INTO patientdemo (id,firstname,lastname,identitynumber) VALUES ('','$patientlist')";
   $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
} // end if

// Update existing patient record
if($_POST['patientlist']) {
   // for each name to change...
   foreach($_POST['patientlist'] as $cid => $patientlist) {
      // Clean
      $id = mysql_real_escape_string($cid);
      $patientlist = mysql_real_escape_string($patientlist);
      // Update patient record in the table  
      $sql = "UPDATE patientdemo SET name = '$patientdemo' WHERE id = '$id'";
      $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
   } // end foreach
} // end if

// Delete patient record from table
if($_GET['patientlist']) {
   // Clean
   $patientlist = mysql_real_escape_string($_GET['patientlist']);
   // Delete record
   $sql = "DELETE FROM patientdemo WHERE id,firstname,lastname,identitynumber = '$patientlist'";
   $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
} // end if
?>

 

 

I need some advice on how I can add,update and delete info users enter into the HTML form.

 

Sorry , I know this is simple but I'm a complete newbie and keen to learn.

 

Thanking you in advance.

 

(edited by kenrbnsn to add


tags)

 

Link to comment
https://forums.phpfreaks.com/topic/129295-input-form/
Share on other sites

Hi Everyone,

 

I have given this another try but still not getting it to work. I am sure it's much closer now. Any advice?

 

Cheers

 

<?php
if(isset($_POST['New'])){
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$identitynumber=$_POST['identitynumber'];
mysql_connect("localhost","root") or die(mysql_error());
mysql_select_db("patient") or die (mysql_error());
mysql_query("INSERT INTO 'patient' VALUES ($firstname,$lastname,$identitynumber)");
Print "Patient's' record has been saved to the database"

if(isset($_POST['Update'])){
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$identitynumber=$_POST['identitynumber'];
mysql_connect("localhost","root") or die(mysql_error());
mysql_select_db("patient") or die (mysql_error());
mysql_query("UPDATE 'patient' SET firstname='$firstname',lastname='$lastname',identitynumber='$identitynumber' WHERE id=$id");
Print "Patient's' record has been updated"


if(isset($_POST['Remove'])){
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$identitynumber=$_POST['identitynumber'];
mysql_connect("localhost","root") or die(mysql_error());
mysql_select_db("patient") or die (mysql_error());
mysql_query("DELETE FROM 'patient' WHERE id=$id");
Print "Patien's record has been removed"
?>

 

(edited by kenrbnsn to add


tags)

 

Link to comment
https://forums.phpfreaks.com/topic/129295-input-form/#findComment-670939
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.