Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法将用户名加载到数据库中_Php_Mysql - Fatal编程技术网

Php 无法将用户名加载到数据库中

Php 无法将用户名加载到数据库中,php,mysql,Php,Mysql,我以前使用过这段代码,现在无法再使用它。密码可以加载到数据库中,但用户名不会。用户名标记正确。加载时,用户名为空。请帮忙 我不断得到以下错误: 警告:mysqli_query()至少需要两个参数,其中一个参数在第55行的C:\xampp\htdocs\signup.php中给出 我知道错误的意思。我现在不明白为什么$createusername不作为参数读取 <?php $createusername = (isset($_GET['createusername']) ? $_GE

我以前使用过这段代码,现在无法再使用它。密码可以加载到数据库中,但用户名不会。用户名标记正确。加载时,用户名为空。请帮忙

我不断得到以下错误:

警告:mysqli_query()至少需要两个参数,其中一个参数在第55行的C:\xampp\htdocs\signup.php中给出

我知道错误的意思。我现在不明白为什么$createusername不作为参数读取

<?php
    $createusername = (isset($_GET['createusername']) ? $_GET['createusername'] : null);
$createpassword = (isset($_POST['createpassword']) ? $_POST['createpassword'] : null);
$confirmpassword = (isset($_POST['confirmpassword']) ? $_POST['confirmpassword'] : null);


function unique_salt() {
    return substr(sha1(mt_rand()),0,22);
}
$unique_salt = unique_salt();


function myhash($createpassword, $unique_salt) {
    return crypt($createpassword, '$2y$10$'.$unique_salt);
}
$myhash = myhash($createpassword, $unique_salt);

$con=mysqli_connect("mysite","mylogin","mypassword","mydatabase");


if (mysqli_connect_errno()) {
  echo "Failed to connect to database." . mysqli_connect_error();
}

$sql=mysqli_query("INSERT INTO Users (username, password) VALUES ('$createusername', '$myhash')");


if($createpassword != $confirmpassword) {
    trigger_error("The passwords do not match.");
}else {
$sql;
}
mysqli_close($con);
?>

<

div style="color:#000047;margin-top:60px;">
<form id='newuser' accept-charset='UTF-8' style='margin-top:-45px;'> 
<fieldset > 
<legend style="font-family:verdana;color:#000047;">New User</legend> 
<input type='hidden' name='submitted' id='submitted' value='1'/>   
<label for='createusername' >Create UserName:</label> 
<input type='text' id='createusername'  method='get' maxlength="50" style="background-color:#000047;color:#FFFFFF;"/>   
<label for='createpassword' >Create Password:</label> 
<input type='text' id='createpassword' method='post' maxlength="50" style="background-color:#000047;color:#FFFFFF;"/>
<label for='createpassword' >Confirm Password:</label> 
<input type='text' id='confirmpassword' method='post' maxlength="50" style="background-color:#000047;color:#FFFFFF;"/>
<input type="image" id="login2" method='post' src="/images/submit.jpg" alt="Submit" style="vertical-align:bottom" />    
</fieldset> 
</form> 
</div>
<h3>Please sign in after registration.</h3>
<a href="index.php"><h3>Sign In</h3></a>

在查询中,您需要提供连接:

$sql = mysqli_query($con, "INSERT INTO Users (username, password) VALUES ('$createusername', '$myhash')");
如果使用该版本,则不需要传入连接,因为它存储在对象中



作为旁注,您的代码容易受到SQL注入的攻击。您可以通过过滤输入或使用来解决此问题。

在查询中,您需要提供连接:

$sql = mysqli_query($con, "INSERT INTO Users (username, password) VALUES ('$createusername', '$myhash')");
如果使用该版本,则不需要传入连接,因为它存储在对象中



作为旁注,您的代码容易受到SQL注入的攻击。您可以通过过滤输入或使用来解决此问题。

在查询中,您需要提供连接:

$sql = mysqli_query($con, "INSERT INTO Users (username, password) VALUES ('$createusername', '$myhash')");
如果使用该版本,则不需要传入连接,因为它存储在对象中



作为旁注,您的代码容易受到SQL注入的攻击。您可以通过过滤输入或使用来解决此问题。

在查询中,您需要提供连接:

$sql = mysqli_query($con, "INSERT INTO Users (username, password) VALUES ('$createusername', '$myhash')");
如果使用该版本,则不需要传入连接,因为它存储在对象中


作为旁注,您的代码容易受到SQL注入的攻击。您可以通过过滤输入或使用来解决此问题。


你的表格解释了一切。你用错误的方式处理它。您应该有这样一个表单:

<form action="" method="post">
    <fieldset > 
        <legend style="font-family:verdana;color:#000047;">New User</legend> 
        <input type='hidden' name='submitted' id='submitted' value='1'/>   
        <label for='createusername' >Create UserName:</label> 
        <input type='text' id='createusername' name="createusername" maxlength="50" style="background-color:#000047;color:#FFFFFF;"/>   
        <label for='createpassword' >Create Password:</label> 
        <input type='text' id='createpassword' name="createpassword" maxlength="50" style="background-color:#000047;color:#FFFFFF;"/>
        <label for='createpassword' >Confirm Password:</label> 
        <input type='text' id='confirmpassword' name="confirmpassword" maxlength="50" style="background-color:#000047;color:#FFFFFF;"/>
        <input type="image" id="login2" src="/images/submit.jpg" alt="Submit" style="vertical-align:bottom" />    
    </fieldset> 
</form>
我是说,他们制定指导方针是有原因的。因此,遵循这些原则是切实可行的


一些阅读

你的表格解释了一切。你用错误的方式处理它。您应该有这样一个表单:

<form action="" method="post">
    <fieldset > 
        <legend style="font-family:verdana;color:#000047;">New User</legend> 
        <input type='hidden' name='submitted' id='submitted' value='1'/>   
        <label for='createusername' >Create UserName:</label> 
        <input type='text' id='createusername' name="createusername" maxlength="50" style="background-color:#000047;color:#FFFFFF;"/>   
        <label for='createpassword' >Create Password:</label> 
        <input type='text' id='createpassword' name="createpassword" maxlength="50" style="background-color:#000047;color:#FFFFFF;"/>
        <label for='createpassword' >Confirm Password:</label> 
        <input type='text' id='confirmpassword' name="confirmpassword" maxlength="50" style="background-color:#000047;color:#FFFFFF;"/>
        <input type="image" id="login2" src="/images/submit.jpg" alt="Submit" style="vertical-align:bottom" />    
    </fieldset> 
</form>
我是说,他们制定指导方针是有原因的。因此,遵循这些原则是切实可行的


一些阅读

你的表格解释了一切。你用错误的方式处理它。您应该有这样一个表单:

<form action="" method="post">
    <fieldset > 
        <legend style="font-family:verdana;color:#000047;">New User</legend> 
        <input type='hidden' name='submitted' id='submitted' value='1'/>   
        <label for='createusername' >Create UserName:</label> 
        <input type='text' id='createusername' name="createusername" maxlength="50" style="background-color:#000047;color:#FFFFFF;"/>   
        <label for='createpassword' >Create Password:</label> 
        <input type='text' id='createpassword' name="createpassword" maxlength="50" style="background-color:#000047;color:#FFFFFF;"/>
        <label for='createpassword' >Confirm Password:</label> 
        <input type='text' id='confirmpassword' name="confirmpassword" maxlength="50" style="background-color:#000047;color:#FFFFFF;"/>
        <input type="image" id="login2" src="/images/submit.jpg" alt="Submit" style="vertical-align:bottom" />    
    </fieldset> 
</form>
我是说,他们制定指导方针是有原因的。因此,遵循这些原则是切实可行的


一些阅读

你的表格解释了一切。你用错误的方式处理它。您应该有这样一个表单:

<form action="" method="post">
    <fieldset > 
        <legend style="font-family:verdana;color:#000047;">New User</legend> 
        <input type='hidden' name='submitted' id='submitted' value='1'/>   
        <label for='createusername' >Create UserName:</label> 
        <input type='text' id='createusername' name="createusername" maxlength="50" style="background-color:#000047;color:#FFFFFF;"/>   
        <label for='createpassword' >Create Password:</label> 
        <input type='text' id='createpassword' name="createpassword" maxlength="50" style="background-color:#000047;color:#FFFFFF;"/>
        <label for='createpassword' >Confirm Password:</label> 
        <input type='text' id='confirmpassword' name="confirmpassword" maxlength="50" style="background-color:#000047;color:#FFFFFF;"/>
        <input type="image" id="login2" src="/images/submit.jpg" alt="Submit" style="vertical-align:bottom" />    
    </fieldset> 
</form>
我是说,他们制定指导方针是有原因的。因此,遵循这些原则是切实可行的


一些阅读
各位,你们已经在这里看到了,这是好朋友弗雷德给你们的最后一个答案。 我将正式退出回答。它的评论只是帮助。
目前,表单没有方法,因此它默认为GET。另外,您正在使用2个POST条件。那些不行。如果您在
中添加
method=“post”
各位,这是您在good'ol Fred中看到的最后一个答案。 我将正式退出回答。它的评论只是帮助。
目前,表单没有方法,因此它默认为GET。另外,您正在使用2个POST条件。那些不行。如果您在
中添加
method=“post”
各位,这是您在good'ol Fred中看到的最后一个答案。 我将正式退出回答。它的评论只是帮助。
目前,表单没有方法,因此它默认为GET。另外,您正在使用2个POST条件。那些不行。如果您在
中添加
method=“post”
各位,这是您在good'ol Fred中看到的最后一个答案。 我将正式退出回答。它的评论只是帮助。

目前,表单没有方法,因此它默认为GET。另外,您正在使用2个POST条件。那些不行。要么你在
mysqli\u query()
中添加
method=“post”
,只需在
mysqli\u query()中添加
$con
问题:在将任何值插入数据库之前,如果($createpassword!=$confirmpassword)
,你会不会
@达伦你们俩都很了不起。在你们两位的帮助下,我已经把它安装好并重新运行了。感谢您对HTML表单的解释。我不知道。我做了所有的工作,很好。有人使用我的评论,并将其作为自己的评论。经典这是我最后的答案。我正式退休了。只需在
mysqli_query()
上添加
$con
问题:如果($createpassword!=$confirmpassword)
在向数据库中插入任何值之前,您是否会
呢?我现在正在输入答案@达伦你们俩都很了不起。在你们两位的帮助下,我已经把它安装好并重新运行了。感谢您对HTML表单的解释。我不知道。我做了所有的工作,很好。有人使用我的评论,并将其作为自己的评论。经典这是我最后的答案。我正式退休了。只需在
mysqli_query()
上添加
$con
问题:如果($createpassword!=$confirmpassword)
在向数据库中插入任何值之前,您是否会
呢?我现在正在输入答案@达伦你们俩都很了不起。在你们两位的帮助下,我已经把它安装好并重新运行了。感谢您对HTML表单的解释。我不知道。我做了所有的工作,很好。有人使用我的评论,并将其作为自己的评论。经典这是我最后的答案。我正式退休了。只需在
mysqli_query()
上添加
$con
问题:如果($createpassword!=$confirmpassword)
在向数据库中插入任何值之前,您是否会
呢?我现在正在输入答案@达伦你们俩都很了不起。我已经把它安装好并运行了一个