PHP MySQL Update Leaving Empty Field

PHP MySQL Update Leaving Empty Field

Page 1 of 1

3 Replies - 3868 Views - Last Post: 28 August 2008 - 10:29 AM Rate Topic: -----

#1 jonesa01  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 25
  • View blog
  • Posts: 125
  • Joined: 18-February 07

PHP MySQL Update Leaving Empty Field

Posted 28 August 2008 - 09:20 AM

I am writing a code for a community website where I am making a edit profile feature for registered members. I have the following form:

Complete the following form to edit your profile:<br /><br />
			<form action="index.php?id=13&up=true" method="post" enctype="multipart/form-data">
				<table border="0">
					<tr>
						<td>Avatar: </td>
						<td><p align="center"><img src="#" alt="Avatar" width="100" height="100"></p></td>
					</tr>
					<tr>
						<td>Change Avatar: <br>(Leave blank to keep current) Max: 64MB</td>
						<td><input type="hidden" name="MAX_FILE_SIZE" value="2000000">
							<input type="file" name="userfile" id="userfile">
						</td>
					</tr>
					<tr>
						<td>E-Mail: </td>
						<td><input type="text" name="EMail" value="<?php echo $EMail; ?>"></td>
					</tr>
					<tr>
						<td>Password: <br>(Leave blank to keep current)</td>
						<td><input type="password" name="Password"></td>
					</tr>
					<tr>
						<td>Repeat Password: <br>(Leave blank to keep current)</td>
						<td><input type="password" name="Password2"></td>
					</tr>
					<tr>
						<td>Personal Description: </td>
						<td><textarea name="Description"><?php echo $Description; ?></textarea></td>
					</tr>
					<tr>
						<td></td>
						<td><input type="submit" value="Update"></td>
					</tr>
				</table>
			</form>



I use a class to connect to the database

$dat->connect();



Then I have the following code that processes the file upload:

if($_FILES['userfile']['size'] > 0){
				$fileName = $_FILES['userfile']['name'];
				$tmpName  = $_FILES['userfile']['tmp_name'];
				$fileSize = $_FILES['userfile']['size'];
				$fileType = $_FILES['userfile']['type'];
				$fp = fopen($tmpName, 'r');
				$content = fread($fp, filesize($tmpName));
				$content = addslashes($content);
				fclose($fp);
				if(!get_magic_quotes_gpc()){
					$fileName = addslashes($fileName);
				}
				$query = mysql_query("UPDATE `users` SET `Avatar` = '$content' WHERE `Username` = '$Username' LIMIT 1;") or die("Error");
				echo "Avatar Updated, ";
			}



That works alright, but when i try to modify the e-mail I find a blank field in the database. Here is the code:

$email = addslashes($_POST["EMail"]);
			echo $email."<br>";
			$qy = "UPDATE `users` SET `EMail` = '$email' WHERE `Username` = '$Username' LIMIT 1;";
			echo $qy."<br>";
			$query = mysql_query($qy) or die("Error");
			echo "E-Mail Updated, ";
			echo "<br>";



And using made up data the text echoed is:

someone@someone.com
UPDATE `users` SET `EMail` = 'someone@someone.com' WHERE `Username` = 'someone' LIMIT 1l
Email Updated,


But the table looks like this:

------------------------------------------------
| Username | E-Mail |
------------------------------------------------
| someone | |
------------------------------------------------

And before the update it looked like:

---------------------------------------------------
| Username | E-Mail |
----------------------------------------------------
| someone | someone@somewhere.com |
----------------------------------------------------

But I cannot see a cause. Quick help would be appreciated.

This post has been edited by jonesa01: 28 August 2008 - 09:46 AM


Is This A Good Question/Topic? 0
  • +

Replies To: PHP MySQL Update Leaving Empty Field

#2 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 110
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: PHP MySQL Update Leaving Empty Field

Posted 28 August 2008 - 10:19 AM

E-Mail != EMail

I think, for one, that you're naming your field wrong in your query... also, add "or die(mysql_error())" to the end of the query...

add
if($query){
//email added
}else{
//Error Proccessing
}

Was This Post Helpful? 0
  • +
  • -

#3 Ridikule  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 68
  • Joined: 29-September 05

Re: PHP MySQL Update Leaving Empty Field

Posted 28 August 2008 - 10:19 AM

I think I see your problem.

someone@someone.com
UPDATE `users` SET `EMail` = 'someone@someone.com' WHERE `Username` = 'someone' LIMIT 1l
Email Updated,



------------------------------------------------
| Username | E-Mail |
------------------------------------------------
| someone | |
------------------------------------------------

You are setting the column 'EMail' in your update statement, but the table you show here indicates the column is actually 'E-Mail'. The MySQL query is probably erroring but your error level is suppressing it.
Was This Post Helpful? 0
  • +
  • -

#4 jonesa01  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 25
  • View blog
  • Posts: 125
  • Joined: 18-February 07

Re: PHP MySQL Update Leaving Empty Field

Posted 28 August 2008 - 10:29 AM

View PostRidikule, on 28 Aug, 2008 - 10:19 AM, said:

I think I see your problem.

someone@someone.com
UPDATE `users` SET `EMail` = 'someone@someone.com' WHERE `Username` = 'someone' LIMIT 1l
Email Updated,



------------------------------------------------
| Username | E-Mail |
------------------------------------------------
| someone | |
------------------------------------------------

You are setting the column 'EMail' in your update statement, but the table you show here indicates the column is actually 'E-Mail'. The MySQL query is probably erroring but your error level is suppressing it.


My column in the table is EMail

And i tried with

if($query){
// ok
}else{
// error
}



but it is always ok. If i replace the $email variable with someone@someone.com it works, but with the variable it displays nothing in the database.

But copying the echoed query into phpMyAdmin it works fine.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1