Problem with Function
Posted: Tue Sep 05, 2006 4:53 am
Hi all,
I have a page that updates a user's details to the database, I have user validation etc, but the problem I am having is with the function that updates the database. I get a syntax error. I have laid out the code below for the page and then the function itself that gets called from an include:
The function that updates the database looks like so:
It is this last query that is causing the problem, any ideas on what I am doing wrong?
I have a page that updates a user's details to the database, I have user validation etc, but the problem I am having is with the function that updates the database. I get a syntax error. I have laid out the code below for the page and then the function itself that gets called from an include:
Code: Select all
include details, session details above here.
if(isset($_POST["submit"])){
field_validator("username", $_POST["username"], "alphanumeric", 4, 15);
field_validator("password", $_POST["password"], "string", 4, 10);
field_validator("confirmation password", $_POST["password2"], "string", 4, 10);
field_validator("first_name", $_POST["first_name"], "alphanumeric", 1, 15);
etc, etc. (Field Validator is a function, this works fine).
$id = $_SESSION['username'];
$query = "select * from users where username='$id'";
//now we pass the query to the database
$result=mysql_query($query) or die("Could not get data.".mysql_error());
//get the first (and only) row from the result
$row = mysql_fetch_array($result, MYSQL_ASSOC)
$username=$row['username'];
$password=$row['password'];
$first_name=$row['first_name'];
etc, etc
if(empty($messages)) {
// registration ok, get user id and update db with new info:
updateuser($strUsername = isset($_POST['username']) ? $_POST['username'] : "",
$strPassword = isset($_POST['password']) ? $_POST['password'] : "",
etc, etc
html below here.The function that updates the database looks like so:
Code: Select all
function updateuser($username, $password, etc) {
$query = "UPDATE `users` SET `username` = '$username', `password` = '$password', `first_name`=$first_name, etc";
$result=mysql_query($query, $link) or die("Died inserting login info into db. Error returned if any: ".mysql_error());
return true;
} //It is this last query that is causing the problem, any ideas on what I am doing wrong?