gpt4 book ai didi

php - 使用 PHP 和 MySQL 登录应用程序

转载 作者:太空宇宙 更新时间:2023-11-03 12:27:42 26 4
gpt4 key购买 nike

我使用 HTML 创建了两个文本字段,我想将这些文本处理到我的数据库中。

我想使用 PHP 验证该数据并将其发送到数据库中;但我的问题是我在字段中输入的数据没有处理到数据库中。

我的代码如下:

<form action="index.php" method="post">
<b>username:</b><input type="text" name="textbox1"/>
<b>password:</b><input type="password" name="textbox2"/>
<input type="submit" value="submit">
<?php
if(isset($_POST['textbox1'])&&isset($_POST['textbox2']))
{
$conn_error = 'couldnot connected';
$mysql_user = 'root';
$mysql_pass = '';
$mysql_host = 'localhost';
$mysql_db = 'yep_recharge';
$textbox1 = $_POST['textbox1'];
$textbox2 = $_POST['textbox2'];
if(empty($textbox1)&&empty($textbox2))
{
echo 'required field';
}
if(!empty($textbox1)&&!empty($textbox2))
{
$query = "SELECT `ID` FROM `yep_registration` WHERE `USERNAME`='$textbox1' AND `PASSWORD`='$textbox2'";//"SELECT `ID` from `yep_registration` WHERE `USER-NAME`='$textbox1' and `PASSWORD` = '$textbox2'";
if($query_run = mysql_query($query))
{
$query_num_rows = mysql_num_rows($query_run);
if($query_num_rows==0)
{
echo 'Invalid User Name And Password:';
}
else if($query_num_rows==1)
{
echo 'ok';
}
}
}
}

</form>

最佳答案

你连接到数据库了吗?您可以将资源句柄与您的一些 mysql 函数一起使用:

$db = mysql_connect($mysql_host, $mysql_user, $mysql_pass);

这样你就可以:

$query = mysql_query('query',$db);

(您实际上不需要在查询调用中使用资源句柄。PHP 将假定使用最近打开的数据库连接)

关于php - 使用 PHP 和 MySQL 登录应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16868757/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com