-1

因此,我在引用数据库以存储我的网站的新用户信息时遇到问题。这是我们正在使用的 html 示例。我也提供了 php 表单。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd"
    >
<html lang="en">
<head>
    <title>Log In</title>
</head>
<body>
<form action= "form_process.php" method="post">

//Inputting user information: first name, last name, password, gender.
First Name: <input type="text" name="firstname"> <br/>
Last Name: <input type="text" name="lastname"> <br/>
Password <input type="password" name="password"> <br/>
Are you male or female?<br/>
Male<input type="radio" name="Male" value="Male"> <br/>
Female<input type="radio" name="Female" value="Female"> <br/>
<input type="submit" value="submit"> 
</form> 
</body>
</html>

Here is the php form that I am using to confirm the data passed.

<?php
$first = $_POST['first'];
$last = $_POST['last'];
$email = $_POST['email'];

echo("First: ". $first);
echo("<br/>Last: " . $last);
echo("<br/>Email: " . $email);
?>

让我知道如何将信息存储到 mysql。我使用 Go Daddy 作为 mysql 服务器。

谢谢!

4

1 回答 1

1

假设您的表很简单,具有与您通过 HTTP POST 收集的内容相匹配的字段,您将执行以下操作:

// open database connection
$db = new PDO('mysql:host=hostname;dbname=dbname', 'username', 'password');

// prepare SQL statement
$sql = $db->prepare("INSERT INTO table (first, last, email) VALUES (?, ?, ?)");

// execute prepared statement and insert into db
$sql->execute(array($first, $last, $email));

对于一个非常好的 PDO 初学者教程,我会查看:http ://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers

于 2013-06-18T20:26:45.647 回答