any takers on this on?
Hey guys I need help creating a PHP function/statement to update a record in my database and also one to delete a record from the database.
I already got the add record to the database working.
HTML FORM CODE
HTML Code:<head> <title>Change Person</title> </head> <body> <form action="change_person.php"> ID: <input type="text" name="id" /> Name: <input type="text" name="name" /> Gender: <input type="text" name="gender" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> </body>HTML Code:<head> <title>Add Person</title> </head> <body> <form action="add_person.php"> ID: <input type="text" name="id" /> Name: <input type="text" name="name" /> Gender: <input type="text" name="gender" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> </body>
PHP CODE ADD PERSON
I messed around trying to get the delete and update function working but not getting anywhere. Can anyone provide some help.PHP Code:
<HTML>
<HEAD>
<TITLE> Add Person</TITLE>
</HEAD>
<BODY>
<?php
include('connect.php');
$id=$_GET['id'];
$name=$_GET['name'];
$gender=$_GET['gender'];
$age=$_GET['age'];
$query="INSERT INTO person (id,Name,Gender,Age) VALUES ('$id','$name','$gender','$age')";
if(pg_query($query)) {
echo "User successfully added";
}
else {
echo " ERROR: Duplicate Person";
}
?>
</BODY>
</HTML>
Last edited by King_Jay16; Mar 13, 2012 at 12:09 AM.
any takers on this on?
Your way of coding may be the shorter version I guess....but learning it at school now....for the last coding that you posted....in mine I have something like this...I didnt copy all the coding
If you notice where [mysql_select_db("applicants");] is.....applicants is the name of the database....while students is the name of the table. Dont see the name of the database in yours.
<?php
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$email = $_POST["email"];
$address = $_POST["address"];
$parish = $_POST["parish"];
$homephone = $_POST["homephone"];
$mobilephone = $_POST["mobilephone"];
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Sorry but i could not connect to your server: ' . mysql_error());
}
mysql_select_db("applicants");
mysql_query("INSERT INTO students (Fname, Lname, Email, Address, Parish, Home, Mobile)
VALUES ('$fname','$lname','$email','$address','$parish',' $homephone','$mobilephone')");
Where I have [ mysql_query("INSERT INTO ] that ends with another bracket at the end if you notice...dont know if it makes a difference...though you only have [ $query="INSERT ]. Maybe thats where you are having the issue.
But for your coding, maybe this video may help you....http://www.youtube.com/watch?v=mn0ucCuNOTI. At first I started to use this....but for my assignment, I got lost along the way.
Hope this will help.
Last edited by Yung_Jah; Mar 13, 2012 at 08:45 PM.
thanks will test the later and keep it as a reference... I however met with my Professor and got it sorted out. See the code below
Change/Update Record
As for the name of the database and connection items, those are included in the connect.php file, that way you only update your credentials etc in one placeHTML Code:<HTML> <HEAD> <TITLE> Change Person</TITLE> </HEAD> <BODY> <?php include("connect.php"); $id=$_GET["id"]; $name=$_GET["name"]; $age=$_GET["age"]; $gender=$_GET["gender"]; $query="UPDATE person SET name= $1, gender= $2, age=$3 WHERE id=$4"; pg_query_params($query,array($name,$gender,$age,$id)); ?> </BODY> </HTML>
Cool....good to know you got through. There is always a shorter version to do things.
But I am still puzzles...I dont see the name of the database....I am only seeing the name of the table which is "person"
The database name would be located in the connect.php file. like King_Jay16 previously stated.
@King_Jay16
and that would be your delete based on the last data shown.Code:...... //Delete from database $query_delete="DELETE FROM person WHERE id='$ID' "; mysql_query($query_delete);...... or $query_delete="DELETE FROM person WHERE id=$4 "; pg_query_params($query_delete(array($name,$gender,$age,$id));
if both operations where happening on a form then you would set it to a specific button using IF conditions
if ( isset($_POST['Delete_Details']))
{
}
'Delete_Details' would be the name of the button the user needs to press.
Last edited by Dre'; Mar 21, 2012 at 06:21 AM. Reason: code tags
Oh zeen...respect still.