problem with php sessions/mysql - submitting NULL data to database!!
Posted 20 September 2006 - 03:56 AM
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...)
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
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.
Posted 20 September 2006 - 04:34 AM
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.
Posted 20 September 2006 - 04:43 AM
something weird that may help figure it out...
I get 2 and sometimes 3 emails! but there's only ONE mail command...
Posted 20 September 2006 - 06:12 AM
"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:
$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");
Then you'll get a record of all queries, including any which may not have the output sent to your browser.
Posted 20 September 2006 - 06:17 AM
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!
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users