这个 PHP 脚本有什么问题?
<?php
$url = $_GET['url'];
if($url == "") {
die("Invalid Request! Missing Parameter 1!");
exit;
}
$tags = get_meta_tags($url);
$key = $tags['keywords'];
$desc = $tags['description'];
$con = mysql_connect('HOST', 'USER', 'PASS') or die(mysql_error());
mysql_select_db('zach_WebLock', $con) or die(mysql_error());
$query = "INSERT INTO `Keyword` (`Site`, `Keyword`, `Description`) VALUES ('".$site."', '".$key."', '".$desc."')";
mysql_query($query) or die(mysql_error());
echo '<b>Site: <u>'.$url.'</u></b>';
echo '<br>';
echo '<b>Description:</b>';
echo '<br>';
echo $desc;
echo '<br><br>';
$keys = explode(',', $key);
foreach($keys as $word) {
echo $word;
echo '<br>';
}
?>
此脚本提取 ?url= 变量中 URL 的关键字和描述。它显示所有信息,不会引发任何错误,但不会将信息写入数据库。有什么想法吗? (
(我省略了 mysql_real_escape_string() 进行测试)
<?php
$url = $_GET['url'];
if($url == "") {
die("Invalid Request! Missing Parameter 1!");
exit;
}
$tags = get_meta_tags($url);
$key = $tags['keywords'];
$desc = $tags['description'];
$con = mysql_connect('HOST', 'USER', 'PASS') or die(mysql_error());
mysql_select_db('zach_WebLock', $con) or die(mysql_error());
$query = "INSERT INTO `Keyword` (`Site`, `Keyword`, `Description`) VALUES ('".$site."', '".$key."', '".$desc."')";
mysql_query($query) or die(mysql_error());
echo '<b>Site: <u>'.$url.'</u></b>';
echo '<br>';
echo '<b>Description:</b>';
echo '<br>';
echo $desc;
echo '<br><br>';
$keys = explode(',', $key);
foreach($keys as $word) {
echo $word;
echo '<br>';
}
?>
This script extracts the keywords and description for the URL in the ?url= variable. It displays all the information, doesn't raise any errors but doesn't write the information to the DB. Any ideas? (
(I have left out the mysql_real_escape_string() for testing)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在尝试插入未定义的变量
$site
。也许您的意思是$url
?如果情况并非如此,请提供更多信息。您从
mysql_error()
得到任何输出吗?You're trying to insert the variable
$site
which is not defined. Perhaps you meant$url
?If that's not the case, please provide more information. Do you get any output from
mysql_error()
?您需要添加 '' 以允许 KeyWord 表中主键的自动增量,这应该可以阻止 MySQL 错误的发生。
如果这不能解决您的解决方案,我建议您在运行脚本并查看任何空白值时回显查询,并在必要时进行修复。如果您仍然遇到问题,请复制粘贴从脚本中回显的预期插入查询,并在 PhpMyAdmin 中测试它,看看是否得到不同的结果(错误)。
You need to add '' to allow for the AUTO INCREMENTATION for your primary key in the KeyWord table, which should stop the MySQL Error from occuring.
If that doesn't fix your solution, I'd recommend echoing out the query when you run the script and look any blank values, fix where necessary. If you're still having issues copy paste the your expected INSERT Query that was echoed from the script and test it in PhpMyAdmin and see if you get a different result (errors).