gpt4 book ai didi

php - mysql 将值插入表中?

转载 作者:行者123 更新时间:2023-11-29 23:18:39 25 4
gpt4 key购买 nike

我正在尝试将注册表单数据插入到我的表中,但由于某种原因没有插入任何内容,并且我没有收到错误。

有人可以告诉我哪里出了问题吗,因为我对 php 和 MySQL 很陌生,提前谢谢。

我的 config.php 文件保存我的连接:

<?php
$host="localhost";
$username="mark";
$password="password";
$db_name="hewden1";
$conn = mysql_connect("$host", "$username", "$password") or die("Could Not Connect to Server");
$db = mysql_select_db("$db_name")or die("Cannot Connect the Database");
?>

这是我的注册表 html:

<form name="test" action="validation/signup_process.php" method="post">
<input type="text" name="compname" class="login_form" placeholder="Company or Trading Name">
<br>
<input type="text" name="contactname" class="login_form" placeholder="Contact Name"><br><br><br>
<input type="text" name="emailaddress" class="login_form" placeholder="Email Address">
<br>
<input type="text" name="password1" class="login_form" placeholder="Password">
<input type="text" name="password2" class="login_form" placeholder="Confirm Password"><br>

<input type="submit" name="submit" value="Register" class="buttons">
</form>

我的 php/MySQL 代码:

<?php 
session_start();
include("config.php");
//retrieve our data from POST
$compname = $_POST['compname'];
$contactname = $_POST['contactname'];
$username = $_POST['emailaddress'];
$password1 = $_POST['password1'];
$password2 = $_POST['password2'];

if($password1 != $password2) {
$_SESSION['message2'] = '<div id="message_box2"><div class="boxclose" id="boxclose" onclick="this.parentNode.parentNode.removeChild(this.parentNode);"></div><h23>Ooops!</h23><p>The Password&#39;s did not match.</p> </div>';
header("location:..\sign-up.php");

}else{
if(strlen($username) > 30) {
$_SESSION['message2'] = '<div id="message_box2"><div class="boxclose" id="boxclose" onclick="this.parentNode.parentNode.removeChild(this.parentNode);"></div><h23>Ooops!</h23><p>The Username you have selected is incorrect.</p> </div>';
header("location:..\sign-up.php");

}else{

$hash = hash('sha256', $password1);

function createSalt(){
$text = md5(uniqid(rand(), true));
return substr($text, 0, 3); }
$salt = createSalt();
$password = hash('sha256', $salt . $hash);

$username = mysql_real_escape_string($username);
$query = "INSERT INTO supplier_pre_sign (contactname, company_name, supplier_email, password, date, user_type) VALUES ('$contactname','$compname','$username', '$salt', now(), 'visitor');" or die(mysql_error());

echo "eveything ok";

} }?>

最佳答案

您忘记执行查询。您需要执行查询才能插入到数据库中。

试试这个:

    <?php 
session_start();
include("config.php");
//retrieve our data from POST
$compname = $_POST['compname'];
$contactname = $_POST['contactname'];
$username = $_POST['emailaddress'];
$password1 = $_POST['password1'];
$password2 = $_POST['password2'];

if($password1 != $password2) {
$_SESSION['message2'] = '<div id="message_box2"><div class="boxclose" id="boxclose" onclick="this.parentNode.parentNode.removeChild(this.parentNode);"></div><h23>Ooops!</h23><p>The Password&#39;s did not match.</p> </div>';
header("location:..\sign-up.php");

}else{
if(strlen($username) > 30) {
$_SESSION['message2'] = '<div id="message_box2"><div class="boxclose" id="boxclose" onclick="this.parentNode.parentNode.removeChild(this.parentNode);"></div><h23>Ooops!</h23><p>The Username you have selected is incorrect.</p> </div>';
header("location:..\sign-up.php");

}else{

$hash = hash('sha256', $password1);

function createSalt(){
$text = md5(uniqid(rand(), true));
return substr($text, 0, 3); }
$salt = createSalt();
$password = hash('sha256', $salt . $hash);

$username = mysql_real_escape_string($username);
$query = "INSERT INTO supplier_pre_sign (contactname, company_name, supplier_email, password, date, user_type) VALUES ('$contactname','$compname','$username', '$salt', now(), 'visitor')";
mysql_query($query); //You forgot to add this line
echo "eveything ok";

} }?>

关于php - mysql 将值插入表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27543617/

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