dpizd08264 2013-05-10 22:11
浏览 49
已采纳

无法使用php更新mysql数据库

I am trying to update a record on my customer mysql table. However I get the following errors:

Notice: Undefined index: username in E:\EasyPHP-12.1\www\Register1.php on line 313

Notice: Undefined variable: db_password in E:\EasyPHP-12.1\www\Register1.php on line 315 error updating record

I can't see anything wrong with my code. And have been looking at it for a few hours with no luck.

<div class="footer">
  <img src="images/gardening5.jpg" alt="Image">
  <div>
    <h1>Tips of the Week</h1>
    <form method= "get">
      <form method="get">
      <p>Username:
        <input name="username" type="text">
        </p>
      </form>
      <p>
      <form method="get">
        <p>Password:
          <input name="password" type="password">
        </p>
        <p>First Name:
          <input name="first name" type="first name">
        </p>
        <p>Last Name:
           <input name="last name" type="last name">
        </p>
        <p>1st Line of Address:
          <input name="1st line of address" type="1st line of address">
        </p>
        <p>2nd Line of Address:
          <input name="2nd line of address" type"2nd line of address">
        </p>
        <p>Town:
           <input name="town" type"town">
        </p>
        <p>PostCode:
          <input name="postcode" type="postcode">
        </p>
        <p>Phone Number
          <input name="phone_number" type="phone_number">
        </p>
        <p>
          <input name="submit3" type="submit" value="update customer record">
        </p>
       </form>
     </form>
<?php
  $host="localhost"; // Host name
  $tbl_name="customer"; // Table name
  $db_user="root";
  $db_pass="";

  $connect = mysql_connect("$host", "$db_user", "$db_pass");
  $db_name="the_shop"; // Database name
  mysql_select_db("$db_name");

  if(isset($_GET['submit3'])){

    $db_username = $_GET['username'];

    $sql3 = "UPDATE `customer` SET `Password`='.$db_password.' WHERE `Username`='.$db_username.";
    $result3 = mysql_query($sql3);

    mysql_query($sql3) or die('error updating record');
    echo $sql3;
  }
?>
  • 写回答

3条回答 默认 最新

  • doukongyong44772 2013-05-10 22:16
    关注

    There are several problems with your code:

    You're not getting username parameter with GET method. html markup should be corrected to properly define one form instead of having several.

    You don't have $db_password variable defined. It's probably meant to be

    $db_password = $_GET['password'];
    

    There is invalid concatenation in $sql3.Therefore change

    $sql3 = "UPDATE `customer` SET `Password`='.$db_password.' WHERE `Username`='.$db_username.";
    

    to

    $sql3 = "UPDATE `customer` SET `Password`='$db_password' WHERE `Username`='$db_username'";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 目标计数模型训练过程中的问题
  • ¥100 Acess连接SQL 数据库后 不能用中文筛选
  • ¥15 用友U9Cloud的webapi
  • ¥20 电脑拓展屏桌面被莫名遮挡
  • ¥20 ensp,用局域网解决
  • ¥15 Python语言实验
  • ¥15 我每周要在投影仪优酷上自动连续播放112场电影,我每一周遥控操作一次投影仪,并使得电影永远不重复播放,请问怎样操作好呢?有那么多电影看吗?
  • ¥20 电脑重启停留在grub界面,引导出错需修复
  • ¥15 matlab透明图叠加
  • ¥50 基于stm32l4系列 使用blunrg-ms的ble gatt 创建 hid 服务失败