PHP mysql数据库 插入不报错,但无数据参入,SQL语句在PHPMYADMIN运行通过
<?phpsession_start();require'conn.php';$username=$_POST[userID];$password=sha1($_POST...
<?php
session_start();
require 'conn.php';
$username=$_POST[userID];
$password=sha1($_POST[password]);
$name=$_POST[name];
$gender=$_POST[gender];
$country=$_POST[country];
$phone=$_POST[phone];
$Email=$_POST[email];
$sql="INSERT INTO user (username,password,name,gender,country,phone,Email)";
$sql.=" VALUES ('$username','$password','$name','$gender','$country','$phone','$Email')";
echo $sql;
$result=mysqli_query($link,$sql);
/* echo $result;
echo mysqli_connect_error();
echo mysqli_error($link);
*/
if($result==false){
echo"<script>alert('false');history.back;<//script>";
}else{
$_SESSION['username']=$username;
$_SESSION['id']=$link->insert_id;
echo"<script>alert('success');window.location.href='../profile.php';</script>";
}
?>
conn.php
<?php$link = mysqli_init();if (!$link) { die('mysqli_init failed');}if (!mysqli_options($link, MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0')) { die('Setting MYSQLI_INIT_COMMAND failed');}if (!mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, 5)) { die('Setting MYSQLI_OPT_CONNECT_TIMEOUT failed');}if (!mysqli_real_connect($link, 'localhost', 'root', '', 'Music')) { die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());}?>
数据库设置 展开
session_start();
require 'conn.php';
$username=$_POST[userID];
$password=sha1($_POST[password]);
$name=$_POST[name];
$gender=$_POST[gender];
$country=$_POST[country];
$phone=$_POST[phone];
$Email=$_POST[email];
$sql="INSERT INTO user (username,password,name,gender,country,phone,Email)";
$sql.=" VALUES ('$username','$password','$name','$gender','$country','$phone','$Email')";
echo $sql;
$result=mysqli_query($link,$sql);
/* echo $result;
echo mysqli_connect_error();
echo mysqli_error($link);
*/
if($result==false){
echo"<script>alert('false');history.back;<//script>";
}else{
$_SESSION['username']=$username;
$_SESSION['id']=$link->insert_id;
echo"<script>alert('success');window.location.href='../profile.php';</script>";
}
?>
conn.php
<?php$link = mysqli_init();if (!$link) { die('mysqli_init failed');}if (!mysqli_options($link, MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0')) { die('Setting MYSQLI_INIT_COMMAND failed');}if (!mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, 5)) { die('Setting MYSQLI_OPT_CONNECT_TIMEOUT failed');}if (!mysqli_real_connect($link, 'localhost', 'root', '', 'Music')) { die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());}?>
数据库设置 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询