doushizhou4477 2017-01-21 12:46
浏览 6

PHP没有执行,也没有向数据库添加信息

I am on a localserver learning mysql and php on my local server MAMP, below i will put the code to all three of my files index.php, signup.php and dbh.php. I am trying to create a log in system but it does not send the information in the database but i do not get an error message either when running it runs fine but does not add the information that i entered in the sign up form.

My database name is drugcity and my username is drugcity_data and my password is admin

So please help been trying for hours!

index.php

<!DOCTYPE html>

<html>
    <head>
        <meta charset="UTF-8">
        <title>Drug City</title>
        <link rel="stylesheet" type="text/css" href="style.css">
    </head>
    <body>
        <form action="signup.php" method="POST">
            <input type="text" name="usrname" placeholder="Username Here"><br>
            <input type="password" name="pwd" placeholder="Password Here"><br>
            <button>Sign Up</button>
        </form>
    </body>
</html>

signup.php

<?php
    include 'dbh.php';

    $username = $_POST['usrname'];
    $pass = $_POST['pwd'];

    $sql = "INSERT INTO users(usrname, pwd) VALUES ('$username','$pass')";
    $result = mysqli_query($conn, $sql);


    header("Location: index.php");
?>

dbh.php

<?php
    $user = 'drugcity_data';
    $password = 'admin';
    $db = 'drugcity';
    $host = 'localhost';
    $port = 8889;
    $conn = mysqli_connect($link, $host, $user, $password, $db, $port);
?>
  • 写回答

2条回答 默认 最新

  • dongwu8050 2017-01-21 12:52
    关注

    I think, you have wrong connection to DB. You have

    $conn = mysqli_connect($link, $host, $user, $password, $db, $port);

    Why you have there $link variable? Try it without $link, so

    $conn = mysqli_connect($host, $user, $password, $db, $port);

    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据