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

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题