本文介绍了我在我的php脚本中找不到这个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用PHP编写一个脚本,使用该页面的当前URL,在数据库中搜索(phpMyAdmin和WAMP),并使用该URL打印该行的ID。我已经写了这个,并且就连接的角度而言,每个线程都起作用,与mysql的连接也可以正常工作,问题从这一行开始:
I want to write a script in PHP that takes the current URL of the page, searches it in the database (phpMyAdmin with WAMP) and prints the ID of the row with that URL. I have written this, and to the point of the connection, everythwing works, the connection with mysql also works fine, the problem starts on this line:
$query = "SELECT id FROM search WHERE link = '". $curPageURL . "'";任何人都可以告诉我:我做错了什么?这是整个脚本:
Can anyone please tell me: what Am I doing wrong? this is the whole script:
<!DOCTYPE html> <html> <body> <?php function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } echo curPageURL(); //connection $con= mysql_connect("localhost","root","") or die ("Could not connect"); mysql_select_db("search") or die ("Could not select db"); echo "connection succesful"; $query = "SELECT id FROM search WHERE link = '". $curPageURL . "'"; while($row = mysql_fetch_array($query)) { echo $row; } ?> </body> </html>推荐答案
您可能想尝试这样的事情。 p>
You might want to try something like this.
$query = "SELECT id FROM search WHERE link = '". curPageURL() . "'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { echo $row['id']; }更多推荐
我在我的php脚本中找不到这个错误
发布评论