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

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

报告相同问题?

悬赏问题

  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘