Php 需要在表中插入“;医生;(id为自动递增)。不知道查询出了什么问题。我得到错误-“;网页不可用;。帮助解决它
Php 需要在表中插入“;医生;(id为自动递增)。不知道查询出了什么问题。我得到错误-“;网页不可用;。帮助解决它,php,html,mysql,Php,Html,Mysql,在$country=$\u POST[country']中缺少” $country=$_POST['country']; $sql = "INSERT INTO $table (firstname,lastname,speciality,hospital,city,state,country)VALUES ('$firstname','$lastname','$speciality','$hospital','$city','$state','$country')"; $result =mysq
在$country=$\u POST[country']中缺少”
代码>
$country=$_POST['country'];
$sql = "INSERT INTO $table (firstname,lastname,speciality,hospital,city,state,country)VALUES ('$firstname','$lastname','$speciality','$hospital','$city','$state','$country')";
$result =mysql_query($sql);
if ($result) {
更改此$country=$\u POST[country']代码>至$country=$\u POST['country']代码>
$country=$_POST['country'];
$sql = "INSERT INTO $table (firstname,lastname,speciality,hospital,city,state,country)VALUES ('$firstname','$lastname','$speciality','$hospital','$city','$state','$country')";
$result =mysql_query($sql);
if ($result) {
更新代码:
改变这个
mysql_connect( $host, $username, $password ) or die(" could not connect to database..." .mysql_error ());
mysql_select_db($database) or die ("Could not connect to database..." .mysql_error ());
到
语法
mysql_选择_数据库(连接,数据库名)
所以,connection和dbname是必填字段。将连接值传递给mysql\u select\u db
[注意:mysql函数
被折旧。使用PDO
或mysqli.*函数
]
<?php
$host = 'localhost';
$username = 'uai';
$password = '';
$database = 'Pharma';
$table = 'doctors';
$con = mysql_connect( $host, $username, $password ) or die(" could not connect to database..." .mysql_error ());
$db = mysql_select_db($database,$con) or die ("Could not connect to database..." .mysql_error ());
$firstname =$_POST['firstname'];
$lastname =$_POST['lastname'];
$speciality =$_POST['speciality'];
$hospital=$_POST['hospital'];
$city=$_POST['city'];
$state=$_POST['state'];
$country=$_POST['country'];
$sql = "INSERT INTO $table (firstname,lastname,speciality,hospital,city,state,country)VALUES ('$firstname','$lastname','$speciality','$hospital','$city','$state','$country')";
$result =mysql_query($sql);
if ($result) {
echo "New record created successfully";
}
else {
echo "Insertion Error: ";
}
?>
<?php
mysql_close();
?>
在$country=$\u POST[country']中缺少”
代码>你在那里遇到了什么错误?请编辑带有完整错误的问题@ganeshvasanthwhat是此页面的页面名称。仔细检查
标记action属性@ganeshvasanthform action=doctors.php,这是doctors.php页面。因此,请同时发布您的
。然后,只有我们能找到。还有一件事。doctors.php位于同一文件夹中@ganeshvasanthI改变了一些密码。请看一看@ganeshvasanth
$con = mysql_connect( $host, $username, $password ) or die(" could not connect to database..." .mysql_error ());
$db = mysql_select_db($database,$con) or die ("Could not connect to database..." .mysql_error ());
connection => Required. Specifies the MySQL connection to use
dbname => Required. Specifies the default database to be used
<?php
$host = 'localhost';
$username = 'uai';
$password = '';
$database = 'Pharma';
$table = 'doctors';
$con = mysql_connect( $host, $username, $password ) or die(" could not connect to database..." .mysql_error ());
$db = mysql_select_db($database,$con) or die ("Could not connect to database..." .mysql_error ());
$firstname =$_POST['firstname'];
$lastname =$_POST['lastname'];
$speciality =$_POST['speciality'];
$hospital=$_POST['hospital'];
$city=$_POST['city'];
$state=$_POST['state'];
$country=$_POST['country'];
$sql = "INSERT INTO $table (firstname,lastname,speciality,hospital,city,state,country)VALUES ('$firstname','$lastname','$speciality','$hospital','$city','$state','$country')";
$result =mysql_query($sql);
if ($result) {
echo "New record created successfully";
}
else {
echo "Insertion Error: ";
}
?>
<?php
mysql_close();
?>
<?php
$host = 'localhost';
$username = 'uai';
$password = '';
$database = 'Pharma';
$table = 'doctors';
$con = mysqli_connect($host, $username, $password,$database) or die(" could not connect to database..." .mysqli_connect_error());
$firstname =$_POST['firstname'];
$lastname =$_POST['lastname'];
$speciality =$_POST['speciality'];
$hospital=$_POST['hospital'];
$city=$_POST['city'];
$state=$_POST['state'];
$country=$_POST['country'];
$result = mysqli_query($con,"INSERT INTO $table (firstname,lastname,speciality,hospital,city,state,country)VALUES ('$firstname','$lastname','$speciality','$hospital','$city','$state','$country')");
if ($result) {
echo "New record created successfully";
}
else {
echo "Insertion Error: ";
}
mysqli_close($con);
?>