Welcome to Dream.In.Code
Become a PHP Expert!

Join 150,175 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,192 people online right now. Registration is fast and FREE... Join Now!




PHP MySQL Update Leaving Empty Field

 
Reply to this topicStart new topic

PHP MySQL Update Leaving Empty Field, PHP MySQL Update Leaving Empty Field

jonesa01
28 Aug, 2008 - 08:20 AM
Post #1

New D.I.C Head
Group Icon

Joined: 18 Feb, 2007
Posts: 39


Dream Kudos: 25
My Contributions
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:

CODE

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

CODE

$dat->connect();


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

CODE

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:

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 Aug, 2008 - 08:46 AM
User is offlineProfile CardPM
+Quote Post

JBrace1990
RE: PHP MySQL Update Leaving Empty Field
28 Aug, 2008 - 09:19 AM
Post #2

D.I.C Regular
Group Icon

Joined: 9 Mar, 2008
Posts: 479



Thanked: 24 times
Dream Kudos: 350
My Contributions
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
php
if($query){
//email added
}else{
//Error Proccessing
}

User is offlineProfile CardPM
+Quote Post

Ridikule
RE: PHP MySQL Update Leaving Empty Field
28 Aug, 2008 - 09:19 AM
Post #3

D.I.C Head
**

Joined: 29 Sep, 2005
Posts: 58



Thanked: 4 times
My Contributions
I think I see your problem.

php

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.


User is offlineProfile CardPM
+Quote Post

jonesa01
RE: PHP MySQL Update Leaving Empty Field
28 Aug, 2008 - 09:29 AM
Post #4

New D.I.C Head
Group Icon

Joined: 18 Feb, 2007
Posts: 39


Dream Kudos: 25
My Contributions
QUOTE(Ridikule @ 28 Aug, 2008 - 10:19 AM) *

I think I see your problem.

php

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

CODE

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.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 03:35AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month