PHP variable not updating in to MYSQl field

358

I have a piece of code which takes the keywords out of a url from a database. The code then updates a field within the database with the keywords. The code gets the keywords from the url successfully and then echo's them out on to the page perfectly.

However when I try and update them in to the database, the field doesn't update. If i swap out the variable $c for a word such as test this works perfectly and so the issue is with the variable $c, however i have tried to do this several different ways but i just can not get the field to update.

 $result = mysql_query("SELECT * FROM ip_stats1 WHERE page LIKE   'http://www.google.com/uds/afs?q=%' AND id='44'")
 or die(mysql_error());  
 $row = mysql_fetch_array( $result );


 $keyword = $row['page'];   
 $id = $row['id'];

 $a = "$keyword"; 
 $b = substr($a, strpos($a, '=') + 1); 
 print $b; 
 $c = substr($b, 0, strpos($b, '$')); 
 echo "$c";

 $result2 = mysql_query("UPDATE ip_stats1 SET string1 = '$c' WHERE id = '44'") 
 or die(mysql_error()); 

UPDATE

ok, so if I echo $c i get the keywords, so it would simply be for example something like Dough Maker, so that works perfectly. i have also tried writing it like this.

 $test = $c; 

and then test returns the same result. Originally this was a loop and i took all of the results fro the database to produce a long list, but in an effort to try and find the error i removed the loop to just return one result.

967

Answer

Solution:

OK, firstly thanks for all your suggestions, I tried various things and then in the end simply realised that actually this was a silly error. the variable $b holds the information i want and as soon as i inserted this to the database everything worked fine.

People are also looking for solutions to the problem: php - How to make a function for autoset

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.