Thanks Neil, but it won't let me update the data in the database.
However, I have adjusted some parts of the code from my previous post and I nearly got there. The data have been update in the table, but it have written as blank.
Here it is the code:
<?php
session_start();
define('DB_HOST', 'localhost');
define('DB_USER', 'myusername');
define('DB_PASSWORD', 'mypassword');
define('DB_DATABASE', 'mydatabase');
$errmsg_arr = array();
$errflag = false;
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
function clean($var){
return mysql_real_escape_string(strip_tags($var));
}
$login = clean($_GET['user']);
$password = clean($_GET['pass']);
$firstname = clean($_GET['firstname']); //variable in the url you posted was firstname, not value.
if($login == '') {
$errmsg_arr[] = 'Login ID missing';
$errflag = true;
}
if($password == '') {
$errmsg_arr[] = 'PASSWORD ID missing';
$errflag = true;
}
if($firstname == '') {
$errmsg_arr[] = 'THE FIRSTNAME is missing';
$errflag = true;
}
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
echo implode('<br />',$errmsg_arr);
}
else {
$qry="SELECT * FROM members WHERE login='$login' AND passwd='$password' AND firstname='$firstname'";
$result=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error());
if(mysql_num_rows($result) > 0) {
$row = mysql_fetch_row($result);
echo $row[0];
}
else {
echo 'Username, Password or value is not found.';
$firstname = ($_POST['firstname']);
$lastname = ($_POST['lastname']);
$sql="update members set firstname='".$_POST['firstname']."',lastname='".$_POST['lastname']."' where login='{$login}' and passwd='{$password}'";
if (!mysql_query($sql,$link))
{
die('Error: ' . mysql_error());
}
echo "The information have been updated";
}
}
?>
When I have input the data only for the firstname in the url, both firstname and lastname in the database table have been written as blank which I mean it have been empty.
The firstname should have only written in the database when I input the data after firstname=whateveriinputithere without included the lastname data.
If I wish to write firstname or lastname, I should use one of them at a time otherwise to write them at the same time if I put the value name of the firstname and the lastname in the url.
So I don't know what's wrong, why it have been blank in the table?