我在让我的代码连接到我的 sql 时遇到问题。我正在用一个 wamp 堆栈在 aptana 中创建。运行时,网页仅显示:
无法连接到数据库:mysql_error()。'" );mysql_select_db("Q4u!")或 模具("无法选择数据库");回声"连接!
";$INSERT_sql ="插入客户(cust_Fname,cust_Lname, cust_Phone、cust_alt_phone、cust_Email、cust_notification_preference) 值 ('$_POST[名字]','$_POST[姓氏]','$_POST[电话号码]','$_POST[altphone]','$_POST[电子邮件地址]','$_POST[notipref]')"; mysql_query($INSERT_sql); ?>
我的代码看起来像
<?php
mysql_connect("localhost:3306", "root", "") or die ("<p>cannot connect to DB: mysql_error().</p>" );
mysql_select_db ("q4u!") or die ("cannot select db");
echo "<p>Connected!</p>";
$INSERT_sql = "insert into customer (cust_Fname, cust_Lname, cust_Phone, cust_alt_phone, cust_Email, cust_notification_preference)
VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[phonenumber]','$_POST[altphone]','$_POST[emailaddress]','$_POST[notipref]')";
mysql_query($INSERT_sql);
?>
PHP 未安装或文件扩展名未.php
试试这个$db = mysqli_connect('localhost:3306','root','');
不再包含mysql_select_db
。