我正在尝试创建一个处理现有用户名之类的页面。这就是我到目前为止所得到的。
<?php
// Parse the form data and add inventory item to the system
if (isset($_POST['username'])) {
$username = ($_POST['username']);
$password = ($_POST['password']);
$level = ($_POST['level']);
// See if that product name is an identical match to another product in the system
$sql = mysql_query("SELECT id FROM users WHERE username='$username' LIMIT 1");
include "storescripts/connect_to_mysql.php";
$productMatch = mysql_num_rows($sql); // count the output amount
if ($productMatch > 0) {
header("location: message.php?msg=activation_failure");
exit();
}
// Add this product into the database now
$username = preg_replace('#[^a-z0-9]#i', '', $_POST['username']);
$email = mysql_real_escape_string($_POST['email']);
$p_hash = md5($password);
$sql = mysql_query("INSERT INTO users (username, password, email, level, date_added)
VALUES('$username','$p_hash','$email','$level',now())") or die (mysql_error());
header("location: order_complete.php");
exit();
}
?>
if 语句查询 mysql 以确定表单条目和数据库之间是否匹配。然后我想去message.php,并带有类似...这个用户名已经存在的消息。非常感谢有关如何执行此操作或如何处理它的任何提示。
进一步澄清..表格开始:
<form action="user-info.php" enctype="multipart/form-data" name="signupform" id="signupform" method="post">
和message.php
<?php
$message = "";
$msg = preg_replace('#[^a-z 0-9.:_()]#i', '', $_GET['msg']);
if($msg == "sorryuser"){
$message = 'No good';
} else if($msg == "activation_success"){
$message = 'test';
} else {
$message = $msg;
}
?>
<?php include_once("./includes/site-opener.php");?>
<title></title>
</head>
<body id="home">
<?php include 'includes/header.php'; ?>
<?php include 'includes/content-opener.php'; ?>
<div class="containOthers">
<div style="width:300px;margin-left:auto;margin-right:auto;margin-bottom:40px;min-height:500px;">
<div><?php echo $message; ?><?php echo $emailError; ?></div>
</div>
</div>
<?php include 'includes/footer.php'; ?>
</body>
</html>
这是表单提交后 user-info.php 上的错误。
警告:mysql_query():第 18 行 /home3/onlinfaa/public_html/user-info.php 中的用户 'onlinfaa'@'localhost' 的访问被拒绝(使用密码:NO)警告:mysql_query():到服务器的链接无法在第 18 行的 /home3/onlinfaa/public_html/user-info.php 中建立 警告:mysql_num_rows() 期望参数 1 是资源,布尔值在第 20 行的 /home3/onlinfaa/public_html/user-info.php 中给出密钥“用户名”的重复条目“test-email@aol.com”