它们没有错误,但当我检查phpmyadmin时,它没有显示任何数据条目。这是我的代码-
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="registered.css" rel="stylesheet"/>
<title>Registration details</title>
<?PHP
require ('C:/xampp/htdocs/try/connect.php');
$name = isset($_POST['usernamesignup']);
$email = isset($_POST['emailsignup']);
$password = isset($_POST['passwordsignup']);
$confirm_password= isset($_POST['passwordsignup_confirm']);
$password_hash = md5($password);
if (isset($_POST['submit'])) {
$sql12="SELECT * FROM register";
$result12= mysql_query($sql12);
if($result12== FALSE){
die(mysql_error());
}
while($rows=mysql_fetch_array($result12)){
if($email==$rows['email'] ){
die('Sorry, The email-id you entered is present in our database. Please use your other ID. <a href="index.html"> Go Back </a>');
}
}
$query = "INSERT INTO register (name,password,email) VALUES ('$name','$password_hash','$email')";
mysqli_query($link,$query) or die('Error in connecting database');
mysqli_close($link);
}
?>
</head>
Thank you for registering.
</html>
connect.php的代码是-
<?php
$link=mysql_connect('localhost','root','','register') or die('error connecting');
mysql_select_db('register',$link) or die('cannot select db');
?>
输出是感谢您的注册。var_dump显示值正在发布。请帮忙。
不要混合使用mysql和mysqli
您正在mysql_
连接上运行mysqli_query
。如果你将连接切换到mysqli_connect
,这将解决你遇到的特定问题(阅读文档以确保这不需要对你的参数进行任何更改)。
这里有另一个mysql_query
:
$result12= mysql_query($sql12);
变量分配不正确
您还分配:
$name = isset($_POST['usernamesignup']);
$email = isset($_POST['emailsignup']);
如果设置,则会将这两个变量都设置为true
。这可能会导致MySQL查询在尝试将其传递到查询中时失败。
你可能想这样做:
if (true === isset($_POST['usernamesignup']) && true === isset($_POST['email']) {
$name = $_POST['usernamesignup'];
$email = $_POST['email'];
} else {
throw new Exception('Username or e-mail address not sent.');
}
Asi表示
Xdebug是你的朋友,display_errors
也是。
当你在等待Xdebug编译时,我建议你查找绑定参数(否则有人可以用这个代码对你的数据库做任何他们想做的事情),以及为什么在2015年使用md5
来哈希密码是一个非常糟糕的主意(看看password_hash
和password_verify
,它并不比明文好多少)。