Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

User Input

munky344munky344 Posts: 12Member
Hi there

I have created the following HTML form for user input:



Patient Demographics:


Identity Number:


First Name:


Last Name:








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.

Comments

  • munky344munky344 Posts: 12Member
    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"
    ?>

    : Hi there
    :
    : I have created the following HTML form for user input:
    :
    :
    :
    : Patient Demographics:

    :


    : Identity Number:
    :

    : First Name:
    :

    : Last Name:
    :

    :


    :
    :
    :
    :
    :
    : 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.
    :

  • tradmtradm Posts: 49Member
    : 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='$identity
    : number' 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"
    : ?>
    :
    : : Hi there
    : :
    : : I have created the following HTML form for user input:
    : :
    : :
    : :
    : : Patient Demographics:

    : :


    : : Identity Number:
    : :

    : : First Name:
    : :

    : : Last Name:
    : :

    : :


    : :
    : :
    : :
    : :
    : :
    : : 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.
    : :
    :
    :


    Just add a semicolon and a bracket to ALL your print statement. They should look like this
    [code]Print "Patient's' record has been updated" [b]; }[/b][/code]

  • apictonapicton Posts: 1Member
    Also - I think you need to name your submit buttons.

    You have:




    I think you need to add the name argument to each one so it knows which button you are clicking.
    The VALUE argument only tells what is displayed on the buttons.
    The NAME field tells the browser the name of each button so it can tell what is clicked.






Sign In or Register to comment.