ATLChris Posted February 9, 2009 Share Posted February 9, 2009 $location = $_POST['location']; $query = "UPDATE temp SET location='$location' WHERE sid='$session_id'"; $result = mysql_query("$query") or die(mysql_error()); OK, this code has me stumped, if I echo location as is, it shows the contents from the form as expected, but when I process the form, the field updates in the SQL database, but with a blank instead of the varible. Now, if I change it to this: $location = $_POST['location']; $query = "UPDATE temp SET location='My Office' WHERE sid='$session_id'"; $result = mysql_query("$query") or die(mysql_error()); It submits updates fine, so I know it is not the SQL Q, I have also run it through the database manually and it goes fine. It also works if I define location on this page: $location = 'My Office'; $query = "UPDATE temp SET location='$location' WHERE sid='$session_id'"; $result = mysql_query("$query") or die(mysql_error()); It has something todo with the $_POST in the MySQL statement. Please help everyone, this has me totally floored. Quote Link to comment https://forums.phpfreaks.com/topic/144494-solved-having-and-issue-with-passing-a-varible-in-a-mysql-q/ Share on other sites More sharing options...
premiso Posted February 9, 2009 Share Posted February 9, 2009 Sounds like a weird error. So if you echo $location after defining it from the $_POST['location'] it works just fine. Is that how the code is setup in those 3 lines (there is no other processing between them?) Also, you are not really escaping input, which could cause a problem, but that would throw a mysql error, so I doubt it is that. Something to be aware of though. Have you echo'd out the $session_id also after assigning $location to the post variable to make sure that, somehow, it is not being wiped out? Quote Link to comment https://forums.phpfreaks.com/topic/144494-solved-having-and-issue-with-passing-a-varible-in-a-mysql-q/#findComment-758227 Share on other sites More sharing options...
ATLChris Posted February 9, 2009 Author Share Posted February 9, 2009 Sounds like a weird error. So if you echo $location after defining it from the $_POST['location'] it works just fine. Is that how the code is setup in those 3 lines (there is no other processing between them?) Also, you are not really escaping input, which could cause a problem, but that would throw a mysql error, so I doubt it is that. Something to be aware of though. Have you echo'd out the $session_id also after assigning $location to the post variable to make sure that, somehow, it is not being wiped out? I have done the echo. I echo out the entire query and it echos fine with all the variables defined. I can take that echo and put it manually through MySQL Admin and it will update fine. I is something weird that has me floored, and I am pretty advanced PHP user. Quote Link to comment https://forums.phpfreaks.com/topic/144494-solved-having-and-issue-with-passing-a-varible-in-a-mysql-q/#findComment-758230 Share on other sites More sharing options...
premiso Posted February 9, 2009 Share Posted February 9, 2009 I have done the echo. I echo out the entire query and it echos fine with all the variables defined. I can take that echo and put it manually through MySQL Admin and it will update fine. I is something weird that has me floored, and I am pretty advanced PHP user. Well at least you tried debugging it yourself, we rarely see that here lol. I am not sure what could be happening...So the query echos out with the location being shown etc? Let me ask this, register_globals is not turned on is it? I doubt it would be, but if it is maybe that is causing some issues? Post the form code for us to look at, maybe something is going askew in there? Quote Link to comment https://forums.phpfreaks.com/topic/144494-solved-having-and-issue-with-passing-a-varible-in-a-mysql-q/#findComment-758233 Share on other sites More sharing options...
ATLChris Posted February 9, 2009 Author Share Posted February 9, 2009 I have done the echo. I echo out the entire query and it echos fine with all the variables defined. I can take that echo and put it manually through MySQL Admin and it will update fine. I is something weird that has me floored, and I am pretty advanced PHP user. Well at least you tried debugging it yourself, we rarely see that here lol. I am not sure what could be happening...So the query echos out with the location being shown etc? Let me ask this, register_globals is not turned on is it? I doubt it would be, but if it is maybe that is causing some issues? Post the form code for us to look at, maybe something is going askew in there? Haha yes, I have been debugging this issue myself for hours. Here is the form data: <form name="capsule" id="capsule" action="handle.php" method="POST"> <div class="form_field_capsule"> <label for="location">Where Are You Right Now?</label> <input type="text" id="location" name="location" size="25" tabindex="1" value="<?PHP echo $location; ?>" /> <div class="hint">Try to be specific. i.e. I am sitting at my desk in my bedroom at my house at 1600 Pennsylvania Ave NW, Washington, DC 20500.</div> </div> <div id="capsule_submit"> <input type="hidden" id="capsule" name="page" value="capsule" /> <input type="submit" id="next" value="Next: The Pictures >>" name="submit" /> </div> </form> Quote Link to comment https://forums.phpfreaks.com/topic/144494-solved-having-and-issue-with-passing-a-varible-in-a-mysql-q/#findComment-758241 Share on other sites More sharing options...
premiso Posted February 9, 2009 Share Posted February 9, 2009 Looks sound to me, what are you putting in that text field? Just "My Office" for testing reasons? Maybe the DB Field is not long enough...but that should have just chopped the string down to that size. Also, is register_globals turned off? Can you post the full code that is being ran, just to look and make sure that is not doing anything funky? Quote Link to comment https://forums.phpfreaks.com/topic/144494-solved-having-and-issue-with-passing-a-varible-in-a-mysql-q/#findComment-758243 Share on other sites More sharing options...
ATLChris Posted February 9, 2009 Author Share Posted February 9, 2009 OK, I have done some more debugging, and have come to the result that it is javascript that is causing the problem, but I still have not figured it out. If I comment out the links to my javascript files in my header it works, but if I goto the actual javascript file, and comment all the data out, it doesn't work. Any ideas? I am using jquery on this site. Quote Link to comment https://forums.phpfreaks.com/topic/144494-solved-having-and-issue-with-passing-a-varible-in-a-mysql-q/#findComment-758288 Share on other sites More sharing options...
premiso Posted February 9, 2009 Share Posted February 9, 2009 Post the full html page where the form is. Hard to say without seeing that, if you want to also, post the js file too (or attach it). That will help. Quote Link to comment https://forums.phpfreaks.com/topic/144494-solved-having-and-issue-with-passing-a-varible-in-a-mysql-q/#findComment-758290 Share on other sites More sharing options...
ATLChris Posted February 9, 2009 Author Share Posted February 9, 2009 Ok, well I didn't solve this problem, but I was able to narrow it do enough to create a work around. The problem was, that some how JavaScript was looping the page 2 times. The first time it was updating the SQL with the values like it was suppose to, then it reloaded the page with no POST variables to everything got updated again with blank values. What I did is create a function that allow me to determine if I want javascript on certain pages or not. It was a very strange problem that had me stumped for over 8 hours. The JavaScript problem was in the jquery code to which is strange because that is a well known developer app.. Quote Link to comment https://forums.phpfreaks.com/topic/144494-solved-having-and-issue-with-passing-a-varible-in-a-mysql-q/#findComment-758374 Share on other sites More sharing options...
premiso Posted February 9, 2009 Share Posted February 9, 2009 Are you using the latest jQuery? I know Javascript and ajax are a pain in the butt to code/debug. It could be 1 minor thing that does it, and that is all it takes. Such as making your button post twice on accident, I have done that before. Well hope for the best. Quote Link to comment https://forums.phpfreaks.com/topic/144494-solved-having-and-issue-with-passing-a-varible-in-a-mysql-q/#findComment-758382 Share on other sites More sharing options...
ATLChris Posted February 9, 2009 Author Share Posted February 9, 2009 I am using the latest build of jQuery. I am not a JavaScript guy, and don't plan to be, because I HATE JAVASCRIPT with a passion. Quote Link to comment https://forums.phpfreaks.com/topic/144494-solved-having-and-issue-with-passing-a-varible-in-a-mysql-q/#findComment-758395 Share on other sites More sharing options...
ATLChris Posted February 10, 2009 Author Share Posted February 10, 2009 I figured it out, the problem was the result of a: , "" In a image preload script. haha it was trying to preload a image but the image was not linked so it was preloading the page. 8 hour and it was 3 character haha Quote Link to comment https://forums.phpfreaks.com/topic/144494-solved-having-and-issue-with-passing-a-varible-in-a-mysql-q/#findComment-758591 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.