michael
michael

Reputation: 23

Fetch data from database and update is not working

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

Upvotes: 0

Views: 801

Answers (1)

Bhargav Chudasama
Bhargav Chudasama

Reputation: 7161

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

Upvotes: 1

Related Questions