update data in my php form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
heshan
Forum Commoner
Posts: 26
Joined: Tue Jul 13, 2010 1:16 pm

update data in my php form

Post by heshan »

Hi all,

I want to modify details in my form. Therefore i use following code. But it does not work properly.Can anyone check and see where am i go wrong?

Code: Select all

<?php

$customer_id = $_POST['customer_id'];
$nic =$_POST['nic'];
$full_name=$_POST['full_name'];
$name_with_initials=$_POST['name_with_initials'];
$address=$_POST['address'];
$contact_number=$_POST['contact_number'];
$gender=$_POST['gender'];

$result = mysql_query("UPDATE customer SET `nic` = '$nic', `full_name` = '$full_name', `name_with_initials` =                      $name_with_initials', address = '$address', contact_number = '$contact_number', gender  = '$gender'  WHERE `customer_id` = '$customer_id' ");
if($result)
echo "Your information has been successfully added to the database.";
else
echo "Failed";
?>
Thanks,
Heshan
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: update data in my php form

Post by AbraCadaver »

What does "not work properly" mean? Add a or die(mysql_error()) to the end of the mysql_query() call.

Also, someone is going to destroy your database or collect some sensitive info. Read here: http://www.php.net/manual/en/security.d ... ection.php
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
heshan
Forum Commoner
Posts: 26
Joined: Tue Jul 13, 2010 1:16 pm

Re: update data in my php form

Post by heshan »

Simply the code is not correct. It isn't to do with any security features.
I think there should be an error in this code which i cannot find. That is the one i am looking for :( :(
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: update data in my php form

Post by AbraCadaver »

AbraCadaver wrote:Add a or die(mysql_error()) to the end of the mysql_query() call.
Also, I don't see you connecting or selecting a database.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: update data in my php form

Post by mikosiko »

other than the good guidance about security that AbraCadaver gave to you (and you should read it if you no are aware of the topic) in this line

Code: Select all

`name_with_initials` =                      $name_with_initials'
you are missing a quote
heshan
Forum Commoner
Posts: 26
Joined: Tue Jul 13, 2010 1:16 pm

Re: update data in my php form

Post by heshan »

yeah , i got the point. thanks everyone :D
Post Reply