答案 很好,这很有趣。基本上它与我认为的没有关系。事实证明,我数据库上的 id 字段以某种方式搞砸了,每次我尝试插入新行时,它都试图输入第二个数字 0 主键。因此,我删除了 id 列并重新创建了它,确保将其标记为自动递增,并且也没有在其中输入任何数据,以便它可以自动递增而不会中断。现在它似乎工作得很好
感谢所有给它一个打击的人!
已更新 因此通知问题已得到解决。现在的问题是我仍然卡在一个空白的白色屏幕上,而且我没有任何信息真正进入我的数据库。我没有看到或想到的错误,但它只是没有向数据库中插入任何内容。每个人都告诉我应该搬家做 POD 什么的,但我没有时间从头开始。如果在我已经进行了无数次更改之后,如果有人能想到任何可能导致白屏的事情,我会弄湿自己 XD
我已经将我的代码更新为我目前正在运行的代码。有任何想法吗?我已经走到尽头了TT
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$hostname = "myHostName";
$username = "PreRegCustomers";
$dbname = "PreRegCustomers";
$password = "myPassword";
$usertable = "CustomerInfo";
//connect to mysql
$link_id = mysql_connect($hostname, $username, $password);
if (!$link_id) {
die("Unable to connect to database! Please try again later. error:".mysql_errno());
}
//make sure DB exists
if (!mysql_select_db($dbname)) die ("Connected to mysql but could not connect to the DB. error:".mysql_errno());
//avoid sql_injection
$firstName = mysql_real_escape_string($_POST['firstName']);
$lastName = mysql_real_escape_string($_POST['lastName']);
$streetAddress = mysql_real_escape_string($_POST['streetAddress']);
$city = mysql_real_escape_string($_POST['city']);
$state = mysql_real_escape_string($_POST['state']);
$zip = mysql_real_escape_string($_POST['zip']);
$country = mysql_real_escape_string($_POST['country']);
$email = mysql_real_escape_string($_POST['email']);
$phone = mysql_real_escape_string($_POST['phone']);
$badgeName = mysql_real_escape_string($_POST['badgeName']);
//write the query
$sql = "INSERT INTO $usertable
(firstName, lastName, streetAddress, city, state, zip, country, email, phone, badgeName)
VALUES ('$firstName', '$lastName', '$streetAddress', '$city', '$state', '$zip', '$country', '$email', '$phone', '$badgeName')";
//execute the query
mysql_query($sql);
?>
原帖:
所以我对php很陌生。就像现在两天一样,我正试图让我的网络表单将数据插入到由 go daddy 托管的 MySQL 数据库中。我尝试了很多不同的东西,我知道 php 已启用并且可以正常工作,我有一个 DNS,我一直在出现死机白屏,但是在对我的代码进行了一些更改后,我收到了一条通知,上面写着:
注意:未定义的索引:第 26 行 /home/content/85/11323785/html/devTest/insert2.php 中的国家/地区
现在据我所知,我应该可以忽略通知,除非它仍然没有向我的数据库中插入任何内容。我只是在地址栏中看到一个空白屏幕,其中包含我的.php
文件和一个通知。
任何帮助都会很重要!我的代码如下。
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$hostname = "myHostName";
$username = "PreRegCustomers";
$dbname = "PreRegCustomers";
$password = "myPassword";
$usertable = "CustomerInfo";
//connect to mysql
$link_id = mysql_connect($hostname, $username, $password);
if (!$link_id) {
die("Unable to connect to database! Please try again later. error:".mysql_errno());
}
//make sure DB exists
if (!mysql_select_db($dbname)) die ("Connected to mysql but could not connect to the DB. error:".mysql_errno());
//avoid sql_injection
$firstName = mysql_real_escape_string($_POST['firstName']);
$lastName = mysql_real_escape_string($_POST['lastName']);
$streetAddress = mysql_real_escape_string($_POST['streetAddress']);
$city = mysql_real_escape_string($_POST['city']);
$state = mysql_real_escape_string($_POST['state']);
$zip = mysql_real_escape_string($_POST['zip']);
$country = mysql_real_escape_string($_POST['country']);
$email = mysql_real_escape_string($_POST['email']);
$phone = mysql_real_escape_string($_POST['phone']);
$badgeName = mysql_real_escape_string($_POST['badgeName']);
//write the query
$sql = "INSERT INTO $usertable
(firstName, lastName, streetAddress, city, state, zip, country, email, phone, badgeName)
VALUES ('$firstName', '$lastName', '$streetAddress', '$city', '$state', '$zip', '$country', '$email', '$phone', '$badgeName')";
//execute the query
mysql_query($sql);
?>