Reputation: 1
I am a newbie php programmer. I have this actionfrm.php and when it runs i get this msg:
UPDATE personal
SET membername='test this',
sponsorid='102',
dateofjoining='2012-07-23',
address='13432 main',
city='pomona',
state='CA',
country='USA',
mobileno='8187321592',
countrycode='1',
dateofbirth='1988/05/03',
emailid='[email protected]'
WHERE membername='test this'
update query succeeded
However, it is NOT writing to the database. i took this code and put it into phpmyadmin and got this msg: 0 rows affected.
Here is the code:
<?php include('dbconnect.php'); ?>
<?php
$membername=$_POST['membername'];
if(isset($_POST['username']) and $_POST['username']!=""){
$sponsorid=$_SESSION['memberid_for_sp'];
}else{
$sponsorid=0;
}
$dateofjoining=date("Y-m-d");;
$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state'];
$country=$_POST['country'];
$mobileno=$_POST['mobileno'];
$countrycode=$_POST['countrycode'];
$dateofbirth=$_POST['dateofbirth'];
$emailid=$_POST['emailid'];
$myid=$_SESSION['memberid'];
$query = "UPDATE personal SET membername='$membername',
sponsorid='$sponsorid',
dateofjoining='$dateofjoining',
address='$address',
city='$city',
state='$state',
country='$country',
mobileno='$mobileno',
countrycode='$countrycode',
dateofbirth='$dateofbirth', emailid='$emailid' WHERE membername='$membername'";
echo $query;
$checkresult = mysql_query($query);
if ($checkresult) echo 'update query succeeded';
else echo 'update query failed';
mysql_close();
//return $frmdetail.php;
?>
Please help, I really need this corrected...I'm having headaches with this.
Upvotes: 0
Views: 137
Reputation: 446
the new value does not exist in the table,but you execute update,so you got this msg: 0 rows affected,
you should be use replace instead of update.
when membername doesn't exist,mysql will call insert ,otherwise mysql will call update.
Upvotes: 1
Reputation: 9823
You're setting the membername to the new value UPDATE personal SET membername='$membername'
and then using that new value in the WHERE condition. Of course it would return 0 rows as the new value does not exist in the table.
You'll have to use a different field in the WHERE clause (such as id) to update the membername too.
Upvotes: 2