user3323092
user3323092

Reputation:

can not update record while edit

hi i am begginer in php i am create list of records after that if user want to update record than i am redirect user on another page update form is like this when i am redirect on this form i am getting id but when i am submit this form i am not getting in in my update query what is wrong in form logic

<?php include 'header.php'; ?>
<?php 
include 'sidebar.php';  

$settings_id = isset($_REQUEST['settings_id']) ? $_REQUEST['settings_id'] : 0;

$selectdata = "SELECT * FROM settings 
                 WHERE settings_id = ".$_REQUEST['settings_id'];
$res = mysql_query($selectdata);
if($row = mysql_fetch_array($res))
{
 $settings_id = $row['settings_id'];
 $value       = $row['settings_value'];
}

if(isset($_REQUEST['submit']))
{
  $ph          = isset($_REQUEST['phone_no']) ? $_REQUEST['phone_no'] : '';
  $settings_id = isset($_REQUEST['settings_id']) ? $_REQUEST['settings_id'] : '';

  echo $update = "UPDATE settings
               SET settings_value = '".$ph."'
            WHERE settings_id = ".$_REQUEST['settings_id'];

  $updateRes = mysql_query($update);
  if(!$updateRes)
  {
    echo "Update Fail";
  }
  else
  {
    header("Location:settingsedit.php?settings_id=".$_REQUEST['settings_id']);
  }
} 

?>

<head>
  <script src="dist/js/sweetalert.min.js"></script>
  <link rel="stylesheet" type="text/css" href="dist/css/sweetalert.css">
</head>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
  <!-- Content Header (Page header) -->
  <section class="content-header">
    <h1>
      Settings
      <small>Settings</small>
    </h1>
    <ol class="breadcrumb">
      <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
      <li class="active">Change Password</li>
    </ol>
  </section>
  <!-- Main content -->
  <section class="content">
    <!-- Default box -->
    <div class="box">
        <div class="box box-primary">
          <!-- form start -->
          <form role="form" action="settingsedit.php" method="POST">
            <div class="box-body">
              <div class="form-group">
                <label for="exampleInputEmail1">Phone Number</label>
                <input type="text" class="form-control" id="exampleInputEmail1" name="phone_no" value="<?php echo $value; ?>">
              </div>
                <div class="box-footer">
                <button type="submit" name="submit" class="btn btn-primary">Update</button>
            </div>
          </form>
    </div><!-- /.box-body -->
  </section><!-- /.content -->
</div><!-- /.content-wrapper -->

<?php include 'footer.php'; 

Upvotes: 2

Views: 40

Answers (2)

zaman
zaman

Reputation: 145

Please set your id in input hidden field in this form and get id form request like as

<input type="hidden" value="<? echo $id; ?>" name="settings_id"/>  

Upvotes: 1

venca
venca

Reputation: 1222

How does your form look like? You should use prepared statements to prevent SQL injection.

Upvotes: 0

Related Questions