Log in

View Full Version : Amend and Delete data from database



ntin0s
11-19-2010, 07:36 PM
Hello I can you help me with my amend code because is not working.Also if someone could give me a Delete.php code it would be great
Here is my code:

Amend.php

<?php
$con = mysql_connect("*****","*****","****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("*****", $con);

$sql="UPDATE Users
SET name='$_POST[name]', username='$_POST[username]'
WHERE name='$keywords' AND username='$keywords'";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "User details successfully updated";

mysql_close($con)
?>

Thanks in advance

djr33
11-19-2010, 07:54 PM
I think you should start with a tutorial to understand the basics of MySQL, such as DELETE. I like this tutorial:
http://php-mysql-tutorial.com (note that you'll want to look for the oldest articles to start)

As for your code above, it looks generally correct, but I see two problems:
1. You must escape the user input data because if you don't it will be a huge security risk-- someone can inject MySQL code just by using syntax like '; DROP DATABASE `name`; (sent from the form).
It's easy to do this, though:
$variable = mysql_real_escape_string($variable);
Do that for all of your $_POST variables (and maybe others) before the query. That will make the data secure (escape it so that it can't contain any commands).

2. I don't see $keywords set anywhere. That's probably why nothing is happening.

ntin0s
11-19-2010, 08:50 PM
Ok solved it thanks.