如何使用wampserver创建数据库并与php页面连接

时间:2013-09-03 10:35:30

标签: php html mysql wampserver

我为登录页面创建了网页前端设计并将其保存为.php文件。

我甚至安装了wampserver。

让我知道如何连接mysql数据库wampserver和我的登录页面。

是否可以使用工具中wampserver中给出的数据库选项?

如果可能,我们如何连接到登录页面?请提出一些想法...

1 个答案:

答案 0 :(得分:0)

可以在Phpmyadmin中的wampserver中创建数据库,也可以创建表。

以下是连接数据库的代码     

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
 or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";

//select a database to work with
$selected = mysql_select_db("database1",$dbhandle) // "database1" is the database name
 or die("Could not select database1");

//execute the SQL query and return records .. insert ur login info also
$result = mysql_query("SELECT uid  FROM login"); // "login" is table
if(mysql_num_rows($result) != 0){
$result1 = INSERT INTO login (id, name, password) VALUES
('".$_POST['id']."','".$_POST['name']."','".$_POST['password']."'); // The values which
                                                        //you entered in the login form

} else {
 echo "This login name already exists";
}
?>
This is the simple way to connect the database and insert the data into tables. But 
dont forget to create database and tables in phpmyadmin before inserting the data