简体   繁体   English

PHP变量未更新到MYSQl字段

[英]PHP variable not updating in to MYSQl field

I have a piece of code which takes the keywords out of a url from a database. 我有一段代码将关键字从数据库的URL中删除。 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. 代码成功地从url获取了关键字,然后将它们完美地回显到页面上。

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. 如果我将变量$ c换成单词(例如test),则可以正常工作,因此问题出在变量$ c上,但是我尝试了几种不同的方法,但是我无法获取该字段进行更新。

 $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 $ci get the keywords, so it would simply be for example something like Dough Maker, so that works perfectly. 好的,所以如果我回显$ ci得到了关键字,那么例如Dough Maker之类的东西就可以了,这样效果很好。 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. 最初,这是一个循环,我从数据库中获取了所有结果以产生一长串列表,但是为了尝试查找错误,我删除了循环以仅返回一个结果。

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. 变量$ b保存了我想要的信息,将其插入数据库后,一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM