0

i have this piece of code that allow user to edit their profile from the form using php and mysql when i echo the submitted or changed value it display the right and the edit value but nothing change in the database can anyone help me to solve this problem

this is the part that i am updating the query

if you need any addition files let me know and thank you

search.php

//submit whatthe user types into the database

     $fname = $_POST['fname'];
     $lname = $_POST['lname'];
     $country = $_POST['country'];
     $spec = $_POST['specialization'];

    ///errroor in updating the dataabse 


     $edit_query = mysql_query("UPDATE user SET first_name= '$fname', last_name= '$lname', address= '$country', specialization_name= '$spec' WHERE user_name = '$username'") or die(mysql_error());
2

4 Answers 4

0

You need to initialise the userName variable.

Sign up to request clarification or add additional context in comments.

Comments

0

$username is not defined. As result the query is executed for no database row.

Please use prepared statements instead of sql injectionable mysql_query().

1 Comment

ahhhh the $username come from the session that i cried out to each protected page
0

Try this.....

$edit_query = mysql_query("UPDATE `user` SET first_name= '".$fname."', last_name= '".$lname."', address= '".$country."', specialization_name= '".$spec."' WHERE user_name = '".$username."'") or die(mysql_error());

//Make sure that your $username hold some valid value.

1 Comment

The string syntax isn't the issue. If the OP's query didn't work, yours won't either.
0

$username is required and your query is vulnerable by sql injection. so use mysql_real_escape_string() function

$fname = mysql_real_escape_string($_POST['fname']);
$lname = mysql_real_escape_string($_POST['lname']);
$country = mysql_real_escape_string($_POST['country']);
$spec = mysql_real_escape_string($_POST['specialization']);

$edit_query = mysql_query("UPDATE user SET first_name= '$fname', last_name= '$lname', address= '$country', specialization_name= '$spec' WHERE user_name = '$username'") or die(mysql_error());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.