troubleshooting Question

Unable to update row in PHP with $_POST variable

Avatar of Sunny Jain
Sunny Jain asked on
DatabasesPHPMySQL Server
3 Comments1 Solution152 ViewsLast Modified:
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>";
	}
}

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>

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.
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros