dtcyv3985 2014-12-18 09:50
浏览 26
已采纳

mysql将值插入表中?

I am trying to insert my registration form data into my table but for some reason nothing is being inserted and I am not getting an error.

could someone please show me where I am going wrong with this as I am really new to php and MySQL, thanks in advance.

my config.php file holds my connection:

<?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"); 
?>

Here's my registration form 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> 

my php/MySQL code:

<?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";

} }?>
  • 写回答

5条回答 默认 最新

  • doudunyi3796 2014-12-18 09:54
    关注

    You forgot to execute your query. You need to execute the query in order to insert in to your database.

    Try this :

        <?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";
    
        } }?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据