Jump to content

[SOLVED] Having and issue with passing a varible in a MySQL Q.


ATLChris

Recommended Posts

$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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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.