这是我的Php文件代码。当我使用HTML中的输入字段插入数据时,我得到错误无法输入数据。没有选择数据库。
$dbhost="localhost";
$dbuser="root";
$dbpass="";
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
$sql = 'INSERT INTO sale '.
'(Name, Contact, Email, Property_type, Price, Location) '.
'VALUES ( "$a", "$b", "$c", "$d", "$e", "$f" )';
mysql_select_db('gharghar_gharastee');
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($conn);
?>
答案 0 :(得分:1)
尝试检查与数据库的连接
// make foo the current db
$db_selected = mysql_select_db('gharghar_gharastee', $conn);
if (!$db_selected) {
die ('Can\'t use gharghar_gharastee : ' . mysql_error());
}
我建议您使用PDO而不是mysql_connect - 出于安全考虑,它已在较新版本的PHP中折旧
答案 1 :(得分:-1)
你必须像这样使用mysql SQL。
$sql = 'INSERT INTO sale '.
'(Name, Contact, Email, Property_type, Price, Location) '.
"VALUES ( '$a', '$b', '$c', '$d', '$e', '$f' )";