scarezekiel Posted February 13, 2012 Share Posted February 13, 2012 i dont know why it doesnt update the db..someone help?? $connection=mysql_connect("$server", "$username", "$password") or die("Could not establish connection"); mysql_select_db($database_name, $connection) or die ("Could not select database"); $strEditProfile = "UPDATE tblemployee SET EmployeeName='".$_POST["edit_thename"]."', Address1 = '".$_POST[edit_address1]."', Address2 = '".$_POST[edit_address2]."', DesignationID = '".$_POST[edit_des]."', Postcode = '".$_POST[edit_postcode]."', State = '".$_POST[edit_state]."', Country = '".$_POST[edit_country]."', Tel1 = '".$_POST[edit_contact]."' WHERE EEmail='".$_POST["edit_email"]."'"; $resEditProfile = mysql_query($strEditProfile); if($resEditProfile) echo "<img src=\"images/valid.jpg\" /> Profile updated!"; else echo "><img src=\"images/warning.jpg\">Error!"; Quote Link to comment https://forums.phpfreaks.com/topic/257006-php-sql-profile-updates/ Share on other sites More sharing options...
sunfighter Posted February 13, 2012 Share Posted February 13, 2012 Things like this $_POST[edit_address1] must be in quotes like this $_POST['edit_address1'] and you need to escape most of your quotes. Echo out each section in $strEditProfile to see where. Quote Link to comment https://forums.phpfreaks.com/topic/257006-php-sql-profile-updates/#findComment-1317788 Share on other sites More sharing options...
sunfighter Posted February 13, 2012 Share Posted February 13, 2012 Had a little time so worked on it. This is your query $strEditProfile = "UPDATE tblemployee SET EmployeeName=".$_POST['edit_thename'].", Address1 = ".$_POST['edit_address1'].", Address2 = ".$_POST['edit_address2'].", DesignationID = ".$_POST['edit_des'].", Postcode = ".$_POST['edit_postcode'].", State = ".$_POST['edit_state'].", Country = ".$_POST['edit_country'].", Tel1 = ".$_POST['edit_contact'].", WHERE EEmail=".$_POST['edit_email']; Quote Link to comment https://forums.phpfreaks.com/topic/257006-php-sql-profile-updates/#findComment-1317798 Share on other sites More sharing options...
PaulRyan Posted February 14, 2012 Share Posted February 14, 2012 Sunfighter, the code you have given will not work if the content of any of those variables have a space in them. You should also use backticks for the field names (`) This is the updated code: <?PHP $connection=mysql_connect("$server", "$username", "$password") or die("Could not establish connection"); mysql_select_db($database_name, $connection) or die ("Could not select database"); $strEditProfile = "UPDATE `tblemployee` SET `EmployeeName`='{$_POST['edit_thename']}', `Address1` = '{$_POST['edit_address1']}', `Address2` = '{$_POST['edit_address2']}', `DesignationID` = '{$_POST['edit_des']}', `Postcode` = '{$_POST['edit_postcode']}', `State` = '{$_POST['edit_state']}', `Country` = '{$_POST['edit_country']}, `Tel1` = '{$_POST['edit_contact']}', WHERE `EEmail` = '{$_POST['edit_email']}';"; if(mysql_affected_rows()) { echo '<img src="images/valid.jpg">Profile updated!'; } else { echo '<img src="images/warning.jpg">Error!'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/257006-php-sql-profile-updates/#findComment-1317940 Share on other sites More sharing options...
scarezekiel Posted February 18, 2012 Author Share Posted February 18, 2012 thx for d help guys, i think i found d problem..but i forgot to include it in my codes d other day. <form action="index.php?view=editprofile_do" method="post"> <input type="hidden" name="edit_email" value=<?php echo $user; ?> <br /> d other day i used ( value=<$user> instead of value=<?php echo $user; ?> ) lol my mistake..im new to PHP. Quote Link to comment https://forums.phpfreaks.com/topic/257006-php-sql-profile-updates/#findComment-1318538 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.