Avatar of Sunny Jain
Sunny Jain

asked on 

Unable to update row in PHP with $_POST variable

I want it so that when the user types into the textarea/input and clicks save changes, the information they input has been added and saved into the database. Below is my code:
$name = $_SESSION['u_name'];
$uid = $_SESSION['u_uid'];
$id = $_SESSION['u_id'];

$con = mysqli_connect("localhost", "root", "pass123", "db_name");

if ($con->connect_error) {
    die("Connection failed: " . $conn->connect_error);
	echo "<script type='text/javascript'>alert('connection failed. try again');</script>";
}

$remind1 = $_POST['remind1'];
$remind2 = $_POST['remind2'];
$remind3 = $_POST['remind3'];
$remind4 = $_POST['remind4'];
$remind5 = $_POST['remind5'];

if (isset($_POST['updBtn'])){
	$sql = "UPDATE reminders SET remindone='$remind1' WHERE username='$uid'";
	
	if ($con->query($sql) === TRUE) {
		echo "<script type='text/javascript'>alert('Updated successfully');</script>";
	}else{
		echo "<script type='text/javascript'>alert('error while updating. try again');</script>";
	}
}

Open in new window


HTML:
<form action="body.php" method="post"> 
 <input type="submit" class="sideBtn" value="Save Changes" name="updBtn"></input><br>
<div class="displayTask">
           <input type="checkbox" class="check">
           <span class="checkmark"></span>
           <input type="text" id="event" placeholder="remember..." name="remind1"></input>
</div>
<div class="displayTask">
           <input type="checkbox" class="check">
           <span class="checkmark"></span>
           <input id="event" name="remind2"></input>
</div>
<div class="displayTask">
           <input type="checkbox" class="check">
           <span class="checkmark"></span>
           <input id="event" name="remind3"></input>
</div>
           <div class="displayTask">
           <input type="checkbox" class="check">
           <span class="checkmark"></span>
           <textarea id="event" name="remind4"></textarea >
</div>
<div class="displayTask">
           <input type="checkbox" class="check">
           <span class="checkmark"></span>
            <textarea id="event" name="remind5"></textarea >
           </div>
 </div>
</form>

Open in new window


After many trials and errors, I have been able to pinpoint that my problem is somewhere along the $_POST variables in my php as, if I were to substitute the aforementioned variable with a string, it works perfectly. I am not exactly sure what I did wrong, but I feel so close that I know I must be (hopefully) getting somewhere. How can I fix this mistake of mine and make it so that the user is able to POST text into the database.
DatabasesPHPMySQL Server

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon