fazlionline Posted June 3, 2009 Report Posted June 3, 2009 (edited) Hi all I have a form to update user information. The form has name, email &pass. If the user want to update his information, he will type his name, email and password in the form, then he will click the submit button. The PHP code will replace his database name and email with the form name and email IF the password in the form is equal to the password in the form. This is the code I worte, but not working: <?php // connect to database. // Update a record. mysql_query(" UPDATE example SET name= $_POST[name], email =$_POSR[email] WHERE pass==$_POST[pass] "); ?> Can anyone help me how to write this code? Note: I want to update this record in MySQL database using PHP Form Edited June 3, 2009 by fazlionline
BeeDev Posted June 3, 2009 Report Posted June 3, 2009 http://www.w3schools.com/ Here you can learn the correct syntax for PHP and MySQL. <?php // connect to database. // Update a record. mysql_query(" UPDATE example SET name= '".$_POST['name']."', email = '".$_POST['email']. "' WHERE pass = '" .$_POST['pass']."';"); ?>
fazlionline Posted June 3, 2009 Author Report Posted June 3, 2009 (edited) thanks, your code worked thanks alot. Edited June 3, 2009 by fazlionline
fazlionline Posted June 3, 2009 Author Report Posted June 3, 2009 (edited) If I want the record to be updated when two fields in the form are equal to two fields in the tadabase. Is this code right? mysql_query(" UPDATE example SET name= '".$_POST['xname']."', email = '".$_POST['xemail']. "' WHERE pass = '" .$_POST['xpass']."' AND location= '" .$_POST['xlocation']."' ;"); Thanks Edited June 3, 2009 by fazlionline
fazlionline Posted June 3, 2009 Author Report Posted June 3, 2009 (edited) as you solved that problem thanks for that but now same code is not updating another record! my PHP code is this <?php // Make a MySQL Connection // Update Multiple fields mysql_query(" UPDATE schooldb SET regname= '".$_POST['updname']."', regdob= '".$_POST['upddob']."', regdomi= '".$_POST['upddomi']."', regmob= '".$_POST['updmob']."', regcountry= '".$_POST['updcountry']."', regcity= '".$_POST['updcity']."', regposition= '".$_POST['updposition']."', regorg= '".$_POST['updorg']."', regpro= '".$_POST['updpro']."', regedu= '".$_POST['updedu']."', regemail= '".$_POST['updemail']."', WHERE regid = '" .$_POST['updid']."' AND regpass = '" .$_POST['updpass']."';"); echo "Data Updated!"; ?> is there anything missing? Thanks Edited June 3, 2009 by fazlionline
BeeDev Posted June 4, 2009 Report Posted June 4, 2009 (edited) if your regid field in the database is a Number then please remove the single quotes around it. Lets say $_POST['updid'] has value of 5. Then you SQL string looks like this: WHERE regid = '5' .... So MySQL cannot match and find a string field with value 5. You need to remove the outermost single quotes because values for INT or FLOAT or AUTONUMBER fields should not be wrapped in single quotes: WHERE regid = 5 .... Only values for TEXT, NVARCHAR, VARCHAR, DATETIME etc should be wrapped in single quotes in an SQL statement. so: WHERE regid = ".$_POST['updid']." AND regpass = '".$POST['updpass']."';" As I said, it might be a good idea for you to have a look at W3Schools.com as it looks as though you need some info on the SQL and PHP syntax Just a friendly advice, no offense intended. Edited June 4, 2009 by BeeDev
fazlionline Posted June 6, 2009 Author Report Posted June 6, 2009 View Other Records Update Your Information Full Name: Write yo full name with nick name ID: OLD ID Password: OLD PASSWARD Bate of Birth: Date - Month - Year Domicile The place where you parents lived Mobile Numbers: You can enter two mobile numbers, separate them with " / " . Country: The Country you live now State/Province/City: The State/province/City you live now Position Your Job Position Organization Name:: Name of the Organization you work in Profession: What is your profession, what are you expert in? Education Level: Your highest education level Email: The email address you use/check most.
fazlionline Posted June 6, 2009 Author Report Posted June 6, 2009 The second post on this page, solve the problem of updating one field but your last code of updating multi fields is not working. I also read about it in http://www.w3schools.com/php/php_mysql_update.asp as you told me, but I was unable to find updating in MySQL through PHP with taking values from FORM. Thanks
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now