Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.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将配置文件从HTML表单更新为MySQL_Php_Html_Mysql - Fatal编程技术网

尝试使用PHP将配置文件从HTML表单更新为MySQL

尝试使用PHP将配置文件从HTML表单更新为MySQL,php,html,mysql,Php,Html,Mysql,我整天都在做这件事,有种感觉可能很简单。 我试图给我的用户一个选项来更新他们的用户配置文件中的一些条目,而不必每次都填写所有内容 我将在下面发布我的代码,但基本上我现在没有收到任何回复 我的HTML格式如下 <table width="500" border="0" cellpadding="3" cellspacing="1"> <tr> <form method="post" action="edit.php">

我整天都在做这件事,有种感觉可能很简单。 我试图给我的用户一个选项来更新他们的用户配置文件中的一些条目,而不必每次都填写所有内容

我将在下面发布我的代码,但基本上我现在没有收到任何回复

我的HTML格式如下

<table width="500" border="0" cellpadding="3" cellspacing="1">
    <tr>
        <form method="post" action="edit.php">
            <div data-role="fieldcontain">
                <td width="200">Name:</td>
                <td width="450"><input type="text" name="inputName" value="" /> </td>
    </tr>
    <tr>
        <td width="200">Password:</td>
        <td width="450"><input type="password" name="inputPassword" value="" /></td>
    </tr>
    <tr>
        <td width="200">Date of Birth:</td>
        <td width="450"><input type="date" name="inputDOB" value="" /></td>
    </tr>
    <tr>
        <td width="200">Core Competencies:</td>
        <td width="450">
            <input type="checkbox" name="coreComp[]" value="Honesty" />Honesty<br />
            <input type="checkbox" name="coreComp[]" value="Loyalty" />Loyalty<br />
            <input type="checkbox" name="coreComp[]" value="Trust" />Trust<br />
            <input type="checkbox" name="coreComp[]" value="Empathy" />Empathy<br />
            <input type="checkbox" name="coreComp[]" value="Respect" />Respect</td>
    </tr>
    <tr>
        <td colspan="2">
            <button data-theme="b" id="submit" type="submit">Submit</button>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <h3 id="notification"></h3>
        </td>
        </div>
        </form>
    </tr>
</table>

姓名:
密码:
出生日期:
核心能力:
诚实
忠诚
信任
移情
尊重 提交
我的PHP现在看起来是这样的

<?php

session_start();
include 'includes/Connect.php';

$name = $_POST['inputName'];
$password = $_POST['inputPassword'];
$dob = $_POST['inputDOB'];
$aCC = implode( ',' , $_POST['coreComp'] );

$encrypt_password=md5($password);
$username=$_SESSION['myusername'];

if(!empty($name))
{
    mysql_query("UPDATE Profile SET `Name`='$name' WHERE Username='$username'" or die(mysql_error());
                echo("You have successfully updated your Name");
}
if(!empty($password))
{
    mysql_query("UPDATE Profile SET Password='$encrypt_password' WHERE Username='$username'" or die(mysql_error());
                echo("You have successfully updated your Password");
}
if(!empty($dob))
{
    mysql_query("UPDATE Profile SET DOB='$dob' WHERE Username='$username'" or die(mysql_error());
                echo("You have successfully updated your Date of Birth");
}
if(!empty($aCC))
{
    mysql_query("UPDATE Profile SET CC='$aCC' WHERE Username='$username'" or die(mysql_error());
                echo("You have successfully updated your Core Values");
}

   mysql_close(); 

?>

您有一系列语法错误。这是不正确的,因为它缺少一个

您需要关闭查询字符串后面的括号(
),但在
或die…
之前:

mysql_query("UPDATE Profile SET `Name`='$name' WHERE Username='$username'") or die(mysql_error());
更正代码:

if(!empty($name))
{
    mysql_query("UPDATE Profile SET `Name`='$name' WHERE Username='$username'") or die(mysql_error());
                echo("You have successfully updated your Name");
}
if(!empty($password))
{
    mysql_query("UPDATE Profile SET Password='$encrypt_password' WHERE Username='$username'") or die(mysql_error());
                echo("You have successfully updated your Password");
}
if(!empty($dob))
{
    mysql_query("UPDATE Profile SET DOB='$dob' WHERE Username='$username'") or die(mysql_error());
                echo("You have successfully updated your Date of Birth");
}
if(!empty($aCC))
{
    mysql_query("UPDATE Profile SET CC='$aCC' WHERE Username='$username'") or die(mysql_error());
                echo("You have successfully updated your Core Values");
}

另外,正如我在上面的评论中指出的,mysql_*函数已被弃用,并且您对SQL注入非常开放。您需要使用MySQLi或PDO并使用准备好的语句。您的HTML也有各种各样的问题,比如div和表单从一个tr开始,在另一个tr结束。这不是代码失败的原因,但我强烈建议清理代码

我假设
Connect.php
有您的数据库信息。确保密码正确无误,
MD5
不再是一个好选择。在这里阅读是的Connect.php拥有所有连接信息并且正在工作。定义“我现在没有得到响应”mysql_*函数已被弃用,并且您对SQL注入非常开放。您需要使用MySQLi或PDO并使用准备好的语句。此外,HTML有各种各样的问题,比如
div
表单
,它们在一个
tr
中开始,在另一个
中结束。这并不是你的代码失败的原因,但我强烈建议清理你的代码。谢谢你,Ed。我知道这很简单,但我看了太久,没有注意到。谢谢你的建议。我会把这一切都解决的。
if(!empty($name))
{
    mysql_query("UPDATE Profile SET `Name`='$name' WHERE Username='$username'") or die(mysql_error());
                echo("You have successfully updated your Name");
}
if(!empty($password))
{
    mysql_query("UPDATE Profile SET Password='$encrypt_password' WHERE Username='$username'") or die(mysql_error());
                echo("You have successfully updated your Password");
}
if(!empty($dob))
{
    mysql_query("UPDATE Profile SET DOB='$dob' WHERE Username='$username'") or die(mysql_error());
                echo("You have successfully updated your Date of Birth");
}
if(!empty($aCC))
{
    mysql_query("UPDATE Profile SET CC='$aCC' WHERE Username='$username'") or die(mysql_error());
                echo("You have successfully updated your Core Values");
}