从表单更新我的sql数据库


update my sql database from form

嗨,我对php&slq编码。。我一直在寻找和字符串一切,以便能够更新我的php数据库。。

以下是我公平编码的内容。。这显示了论坛中我的数据库字段

   <?php
$host="localhost"; // Host name 
$username="mixfm_djs"; // Mysql username 
$password="0121do1"; // Mysql password 
$db_name="mixfm_djs"; // Database name 
$tbl_name="table1"; // Table name 
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>
<form id="form1" name="form1" method="post" action="index.php">
  <table width="400" border="0" cellspacing="1" cellpadding="0">
    <tr>
      <td><form name="form1" method="post" action="update_ac.php"></td>
    </tr>
    <tr>
      <td><table width="400" border="1" cellspacing="0" cellpadding="3">
        <tr>
          <td colspan="4"><strong>List data from mysql </strong></td>
        </tr>
        <tr>
          <td align="center"><strong>DJ-Name</strong></td>
          <td align="center"><strong>Password</strong></td>
          <td align="center"><strong>State</strong></td>
          <td align="center">&nbsp;</td>
        </tr>
        <?php
while($rows=mysql_fetch_array($result)){
?>
        <tr>
          <td><input name="djname" type="text" id="djname" value="<? echo $rows['djname']; ?>" /></td>
          <td><input name="name" type="text" id="name" value="<? echo $rows['name']; ?>" size="15" /></td>
          <td><input name="state" type="text" id="state" value="<? echo $rows['state']; ?>" size="15" /></td>
          <td align="center">&nbsp;</td>
        </tr>
        <?php
}
?>
      </table></td>
    </tr>
  </table>
  <p>
    <input type="submit" name="update" id="update" value="update" />
  </p>
  <?php
mysql_close();
?>
</form>

希望有人能帮助

感谢

如注释所述,如果您真的致力于mysql,那么您应该使用mysqli。这里有一个关于使用mysqli的小介绍。

http://codular.com/php-mysqli

其次,您需要一个update语句来实际"更新"您的mysql数据库。下面是一个关于使用mysqli扩展进行更新的教程。

http://www.pontikis.net/blog/how-to-use-php-improved-mysqli-extension-and-why-you-should

这里的很多人会告诉你使用mysqli或pdo来处理这里的数据库内容,因为mysql_query会让你的数据库因一些严重的安全缺陷而打开,并使你的代码的可维护性大大降低。

既然你才刚刚开始,你肯定应该更多地了解mysqli、pdo和预先准备好的语句,因为一旦你习惯了使用某些工具,以后就很难改掉坏习惯。