Jump to content

php mysql "FORM" update


fazlionline

Recommended Posts

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 by fazlionline
Link to comment
Share on other sites

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 by fazlionline
Link to comment
Share on other sites

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 by fazlionline
Link to comment
Share on other sites

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 by BeeDev
Link to comment
Share on other sites



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.





Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...