gpt4 book ai didi

php - 下面给出的 insert.php 有问题吗?

转载 作者:行者123 更新时间:2023-11-29 05:37:02 25 4
gpt4 key购买 nike

我已努力调试以下 insert.php 文件。在 wamp 服务器中运行它和相关的 webform 文件时没有错误,但它没有将数据读取到数据库中。有人可以对此发表评论吗?

?php
if (isset($_POST['submit'])) {


//Connect to the database



$host="localhost";
$user="root";
$password="";
$dbc=mysql_connect($host,$user,$password) or die("Connection Error");
$db_name="userregistration";
mysql_select_db("$db_name") or die ("Could not select database");



//Reading data from form and writing to the DB
$fname = $_POST['fname'];
$institution = $_POST['institute'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$pgm = $_POST['pgm'];
$address = $_POST['address'];



//Examining for input errors
$error = FALSE;


if (isset($address)) {
$address = trim($address);
$address = strip_tags($address);
}

if (isset($fname) &&
isset($institute) &&
isset($email) &&
isset($phone) &&
isset($pgm) &&
isset($address) &&
$error == FALSE) {
$process = TRUE;
} else {
$process = FALSE;
}

//Writing the multiple answers for user selected programs

while ((list($key,$val) = each($pgm))) {
$pgm .= "[" . $val . "]";
}



//Creating the table
$query = "create table userdata
( sid int unsigned not null auto_increment primary key,
fname char(50) not null,
institute char(50) not null,
email char(50) not null,
phone int unsigned,
pgm text not null,
address char(200) not null)";
$q = mysql_query($query);




//Inserting the data
$query = "insert into userdata values ('','$fname','$institute','$email','$phone','$pgm','$address')";
$q = mysql_query($query);


//Check whether data was properly inserted
if (!$q) {
exit("<p>MySQL Insertion failure.</p>");
} else {
mysql_close();
echo "<p>MySQL Insertion Successful</p>";
}

}
?>

有人可以对此发表评论吗?

最佳答案

尝试添加

or die(mysql_error());

在你的 mysql_query($query) 之后。如果失败,那肯定会显示错误...

关于php - 下面给出的 insert.php 有问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9826523/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com