Jump to content


Photo

"UPDATE" MySQL information code problem[-SOLVED-]


  • Please log in to reply
2 replies to this topic

#1 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 14 August 2006 - 05:28 AM

I have a change email form .. and its not working ... and yet i dont get an error, what wrong with this code??

<?php 
$db_host = "localhost"; 
$db_user = "zyco"; 
$db_pwd = "*******"; 
$db_name = "zyco_zycologin"; 
mysql_connect($db_host, $db_user, $db_pwd); 
mysql_select_db($db_name); 
?> 
<center> 
<?php 
if($_POST['updateI']){
$sql = "UPDATE users WHERE username = '$_SESSION[username]' email = '$_POST[emailNew]' LIMIT 1"; 
$query = mysql_query($sql); 
} 
?> 
<form action="" method="post">
      <table align="center" border="0" cellspacing="0" cellpadding="3">
<tr><td ><font color=black>E-mail:</font></td><td><input type="text" name="emailNew" maxlength="30"></td></tr>
<tr><td colspan="2" align="right"><input type="submit" name="updateI" value="Update"></td></tr>
</table>
    </form>
</center>

Link shortener with advanced, detailed statistics:

http://tyny.us/

#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 14 August 2006 - 05:49 AM

Try it like this.

<?php 
if($_POST['updateI']){
$username = $_SESSION['username'];
$new_email = mysql_real_escape_string(trim($_POST['emailNew']));

$sql = "UPDATE `users` SET `email` = '$new_email' WHERE `username` = '$username'"; 
$query = mysql_query($sql) or die(mysql_error()); 
} 
?> 
<form action="" method="post">
      <table align="center" border="0" cellspacing="0" cellpadding="3">
<tr><td ><font color=black>E-mail:</font></td><td><input type="text" name="emailNew" maxlength="30"></td></tr>
<tr><td colspan="2" align="right"><input type="submit" name="updateI" value="Update"></td></tr>
</table>
    </form>
</center>

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 14 August 2006 - 05:53 AM

THANKS !!! IT WORKED!! YES! thanks a lot!! you saved me hours of frustration.. lol as simple a code as that was.. I understand MySQL, just dont completely get the coding. THANKS again!
Link shortener with advanced, detailed statistics:

http://tyny.us/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users