Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
PHP
$sql = ("UPDATE member_registration SET fname=:fname,oname=:oname,mname=:mname,gfname=:gfname,gmname=:gmname,rank=:rank,state=:state,village=:village,lga=:lga,workingp=:workingp,dob=:dob;,ocupation=:ocupation,family_group=:family_group,nowives=:nowives,nochild=:nochild,gender=:gender,mstatus=:mstatus,cadres=:cadres,passport=:passport, where phn=$phn");
$stmt = $con->prepare($sql);
$stmt->bindParam('ocupation',$ocupation);
$stmt->bindParam('fname',$fname);
$stmt->bindParam('oname',$oname);
$stmt->bindParam('mname',$mname);
$stmt->bindParam('gfname',$gfname);
$stmt->bindParam('dob',$dob);
$stmt->bindParam('mstatus',$mstatus);
$stmt->bindParam('gender',$gender);
$stmt->bindParam('gmname',$gmname);
$stmt->bindParam('village',$village);
$stmt->bindParam('state',$state);
$stmt->bindParam('lga',$lga);
$stmt->bindParam('family_group',$family_group);
$stmt->bindParam('nowives',$nowives);
$stmt->bindParam('nochild',$nochild);
$stmt->bindParam('cadres',$cadres);
$stmt->bindParam('rank',$rank);
$stmt->bindParam('workingp',$workingp);
$stmt->bindParam('passport',$ppt);
$stmt->execute();
echo "alert('Update Succesfully');";
echo "window.location='report.php';";


What I have tried:

I am try to update a single record but all record got updated at the same time.
Posted
Updated 27-Oct-20 6:17am
v2
Comments
Sandeep Mewara 27-Oct-20 2:49am    
When you run this query manually, what happens?
"UPDATE member_registration SET fname=:fname,oname=:oname,mname=:mname,gfname=:gfname,gmname=:gmname,rank=:rank,state=:state,village=:village,lga=:lga,workingp=:workingp,dob=:dob;,ocupation=:ocupation,family_group=:family_group,nowives=:nowives,nochild=:nochild,gender=:gender,mstatus=:mstatus,cadres=:cadres,passport=:passport, where phn=$phn"
Richard MacCutchan 27-Oct-20 5:29am    
Where is the binding for $phn?

There's a technique you should use in this type of thing - assuming you know how to write SQL queries:

1 - create a SELECT query and see what it finds.
2 - modify the SELECT until it behaves the way you want
3 - change the SELECT query to an UPDATE or DELETE (etc.) using the same criteria

This is a built-in safety net . . . you cannot undo the changes.

Now - for targeting a single record - you need to do (1) and (2) above so you can do the targeting. If the data doesn't allow you to distinguish records on its own (and you should never rely upon that!) you can put in an IDENTITY field - which guarantees each record is unique. You always have at least that one field to single out a record.

Now keep in mind that the above still needs some thought on your part - they're generally useful but at any time your problems utilization of the techniques may take some adaption - especially as the data selection has more and more complex dependencies on other tables (for example).

But, 1/2/3 are a great safety net and should always be used in live (production) databases.
 
Share this answer
 
Comments
Ibrahim Hassan 1234 27-Oct-20 18:31pm    
I am Really grate full for your quick respond and the problems have been fixed thank you so much.
First of all , I see obvious syntax errors, you need to remove them.
PHP
$sql = ("UPDATE member_registration SET ... dob=:dob; ... passport=:passport, where phn=$phn");
//                                 remove semi here ^     remove comma here ^

Online tools exists to help you check sql syntax errors
 
Share this answer
 
Comments
Ibrahim Hassan 1234 27-Oct-20 18:33pm    
I am Really Really undesrtand sir and all i rectify all the problems and everything know working perfect thank you so much Oger 'Patrice T'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900