Updating data in PHP - php

I am using editing file for updating data of mobile no, email details etc, but it is not updating , it shows the results of data so connection is working but no updating of data is there. code:
<?php
include('header.php');
$msg='';
?>
<div class="page-cont1">
<!--heading starts-->
<?php
session_start(); //starts the session
if($_SESSION['user']){ //checks if user is logged in
}
else{
header("location:index.php"); // redirects if user is not logged in
}
$user = $_SESSION['user']; //assigns user value
$id_exists = false;
?>
<body>
<h2>Home Page</h2>
<p>Hello <?php Print "$user"?>!</p> <!--Displays user's name-->
Click here to logout<br/><br/>
Return to Home page
<h2 align="center">Currently Selected</h2>
<table border="1px" width="100%">
<tr>
<th>Id</th>
<th>E-Mail</th>
<th>Mobile No</th>
<th>Details</th>
<th>Extra Information</th>
</tr>
<?php
if(!empty($_GET['id']))
{
$id = $_GET['id'];
$_SESSION['id'] = $id;
$id_exists = true;
$query = mysql_query("Select * from doctor Where id='$id'"); // SQL Query
$count = mysql_num_rows($query);
if($count > 0)
{
while($row = mysql_fetch_array($query))
{
Print "<tr>";
Print '<td align="center">'. $row['id'] . "</td>";
Print '<td align="center">'. $row['your_email'] . "</td>";
Print '<td align="center">'. $row['mobile_no'] . "</td>";
Print '<td align="center">'. $row['detail'] . "</td>";
Print '<td align="center">'. $row['info'] . "</td>";
Print "</tr>";
}
}
else
{
$id_exists = false;
}
}
?>
</table>
<br/>
<?php
if($id_exists)
{
Print '
<form action="edit.php" method="POST">
Enter new E-Mail: <input type="text" name="your_email"/><br/>
Enter new Mobile: <input type="text" name="mobile_no"/><br/>
Enter new detail: <input type="text" name="detail"/><br/>
Enter new Extra Information: <input type="text" name="info"/><br/>
<input type="submit" value="Update List"/>
</form>
';
}
else
{
Print '<h2 align="center">There is no data to be edited.</h2>';
}
?>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$field_email = mysql_real_escape_string($_POST['your_email']);
$field_phone = mysql_real_escape_string($_POST['mobile_no']);
$detail = mysql_real_escape_string($_POST['detail']);
$field_message = mysql_real_escape_string($_POST['info']);
mysql_query("UPDATE doctor SET your_email='$field_email', mobile_no='$field_phone', detail='$detail', info='$field_message' WHERE id='$id'") ;
header("location: home.php");
}
?>
<?php
include('footer.php');
$msg='';
?>
</body>
More over header file includes the connect file, and one query form is there problem lie in header file or problem in edit file.

First replace DOCTOR with doctor in update query (as Utharsh has stated).
Second:
You'll have to include the id in your form to be posted.
Print '<form action="edit.php" method="POST">
Enter new E-Mail: <input type="text" name="your_email"/><br/>
Enter new Mobile: <input type="text" name="mobile_no"/><br/>
Enter new detail: <input type="text" name="detail"/><br/>
Enter new Extra Information: <input type="text" name="info"/><br/>
<input type="hidden" name="id" value="'.$id.'">
<input type="submit" value="Update List"/>
</form>';

replace DOCTOR withdoctor in your update query.
If problem persists than try to hard code your query and execute it in phpmyadmin.
put a hidden field in your form with reference to the id as jeff stated

After receiving ans i studied my code in the ans i read about ID so i noticed that in updating there is no ID reference so i changed my code now problem solved my working code is:
<?php
include('header.php');
$msg='';
?>
<div class="page-cont1">
<!--heading starts-->
<?php
session_start(); //starts the session
if($_SESSION['user']){ //checks if user is logged in
}
else{
header("location:index.php"); // redirects if user is not logged in
}
$user = $_SESSION['user']; //assigns user value
$id_exists = false;
?>
<body>
<h2>Home Page</h2>
<p>Hello <?php Print "$user"?>!</p> <!--Displays user's name-->
Click here to logout<br/><br/>
Return to Home page
<h2 align="center">Currently Selected</h2>
<table border="1px" width="100%">
<tr>
<th>Id</th>
<th>E-Mail</th>
<th>Mobile No</th>
<th>Details</th>
<th>Extra Information</th>
</tr>
<?php
if(!empty($_GET['id']))
{
$id = $_GET['id'];
$_SESSION['id'] = $id;
$id_exists = true;
$query = mysql_query("Select * from doctor Where id='$id'"); // SQL Query
$count = mysql_num_rows($query);
if($count > 0)
{
while($row = mysql_fetch_array($query))
{
Print "<tr>";
Print '<td align="center">'. $row['id'] . "</td>";
Print '<td align="center">'. $row['your_email'] . "</td>";
Print '<td align="center">'. $row['mobile_no'] . "</td>";
Print '<td align="center">'. $row['detail'] . "</td>";
Print '<td align="center">'. $row['info'] . "</td>";
Print "</tr>";
}
}
else
{
$id_exists = false;
}
}
?>
</table>
<br/>
<?php
if($id_exists)
{
Print '
<form action="edit.php" method="POST">
Enter new E-Mail: <input type="text" name="your_email"/><br/><br/>
Enter new Mobile: <input type="text" name="mobile_no"/><br/><br/>
Enter new detail: <textarea name="detail" rows="6" id="detail" style="width:200px;"></textarea><br/><br/>
Enter new Extra Information: <textarea name="info" rows="4" id="info" style="width:200px;"></textarea><br/><br/>
<input type="hidden" name="id" value="'.$id.'">
<input type="submit" value="Update List"/>
</form>
';
}
else
{
Print '<h2 align="center">There is no data to be edited.</h2>';
}
?>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$field_email = mysql_real_escape_string($_POST['your_email']);
$field_phone = mysql_real_escape_string($_POST['mobile_no']);
$detail = mysql_real_escape_string($_POST['detail']);
$field_message = mysql_real_escape_string($_POST['info']);
$id = $_SESSION['id'];
mysql_query("UPDATE doctor SET your_email='$field_email', mobile_no='$field_phone', detail='$detail', info='$field_message' WHERE id='$id'") ;
header("location: home.php");
}
?>
<?php
include('footer.php');
$msg='';
?>
</body>

Related

Update query not functioning

I'm trying to develop a small "To Do List" application. The data for the app is stored in a database, and it needs to perform all CRUD operations. As it is right now, Select, Insert, and Delete work just fine. I'm stuck on updating though. The index.php page is shown below:
<?php
session_start();
require_once 'connect.php';
if (isset($_POST['DeleteTask'])) {
$sqldelete = "DELETE FROM Tasks WHERE dbTaskID = :bvTaskID";
$stmtdelete = $db->prepare($sqldelete);
$stmtdelete->bindValue(':bvTaskID', $_POST['taskID']);
$stmtdelete->execute();
echo "<div>Task successfully deleted</div>";
}
if (isset($_POST['theSubmit'])){
echo '<p>New task added</p>';
$formfield['ffTaskName'] = trim($_POST['taskName']);
$formfield['ffTaskDue'] = trim($_POST['taskDue']);
if(empty($formfield['ffTaskName'])){$errormsg .= "<p>Task field is empty.</p>";}
if(empty($formfield['ffTaskDue'])){$errormsg .= "<p>Deadline field is empty.</p>";}
if ($errormsg != "") {
echo "<div class='error'><p>Please fill out all fields before submitting.</p>";
echo $errormsg;
echo "</div>";
} else {
try {
$sqlinsert = 'INSERT INTO Tasks (dbTaskName, dbTaskDue, dbTaskDone)
VALUES (:bvTaskName, :bvTaskDue, :bvTaskDone)';
$stmtinsert = $db->prepare($sqlinsert);
$stmtinsert->bindValue(':bvTaskName', $formfield['ffTaskName']);
$stmtinsert->bindValue(':bvTaskDue', $formfield['ffTaskDue']);
$stmtinsert->bindValue(':bvTaskDone', 0);
$stmtinsert->execute();
echo "<div><p>There are no errors. Thank you.</p></div>";
} catch(PDOException $e){
echo 'ERROR!!!' .$e->getMessage();
exit();
}
}
}
$sqlselect = "SELECT * from Tasks";
$result = $db->prepare($sqlselect);
$result->execute();
?>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>To Do Application</title>
</head>
<body>
<h1><u>To-Do List</u></h1>
<table border>
<tr>
<th>Task</th>
<th>Deadline</th>
<th>Status</th>
<th>Complete</th>
<th>Edit</th>
<th>Delete</th>
</tr>
<?php
while ($row = $result->fetch()) {
if ($row['dbTaskDone'] == 0) {
$status = "Unfinished";
} else {
$status = "Finished";
}
echo '<tr><td>' . $row['dbTaskName']
. '</td><td>' . $row['dbTaskDue']
. '</td><td>' . $status;
/*if ($status == "Unfinished"){
echo '</td><td>';
echo '<form action="'. $_SERVER['PHP_SELF'] . '" method="post">';
echo '<input type="hidden" name="taskID" value"' . $row['dbTaskID'] . '">';
echo '<input type="submit" name="CompleteTask" value="Complete Task">';
echo '</form>';
}*/
echo '</td><td>';
echo '<form action="updateTask.php" method="post">';
echo '<input type="hidden" name="taskID" value="' . $row['dbTaskID'] . '">';
echo '<input type="submit" name="EditTask" id="EditTask" value="Edit Task">';
echo '</form></td><td>';
echo '<form action="'. $_SERVER['PHP_SELF'] . '" method="post">';
echo '<input type="hidden" name="taskID" value="' . $row['dbTaskID'] . '">';
echo '<input type="submit" name="DeleteTask" value="Delete Task">';
echo '</td></tr>';
}
?>
</table>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="toDoForm">
<fieldset><legend>New Task</legend>
<table>
<tr>
<th>Task</th>
<td><input type="text" name="taskName" id="taskName"
value="<?php echo $formfield['ffTaskName']; ?>"></td>
</tr><tr>
<th>Deadline</th>
<td><input type="text" name="taskDue" id="taskDue"
value="<?php echo $formfield['ffTaskDue']; ?>"></td>
</tr>
</table>
<input type="submit" name = "theSubmit" value="Add Task">
</fieldset>
</form>
</body>
</html>
Each record displays an "Edit" button that grabs the PK from the "Tasks" table and sends it to the updateTask.php page:
<?php
require_once 'connect.php';
$errormsg = "";
if (isset($_POST['EditTask']) ) {
$formfield['ffTaskID'] = $_POST['taskID'];
$sqlselect = "SELECT * FROM Tasks WHERE dbTaskId = :bvTaskID";
$result = $db->prepare($sqlselect);
$result->bindValue(':bvTaskID', $formfield['ffTaskID']);
$result->execute();
$row = $result->fetch();
if( isset($_POST['theEdit']) )
{
$formfield['ffTaskID'] = $_POST['taskID'];
$formfield['ffTaskName'] = trim($_POST['taskName']);
$formfield['ffTaskDue'] = trim($_POST['taskDue']);
if(empty($formfield['ffTaskName'])){$errormsg .= "<p>Task field is empty.</p>";}
if(empty($formfield['ffTaskDue'])){$errormsg .= "<p>Deadline field is empty.</p>";}
if ($errormsg != "") {
echo "<div class='error'><p>Please fill out all fields before submitting.</p>";
echo $errormsg;
echo "</div>";
} else {
try
{
$sqlUpdate = "UPDATE Tasks SET dbTaskName = :bvTaskName,
dbTaskDue = :bvTaskDue
WHERE dbTaskID = :bvTaskID";
$stmtUpdate = $db->prepare($sqlUpdate);
$stmtUpdate->bindvalue(':bvTaskName', $formfield['ffTaskName']);
$stmtUpdate->bindvalue(':bvTaskDue', $formfield['ffTaskDue']);
$stmtUpdate->bindvalue(':bvTaskID', $formfield['ffTaskID']);
$stmtUpdate->execute();
}
catch(PDOException $e)
{
echo 'ERROR!!!' .$e->getMessage();
exit();
}
}
}
}
?>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>To Do Application</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="editForm">
<fieldset><legend>Edit Task</legend>
<table>
<tr>
<th>Task</th>
<td><input type="text" name="taskName" id="taskName"
value="<?php echo $row['dbTaskName'];?>" ></td>
</tr><tr>
<th>Deadline</th>
<td><input type="text" name="taskDue" id="taskDue"
value="<?php echo $row['dbTaskDue']; ?>"></td>
</tr>
<tr>
<th>Submit Changes</th>
<input type="hidden" name="taskID" value="<?php echo $_formfield['ffTaskID']; ?>">
<td><input type="submit" name="theEdit" value="Submit Changes">
</table>
</fieldset>
</form>
</body>
</html>
The Name and Deadline fields populate appropriately based on the PK value passed from the last page. However, whenever I press the "Submit Changes" button, the update doesn't seem to execute. The page just refreshes and I see the table data remains unchanged in the database.
Solved the problem!
There were several issues that I discovered.
1.) In updateTask.php, I had the second if-statement nested within the first one. So it was running the update query as the page loaded, with no change to the data. So the 'theEdit' button did nothing since since it required the previous if statement's condition to run.
2.) The formfield 'ffTaskID' at the bottom of the form on updateTask.php to be passed on the 'theEdit' button press was typed incorrectly.
$_formfield
..should have been..
$formfield
At this point, the update query functions properly.
3.) The issue with the 'Edit' buttons has been fixed. Though I honestly can't say for certain how it was fixed. It may have been linked with the first part of the problem. So when that was fixed, so was this.
Either way, all seems to be functioning as it should. Thanks again to everyone who commented and helped.

send current date only if box is checked

I have a crud system in PHP and creating an approval section. I've create an approval page for the products which works great if the box is checked. But if its not and the person puts in the form, the date is still inputed. How can I have it only input the date if the box is checked?
Here is the form...
// if the form was submitted
if($_POST){
$product->reviewed = $_POST['reviewed'];
$product->review_date = $_POST['review_date'];
// set product property values
// update the product
if($product->approve()){
echo "<div class='alert alert-success alert-dismissable'>";
echo "Product approvals were set.";
echo "</div>";
}
// if unable to update the product, tell the user
else{
echo "<div class='alert alert-danger alert-dismissable'>";
echo "Unable to approve product.";
echo "</div>";
}
}
?>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"] . "?id={$id}");?>" method="post">
<table class='table table-hover table-responsive table-bordered'>
<tr>
<td>Name</td>
<td><?php echo $product->name; ?></td>
</tr>
<tr>
<td>Review</td>
<td><?php
if (is_null($product->reviewed)){
?>
<div id="ck-button"><label><input type="checkbox" name="reviewed" value="<?php echo $userRow['user_name'];?>" id="checkbox"/><span>Approve</span>
<input type='hidden' name='review_date' class='form-control' value="<?php echo date("Y-m-d h:i:sa"); ?>"/>
</div> </label>
<?php ;
}elseif (isset($product->reviewed)){
echo "<div id='approved-button'>" . $product->reviewed . ", " . $product->review_date . "</div>";
}
?>
</td>
</tr>
<tr>
<td></td>
<td>
<button type="submit" class="btn btn-primary">Set Approvals</button>
</td>
</tr>
</table>
</form>
Here is the function in the Product class
//approval for products
function approve(){
$query = "UPDATE
" . $this->table_name . "
SET
reviewed = :reviewed,
review_date = :review_date
WHERE
id = :id";
$stmt = $this->conn->prepare($query);
$this->id=htmlspecialchars(strip_tags($this->id));
$this->reviewed=htmlspecialchars(strip_tags($this->reviewed));
$this->review_date=htmlspecialchars(strip_tags($this->review_date));
$stmt->bindParam(':id', $this->id);
$stmt->bindParam(":reviewed", $this->reviewed);
$stmt->bindParam(":review_date", $this->review_date);
// execute the query
if($stmt->execute()){
return true;
}
return false;
}
To check if a checkbox element has been 'checked' in PHP you do the following:
if(isset($_POST['myCheckbox'])) { ... }
Instead, you have
if($_POST) { ... }
Which is what your problem seems to be if I am understanding your question correctly.

PHP redirect to page on form submit based on select

I am trying to get PHP to read my select options as variables and then echo out a particular page based on the users choice.
The login system is functional but only logs me into one page.
<form action="login.php" method="POST">
<table cellspacing="10">
<tr>
<td>Email: </td>
<td><input type='text' name='email'/></td>
</tr>
<tr>
<td>Password: </td>
<td><input type='password' name='password'/></td>
</tr>
<tr>
<td>Event: </td>
<td>
<select name="event">
<option><?php echo $title?></option>
<option><?php echo $title2?></option>
</select>
</td>
</tr>
</table>
<br />
<button class="button" type='submit' name='Submit' value='Submit' />Login</button>
</form>
<?php
if (!empty($email) && !empty($password)) {
$pdo = getPdo();
$statement = $pdo->prepare('SELECT * FROM awdawda WHERE email=:email;');
$statement->bindParam(':email', $email);
$statement->execute();
$data = $statement->fetch();
$pdo = null;
if (!empty($data)) {
$dbemail = $data['email'];
$dbpassword = $data['password'];
$dbfullname = $data['fullname'];
if ($password == $dbpassword) {
$_SESSION['fullname'] = $dbfullname;
$_SESSION['email'] = $email;
$_SESSION['password'] = $password;
if ($_POST['event']) {
$event1=$title;
echo '<script type="text/javascript">window.location = "http://awda/adwa/awd1.php" </script>';
}
if ($_POST['event']) {
$event2=$title2;
echo '<script type="text/javascript">window.location = "http://awdaw/awda/adwa.php" </script>';
}
}
echo '<div style="padding: 10px;">Login Failed: Password Incorrect</div>';
}
echo '<div style="padding: 10px;">User not found</div>';
}
?>
That is the code I am using to login with. I left out what was above it since it all works fine right now.
You have to give value to the options of your select tag
<select name="event">
<option value="value1"><?php echo $title?></option>
<option value="value2"><?php echo $title2?></option>
</select>
and have to update your php logic according to these value
if ($_POST['event'] == "value1") {
$event1=$title;
echo '<script type="text/javascript">window.location = "http://awda/adwa/awd1.php" </script>';
}
if ($_POST['event'] == "value2") {
$event2=$title2;
echo '<script type="text/javascript">window.location = "http://awdaw/awda/adwa.php" </script>';
}

Session variable passed dynamically to the next page

This code here is working perfectly well. All i want to do is to pass the FirstName and LastName (using SESSION) which is already stored in the $userName. The first and last name is actually retrieved from the database when trying to login.
I want to have the First and Last Name show on every page once logged in.. Thanks
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><?php
$DisplayForm = TRUE;
$errors = 0;
if(isset($_POST['uname']) && isset($_POST['pass'])) {
include("dbconnect.php");
if($DBConnect !== FALSE){
$SQLstring = "SELECT userid, first_name, last_name FROM users WHERE username ='".
$_POST['uname']. "' and password = '".md5($_POST['pass'])."'";
$DisplayForm = FALSE;
$QueryResult = #mysql_query($SQLstring, $DBConnect);
echo mysql_error();
if (mysql_num_rows($QueryResult)=== 0){
echo "<p style='color:red;'><b> The email address/password " .
" combination is not valid.</b></p>\n";
++$errors;
$DisplayForm = TRUE;
}
else
{
$DisplayForm = FALSE;
}
}
}
if ($DisplayForm)
{?>
<form id="form1" name="loginForm" method="post" action="index.php">
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="93" bgcolor="#DACFAF"><strong> Username:</strong></td>
<td width="149" bgcolor="#DACFAF"><label for="textfield"></label>
<input type="text" name="uname" id="textfield" /></td>
<td width="76" bgcolor="#DACFAF"><strong>Password:</strong></td>
<td width="150" bgcolor="#DACFAF"><label for="textfield2"></label>
<input type="password" name="pass" id="pass" /></td>
<td width="196" bgcolor="#DACFAF"><input type="image" name="login" src="images/login.jpg" /> </td>
<td width="68" bgcolor="#DACFAF"> </td>
<td width="68" bgcolor="#DACFAF"><strong>Register </strong> </td>
</tr>
</table>
</form>
<?php }
else {
$Row = mysql_fetch_assoc($QueryResult);
$userID = $Row['userid'];
$userName = $Row['first_name']. " ". $Row['last_name'];
echo "<table width=780px border=0px >";
echo "<tr>";
echo "<td style='color:red;'>";
echo "<b> Welcome back, $userName!</b>";
echo "</td>";
echo"<td align='right'>";
echo "<form method='POST' action=''>";
echo "<input type='submit' name='submit' value='logout'>";
echo "</form>";
echo "</td>";
echo "</tr>";
echo "</table>";
}
?> </td>
</tr>
</table>
Assuming you know how to set $_SESSION variable.
or if not
In your log in php start a session using session_start();. after all the checking is done. Put the name inside of the $_SESSION variable.
like this
$_SESSION['username'] = $firstname.$lastname;
assuming $firstname has the user's first name and $lastname has the user's last name.
THEN:
Put session_start(); at the very beginning of your PHP file that you want to display the username.
then
$userName=$_SESSION['username'];
Put this two together at the very start of every php file you want to display the name.
Now you can use the variable $userName to display the name.

My PHP Form will not refresh properly

So when I hit submit on the form that is displayed, the page (if working properly) should refresh, and the ELSE statement should be displayed instead, but I have 2 problems
The else statement is not displayed until I manually refresh the page
The Pub Score is not updated until the page is manually refreshed either, I think my code placement might be what's causing it, but I tried to put my form as far down as I could, I'm out of ideas, any help would be great thanks.
<?php
require_once('header.php');
require_once('connectdb.php');
require_once('sessioncheck.php');
if (isset($_SESSION['user_id'])) {
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_DATA);
$user_name = mysqli_real_escape_string($dbc, trim($_GET['username']));
$query = "SELECT * FROM blah WHERE username = '$user_name'";
$data = mysqli_query($dbc, $query);
$row = mysqli_fetch_array($data);
if (mysqli_num_rows($data) != 0) {
if ($row['havemic'] == 1) {
$micstatus = "Yes";
} else {
$micstatus = "No";
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title><?php echo $user_name . ' profile' ?></title>
</head>
<body>
<?php
$commenduser = $user_name;
$query = "SELECT * FROM blah where commenduser = '$commenduser'";
$data = mysqli_query($dbc, $query);
$row = mysqli_fetch_array($data);
$lowerusername = strtolower($username);
$loweruser_name = strtolower($user_name);
if (mysqli_num_rows($data) == 0) {
if (isset($_POST['submit'])) {
$commendplayer = mysqli_real_escape_string($dbc, trim($_POST['commendplayer']));
$commend = mysqli_real_escape_string($dbc, trim($_POST['commend']));
$comment = mysqli_real_escape_string($dbc, trim($_POST['comment']));
if (empty($comment)) {
echo '<p class="error">Please fillout a comment before submitting</p>';
} else {
$query = "INSERT INTO commend (commendby, commenduser, comment) VALUES ('$username', '$user_name', '$comment')";
mysqli_query($dbc, $query);
if ($commend == true) {
$query = "UPDATE blah SET points=points+1 WHERE username='$user_name'";
mysqli_query($dbc, $query);
echo '<p class="success">Your commendation has been submitted with + 1 account points.</p>';
} else {
echo '<p class="success">Your commendation has been submitted with no affect on the users account points.</p>';
}
}
}
} else {
echo '<p class="success">You have already submitted a commendation for this player.</p>';
}
?>
<div id="accsettings">
<table cellpadding="5">
<tr><td><label for="username" class="reglabel">Username: </label></td>
<td><label for="username" class="reglabel"><?php echo $row['username']; ?></label></td></tr>
<tr><td><label class="reglabel">Pub Score: </label></td><td><label class="reglabel">
/*This value 'points' should be updated to the new value after form submit */
/*As well the ELSE statement near the bottom should be displayed*/
<?php echo $row['points'] ?></label></td></tr>
<tr><td><label for="steamname" class="reglabel">Steam Name: </label></td>
<td><label for="steamname" id="acclink"><?php echo '' . $row['steamname'] . ''; ?></label>
<tr><td><label for="favchar" class="reglabel">Prefered Hero: </label></td>
<td><label for="favchar" class="reglabel"><?php echo $row['favchar']; ?></label></td></tr>
<tr><td><label for="language" class="reglabel">Spoken Language: </label></td>
<td><label for="language" class="reglabel"><?php echo $row['language']; ?></label></td></tr>
<tr><td><label for="playernote" class="reglabel">Player Note: </label></td>
<td><label for="playernote" class="reglabel"><?php echo $row['note']; ?></label></td></tr>
<tr><td><label for="micstatus" class="reglabel">Has a Mic and VO-IP?</label></td>
<td><label for="micstatus" class="reglabel"><?php echo $micstatus; ?></label></td></tr>
<tr><td colspan="2">Players Comments</td></tr>
<?php
if ($row['commendby'] != $username && $lowerusername != $loweruser_name) {
?>
<tr><td><br></td></tr>
<tr><td colspan="2"><p class="success">Player Commendations/Comments</p></td></tr>
<tr><td><br></td></tr>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] . '?username=' . $user_name; ?>">
<tr><td><label for="comment">Leave a comment</label></td>
<td><input type="text" name="comment" class="regtext" /></td></td>
<tr><td colspan="2"><label for="commend" class="right">Commend Player?</label><input type="checkbox" class="right" name="commend" value="yes" /></td></tr>
<tr><td colspan="2"><input id ="submit" type="submit" class="button1" name="submit" value="Submit" /></td></tr>
</form>
<?php
} else {
/*This is what should be being displayed after the form is submitted. But it is not.*/
$query = "SELECT * FROM blah where commenduser = '$commenduser'";
$data = mysqli_query($dbc, $query);
while($row = mysqli_fetch_array($data)) {
echo '<tr><td><br></td></tr>';
echo '<tr><td><br></td></tr>';
echo '<tr><td><label class="reglabel" for="commendedbyy">Comment From: ' . $row['commendby'] . '</label></td>';
echo '<td><label class="reglabel">' . $row['comment'];
echo '<input type="hidden" name="submit" />';
echo '</form>';
}
}
?>
</table>
<?php
} else {
echo '<p class="error">' . $user_name . ' is not a registered account.</p>';
}
}
else {
echo '<p class="error">You must Log In to view this profile.</p>';
}
?>
</div>
</body>
</html>
<?php
require_once('footer.php');
?>
The $row is first grabbed from the database and then the database is updated.
You can do one of three things, the last being the simplest:
You can refactor the code to change the order
Reload the data using another query after the update
Once you update the points then update the array (i.e. do $row['points'] = $row['points'] + 1;)

Categories