I cannot seem to connect my PHP page to my SQL test server and database

跟風遠走 提交于 2019-12-22 10:38:34

问题


What I would like to happen is for a user to fill out a form and that information be sent to a database. I am using html and php in dreamweaver, and WAM with phpMyAdmin.

I have tried everything and I cannot seem to get my .php file to work with my localhost test server (or any server for that matter). It is a sign up registration form, and there is a html document and a php document, I will include both:

HTML Form:

<table width="15px" border="0">
<form form action="localhost.php" method="POST">
<tr>
<td>Username</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>Skype Name</td>
<td><input type="text" name="skype" /></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="pass" /></td>
</tr>
<tr>
<td>Retype Password</td>
<td><input type="password" name="repass" /></td>
</tr>
<tr>
  <td><input type="submit" name="submit" value="Submit"/></td>
</tr>
</form>

PHP File:

<?php
$hostname= "localhost";
$database = "boost";
$username = "root";
$password = "";
$localhost = mysqli_connect($hostname, $username, $password, $database);
if(mysqli_connect_errno())
    {
        die('Connection Failed'.mysqli_error());
    }

    ?> 
 <html>
  <head>
    <title>Sign Up</title>
  </head>
  <body>
    <?php 
        if(isset($_POST['Submit']))
        {
            $username=$_Post['username'];
            $skype=$_Post['skype'];
            $email=$_Post['email'];
            $pass=$_Post['pass'];
            $repass=$_Post['repass'];
                if(empty($username) || empty($skype) || empty($email) || empty($pass) || empty($repass))
                {
                    echo "Cannot leave any field blank";
                }
                elseif ($pass!=$repass)
                    {
                        echo "Passwords did not match! Please try again.";
                    }
                else
                {
                    $sql="INSERT INTO users(Username,SkypeID,Email,Password) " .
                         "VALUES ('$username','$skype','$email','$pass')";
                    $res=mysqli_query($localhost,$sql);
                    if(!$res)
                    {
                        die("Query Failed" .mysqli_error($localhost));
                    }
                else
                    {
                        echo "Welcome";
                    }
                }
        }

When I enter data into the fields to test it out, data is not sent to the localhost server (or the one connected to WAM). I don't know what I am doing wrong here. Are my HTML and PHP documents not interconnected to share values? Is there something wrong with the code? Am I not defining my database properly?

SOLUTION: My "POST" and "submit" where not being treated as case-sensitive. Thanks for the help.


回答1:


Have you try to edit your php :

isset($_POST['Submit']

and change it to :

isset($_POST['submit']

variable $_POST is case-sensitive so you should use the exact same name that you assign in your html code.

CMIIW



来源:https://stackoverflow.com/questions/33622900/i-cannot-seem-to-connect-my-php-page-to-my-sql-test-server-and-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!