I’m trying to fix an update but all other things work expect for the comments, it doesn’t change please I need help; below is the code;
function updateStatus($dbConn) {
$OfficeName = $_POST['OfficeName'];
$status = $_POST['status'];
$comments = $_POST['comments'];
$cid = (int)$_POST['cid'];
$cons_no = $_POST['cons_no'];
//$OfficeName = $_POST['OfficeName'];
$sqli = "INSERT INTO tbl_courier_track (cid, cons_no, current_city, status, comments, bk_time)
VALUES ($cid, '$cons_no', '$OfficeName', '$status', '$comments', NOW())";
dbQuery($sqli,$dbConn);
$sql_1 = "UPDATE tbl_courier
SET status = '$status'
WHERE cid = $cid
AND cons_no = '$cons_no'";
dbQuery($sql_1,$dbConn);
header('Location: update-success.php');
Have you tried printing out your $_POST
array?
donboe
August 21, 2018, 10:26am
3
Can you show the html as well?
How do I print out your $_POST
array? I’m new on PHP
chorn
August 21, 2018, 10:45am
6
throw an error within dbQuery()
, then refactor to prepared statements.
donboe
August 21, 2018, 10:46am
7
@ikechukwuprosper20 . The Form. Besides of that you say
But I don’t see comments in your update query?
This is the html
<span class="Partext1"><br>
</span><span class="Partext1"><br>
<br>
</span>
<form action="process.php?action=update-status" method="post" name="frmShipment" id="frmShipment">
<table bgcolor="#EEEEEE" cellpadding="2" cellspacing="2" align="center" width="75%">
<tbody><tr>
<td colspan="3" bgcolor="#FFFFFF" align="right"><div class="Partext1" align="center"><strong>UPDATE STATUS </strong>
</div></td>
</tr>
<tr>
<td colspan="3" bgcolor="#FFFFFF" align="right"></td>
</tr>
<tr>
<td class="Partext1" bgcolor="#FFFFFF" align="right" width="16%">New Location:</td>
<td colspan="2" class="Partext1" bgcolor="#FFFFFF">
<select name="OfficeName">
<?php
while($data = dbFetchAssoc($result_1)){
?>
<option value="<?php echo $data['off_name']; ?>"><?php echo $data['off_name']; ?></option>
<?php
}//while
?>
</select> </td>
</tr>
<tr>
<td class="Partext1" bgcolor="#FFFFFF" align="right">New Status: </td>
<td class="Partext1" bgcolor="#FFFFFF" width="26%">
<select name="status">
<option value="In Transit">In Transit</option>
<option value="Landed">Landed</option>
<option value="Delayed">Delayed</option>
<option value="Completed">Completed</option>
<option value="Onhold">Onhold</option>
</select>
<br></td>
<td class="Partext1" bgcolor="#FFFFFF" width="58%"><div align="center">
<a href="process.php?action=delivered&cid=<?php echo $cid; ?>">Marked this shipment as to be <span class="style1">DELIVERED </span></a><span class="style1"></span></div></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" align="right"><span class="Partext1">Comments:</span></td>
<td colspan="2" class="Partext1" bgcolor="#FFFFFF">
<textarea name="comments" cols="40" rows="3" id="comments"></textarea></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" align="right"> </td>
<td colspan="2" class="Partext1" bgcolor="#FFFFFF">
<input name="submit" value="Submit" type="submit">
<input name="cid" id="cid" value="<?php echo $cid; ?>" type="hidden">
<input name="cons_no" id="cons_no" value="<?php echo $cons_no; ?>" type="hidden"> </td>
</tr>
<tr>
<td colspan="3" bgcolor="#FFFFFF" align="right"><div align="center">
</div></td>
</tr>
</tbody></table>
<br>
</form> </td>
</tr>
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" align="center" width="900">
<tbody><tr>
<td bgcolor="#2284d5" height="40" width="476"> </td>
<td bgcolor="#2284d5" width="304"><div align="right"></div></td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
donboe
August 21, 2018, 10:55am
9
@ikechukwuprosper20 . Can you please just copy the entire form in just one code block incl. the form tags. This is very confusing
Off Topic:
@ikechukwuprosper20 : when you post code on the forums, you need to format it so it will display correctly. (I’ve edited your post above for you.)
You can highlight your code, then use the </>
button in the editor window, or you can place three backticks ``` (top left key on US/UK keyboards) on a line above your code, and three on a line below your code. I find this approach easier, but unfortunately some European and other keyboards don’t have that character.
1 Like
donboe
August 21, 2018, 11:04am
12
So, just to be clear the insert for:
comments
is not working?
Mmm the entire html is gone!
Please can I make you understand?
You see that picture, when I try to update every other things works well; the new location and new status but the comments doesn’t update.
donboe
August 21, 2018, 11:17am
16
This is your update query:
$sql_1 = "UPDATE tbl_courier
SET status = '$status'
WHERE cid = $cid
AND cons_no = '$cons_no'";
So how can it update field comments when it is not in the Query?
Need to see the html code that draws that form, rather than the form itself.
Is it correct that the form says it is to “update status”, but the only query in your first post that contains comments is the insert, not the update?
I presumed the insert query is kind of a transaction log, so it’s actually the insert query that needs to store the comments. Might be wrong though.
Can you help me with the query, I’m new to php
Gandalf
August 21, 2018, 11:26am
19
You need the print_r()
function.
Can you help me define the comments in the Query above?