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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18590068/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:52:08  来源:igfitidea点击:

how to create database using wampserver and to connect with the php page

phphtmlmysqlwampserver

提问by user2728468

I have created the webpage frontend design for a login page and saved it as .phpfile.

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

I have even installed wampserver.

我什至安装了wampserver。

Give me some idea how to connect a mysql database wampserver and my login page.

给我一些如何连接 mysql 数据库 wampserver 和我的登录页面的想法。

Is it possible to use the database option given in wampserver inside the tools?

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

If it is possible, how we can connect to the login page? Please give some idea...

如果可能,我们如何连接到登录页面?请给点意见...

回答by user2696043

It is possible to create the database in wampserver in Phpmyadmin and can create the tables also.

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

The following is the code to connect to database

以下是连接数据库的代码

//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