我是 php 新手,我正在尝试使用 php 和 mysql 制作一个简单的注册表单。我遵循了一个教程,但它似乎不起作用。
这是我的代码:
配置文件
<?php
$host = "******";
$user = "******";
$pass = "******";
$db = '******';
$con = mysql_connect($host,$user,$pass) or die('could not connect to database.');
mysql_select_db($db,$con) or die('could not find database');
?>
注册.php
<?php
include "con.php";
$username = $_POST['user_name'];
$password = md5($_POST['password']);
$first = $_POST['first'];
$last = $_POST['last'];
$insert = "insert into users (user_name,password,first,last) values(".$username.",".$password.",".$first.",".$last.")";
mysql_query($insert) or die("Sorry could not complete signup");
echo 'Signup succsessfull';
?>
HTML
<form action='register.php' method='post'>
<div style='color:orange;'>First name:</div>
<input type='text' name='first' value='<?php if(isset($_POST["first"])){echo $_POST["first"];}?>'>
<div style='color:orange;'>Last name:</div>
<input type='text' name='last' value='<?php if(isset($_POST["last"])){echo $_POST["last"];}?>'>
<div style='color:orange;'>User name:</div>
<input type='text' name='user_name' value='<?php if(isset($_POST["user_name"])){echo $_POST["user_name"];}?>'>
<div style='color:orange;'>Password:</div>
<input type='password' name='password'>
<input type='reset' value='Reset'>
<input type='submit' value='Submit'>
</form>
如果有人可以帮助解决这个问题,那就太好了,因为我做不到。