Jump to content

problem with php sessions/mysql - submitting NULL data to database!!


saturn

Recommended Posts

it makes NO sense to me. my brain is hurting. even my friend who does programming said it makes no sense.

this script is to edit a profile saved in a mysql database. the profile already exists... this just simply changes the data.

(for some reason can't post code...)

..problem:

whenever I submit this form, it blanks out the database! I've tried everything, from putting the variables within quotes, to changing the mysql query. finally I got rid of the sessions and tried a dry run with no pre-saved data -- it worked flawlessly! but as soon as I turn on sessions and have the form pre-filled with session data, even when that data is changed or left the same, it sends BLANKS to the database...

BUT WHAT IS INSANE:

if I do

echo $query;

it shows me a valid mysql query!!

is there some sort of crazy weirdness? am I going about this completely wrong?

please, someone help. also, no one haxx0r my server. thanks.
Link to comment
Share on other sites

"Whenever you have eliminated the impossible, whatever remains, however improbable, must be true." :)

If echo $query shows you a valid query, but the database is getting null values, then there are only so many explanations.  I'm listing them in order of how likely I think they are.

1.  The $query you are echoing is not the one being sent to mysql
2.  The $query you are echoing isn't doing what you expect it to do (it looks good to me though)
3.  The $query you are echoing IS sent to mysql, but another one is also sent.
4.  The $query is corrupted after being sent to mysql_query() (very unlikely)

The way I solve a problem like this is to add more and more debugging statements.  In your case, I would add echo $query right before and after the mysql_query() call, just to be 100% sure.  I would also see if I can get mysql to log all the queries executed.  If you can do that, then you will have very valuable information.

Since mysql_query() is the only thing that can change the database, if you focus on that function call, you will find the bug eventually.

Good luck :)
Link to comment
Share on other sites

Then number 3 is very likely..

"3.  The $query you are echoing IS sent to mysql, but another one is also sent."

If you're getting a second mail, it's possible your script is being executed again (through some mechanism, maybe being included more than once?), and the second query blanks out your values.

You might want to try making a log file, like this:

[code]$log_fp = fopen("/tmp/mylog", "w");
if (!$log_fp) die("Couldn't open log file!<br>");

and then just before your mysql statement, add

fwrite($log_fp, "About to execute $query\n");[/code]

Then you'll get a record of all queries, including any which may not have the output sent to your browser.
Link to comment
Share on other sites

I figured it out...

apparently php gets all confused if you call $variable but also have a form element with name="variable" and also have $_SESSION['variable']

::)

so it all works now! what a dumb thing to go wrong.

it was basically doing this:

sending my query, but then I was also defining those variables as the post...
so when it wasn't being posted (for example, mysql sending, or going back to the profile), it was re-defining those variables as nothing, since it wasn't being posted again......

anyway. all good now! thanks!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.