这是我的代码
mysql_connect('localhost', 'root', 'password');
mysql_select_db('db');
mysql_query("INSERT INTO metabase(url, title, image, description) VALUES('http://www.imgur.com/', '$title', '$image', '$descr')") or die();
它不会显示任何错误,但是值不会插入数据库中。我的表名称是配置数据库。网址,标题,图片为varchar(255)和说明文字。这是错误
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's visual storytelling community. Explore, share, and discuss the best visual sto' at line 1
这是说明
The Internet's visual storytelling community. Explore, share, and discuss the best visual stories the Internet has to offer.
这是因为'
我要如何纠正它?
我建议使用PDO或MYSQLi,因为它MySQL_
已贬值。不仅如此,您还没有逃避自己的价值观,并使自己暴露于诸如MySQL注入之类的一些问题中
$pdo = new PDO("mysql:host=localhost;dbname=db","root","password");
$query = $pdo->prepare("INSERT INTO `metabase` (url, title, image, description) VALUES(:url, :title, :image, :descr)");
$query->bindValue(":url", "http://www.imgur.com", PDO::PARAM_STR);
$query->bindValue(":title", $title, PDO::PARAM_STR);
$query->bindValue(":image", $image, PDO::PARAM_STR);
$query->bindValue(":descr", $descr, PDO::PARAM_STR);
$query->execute();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句