我似乎无法将我的PHP页面连接到我的SQL测试服务器和数据库 [英] I cannot seem to connect my PHP page to my SQL test server and database
问题描述
我想要发生的是一个用户填写一个表单,并将这些信息发送到数据库。我在dreamweaver中使用html和php,使用phpMyAdmin使用WAM。
我已经尝试了一切,我似乎无法得到我的.php文件与我的localhost测试服务器(或任何服务器)。这是一个注册注册表单,并有一个html文档和一个php文档,我将包括两个:
HTML表单:
< table width =15pxborder =0>
< form form action =localhost.phpmethod =POST>
< tr>
< td>用户名< / td>
< td>< input type =textname =username/>< / td>
< / tr>
< tr>
< td> Skype名称< / td>
< td>< input type =textname=skype/>< / td>
< / tr>
< tr>
< td>电子邮件< / td>
< td>< input type =textname =email/>< / td>
< / tr>
< td>密码< / td>
< td>< input type =passwordname =pass/>< / td>
< / tr>
< tr>
< td>重新输入密码< / td>
< td>< input type =passwordname =repass/>< / td>
< / tr>
< tr>
< td>< input type =submitname =submitvalue =Submit/>< / td&
< / tr>
< / form>
PHP档案:
<?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>注册< / 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 不能留空任何字段;
}
elseif($ pass!= $ repass)
{
echo密码不符,请重试。
}
else
{
$ sql =INSERT INTO用户(用户名,SkypeID,电子邮件,密码)。
VALUES('$ username','$ skype','$ email','$ pass');
$ res = mysqli_query($ localhost,$ sql);
if(!$ res)
{
die(Query Failed.mysqli_error($ localhost));
}
else
{
echoWelcome;
}
}
}
字段来测试它,数据不会发送到localhost服务器(或连接到WAM的服务器)。我不知道我在这里做错了什么。我的HTML和PHP文档没有互连以共享值?代码有什么问题吗?我没有正确定义我的数据库?
解决方案:我的POST和提交不被视为区分大小写。感谢您的帮助。
您尝试编辑您的php:
isset($ _ POST ['Submit']
并将其更改为:
isset($ _ POST ['submit']
/ pre>
变量$ _POST区分大小写,因此您应该使用在HTML代码中分配的完全相同的名称。
CMIIW
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.
解决方案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
这篇关于我似乎无法将我的PHP页面连接到我的SQL测试服务器和数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!