+ 3

What's wrong with this code?

trying to update data<?php include("connect.php"); include("functions.php"); if(logged_in()) { ?> <a href="changepassword.php">Change Password</a> <a href="logout.php" style="float:right; padding:10px; margin-right:40px; background-color:#eee; color:#333; text-decoration:none;">Logout</a> <?php } else { header("location:login.php"); exit(); } $amount = ""; $id=""; $error=""; if(isset($_POST['submit'])) { $userid = $_POST['id']; $amount = $_POST['amount']; $verify = mysqli_query($con,"SELECT amount FROM users WHERE id = '$id'"); $row=mysqli_num_rows($verify); if ($row <= 0) { $error = "invalid username or password!"; }else{ $sql = "UPDATE users SET amount='.$amount.' WHERE id='$id'"; mysqli_query($con,$sql); } } ?> This is form code <div id="formDiv"> <form method="POST" action="profile.php" enctype="multipart/form-data"> <label>ID:</label><br/> <input type="text" name="id" class="inputFields" required/><br/><br/> <label>Amount</label><br/> <input type="text" name="amount" class="inputFields" required/><br/><br/> <input type="submit" class="theButtons" name="submit"/> </form>

7th Oct 2017, 8:42 AM
Shubham Bauskar
Shubham Bauskar - avatar
2 Answers
+ 1
Also, syntax error. The right syntax is: else { $sql ="UPDATE users SET amount = '" . $amount . "' WHERE id = '" . $id . "'"; //Blocks of code }
7th Oct 2017, 8:58 AM
Freezemage
Freezemage - avatar
0
Headers must be ALWAYS before any other page content. Rebuild the if-else condition. Also, does your 'logged_in()' function return bool datatype?
7th Oct 2017, 8:53 AM
Freezemage
Freezemage - avatar