duan97689 2017-11-17 09:56
浏览 34
已采纳

从数据库中获取数据并且更新无效

i have this code for the user-edit.php what i need with this code is to fetch user data from database and show it to the textbox and also the user able to edit the textbox value and updating the database

<?php
    include("config/session.php");
    include("config/connection.php");
    $user_id =  $_SESSION['LOGGED_USER_ID']; 
?>

<?php 
    $sql_query = "SELECT * FROM table_users WHERE `SNo` = '$user_id'"; 
    $query = mysql_query($sql_query);
    //$i = 1;
    $fetch = mysql_fetch_assoc($query);

    //$user_id = $_GET['id'];   

?>      
<form name="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" >
    <fieldset>

        <p>
            <label for="simple-input" >User Name</label>
            <input type="text" id="UserName" class="round default-width-input" autofocus name="UserName" value="<?php echo $fetch['UserName'];?>" readonly="readonly" />
        </p>
        <p>
            <label for="simple-input" >Password</label>
            <input type="text" id="pass_word" class="round default-width-input" autofocus name="pass_word" value="<?php echo $fetch['pass_word'];?>" />
        </p>
        <p>
            <label for="simple-input" >Email ID</label>
            <input type="text" id="Email" class="round default-width-input" autofocus name="Email" value="<?php echo $fetch['Email'];?>" />

        </p>
        <p>
            <label for="simple-input" >Website</label>
            <input type="text" id="website" class="round default-width-input" autofocus name="website" value="<?php echo $fetch['website'];?>" />
        </p>


    </fieldset>

    <input type="submit" class="btn btn-primary btn-large" name="form_submit" value="Update Data"/> 

</form>

<?php

if(isset($_POST['form_submit']))
{
    "UPDATE `table_users` SET `pass_word` =  '".$_POST['pass_word']."',`Email` =  '".$_POST['Email']."',`website` =  '".$_POST['website']."', WHERE `SNo` = '$user_id'";

    // sql query for update data into database
    if(mysql_query($sql_query))
     {

      echo '<script type="text/javascript">';
      echo 'alert("Data Are Updated Successfully");';
      echo '</script>';

     }
     else
     {

      echo '<script type="text/javascript">';
      echo 'alert("error occured while updating data");';
      echo '</script>';
    }
    }
?>

        </div>
    </div>                          
</div>

been working with this for hours and still the data are not updated to the mysql database, been trying several way but still the textbox value cant update the database, please help

  • 写回答

1条回答 默认 最新

  • doudou1897 2017-11-17 10:02
    关注

    remove , before where in query

    $sql_query="UPDATE `table_users` SET `pass_word` =  '".$_POST['pass_word']."',`Email` =  '".$_POST['Email']."',`website` =  '".$_POST['website']."' WHERE `SNo` = '$user_id'";
    

    store query in $sql_query because you not store update string into variable without store in $sql_query you run sql query

    if(mysql_query($sql_query)) so store update query in $sql_query

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路