Jump to content

PHP SQL profile updates


scarezekiel

Recommended Posts

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!";

 

Link to comment
https://forums.phpfreaks.com/topic/257006-php-sql-profile-updates/
Share on other sites

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'];

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!';
  }
  
?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.