开发者

What is wrong with this PHP script?

<?php

$url = $_GET['url'];
if($url == "") {
  die("Invalid Request! Missin开发者_如何学运维g 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)


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()?


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.

$query = "INSERT INTO 'Keyword' VALUES ('','$site', '$key', '$desc')";
echo $query;

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜