Updating existing entry (MySQL PHP HTML) -


please bare me i'm still learning basics.

i'm trying make page retrieves name of owner , giving me option enter comments of action. sending comments timestamp of appropriate selected person.

i can retrieve 'owner' name in viewing format i'm having problem when submitting comments updates columns of 'comments', rather add selected entry (probably an'id' issue) field , timestamp doesn't capture properly, adds new row blank fields timestamp value.

this have far:

<?php function renderform($id, $owner, $attendance, $comments, $log, $error) { ?> <!doctype html> <html> <head> <title>log</title> </head> <body> <?php if ($error != '') { echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>'; } ?> <form action="" method="post"> <input type="hidden" name="id" value="<?php echo $id; ?>"/> <div> <strong>owner: </strong><?php echo $owner; ?><br/><br/>  <strong>attendance: </strong><select name="attendance" id="attendance">             <option value=""><?php echo $status; ?></option>             <option value = "present">ongoing</option>                <option value = "absent">closed</option>        </select><br/><br/>  <div style="position: absolute; top: 200px; left: 300px; width: 210px; height: 125px;"> <strong>comments: </strong><br/> <?php  // connect database $conn = mysqli_connect("localhost", "root", ""); $result = mysqli_query($conn, "select * arc.log attendance in ('present', 'absent')", mysqli_use_result)     or die(mysql_error()); echo "<table border='1' cellpadding='10'>"; echo "<font color=\"white\"><tr><th>timestamp</th><th>comments</th></tr>"; while($row = mysqli_fetch_array( $result )) {    echo "<tr>"; echo '<td>' . $row['timestamp'] . '</td>'; echo '<td>' . $row['comments'] . '</td>'; echo "</tr>"; } // close table> echo "</table>"; ?></div>  <div style="position: absolute; top: 8px; left: 700px; width: 210px; height: 125px;"> <strong>comments: </strong> <br/><textarea id="comments" name="comments" rows="10" cols="50"></textarea></div> </div> <br/> <br/> <input type="submit" name="submit" value="submit"> </form> </body> </html>  <?php } $conn = mysqli_connect("localhost", "root", ""); if (isset($_post['submit'])) { if (is_numeric($_post['id'])) { $comments = mysqli_real_escape_string($conn, $_post['comments']); $timestamp_history = date("y-m-d h:i:s"); if ($comments == '') { $error = 'error: please fill in required fields!'; renderform($remarks, $error); } else { mysqli_query($conn, "update arc.log set comments='$comments'") or die(mysql_error()); $query = "insert `ticket`(`timestamp`) values ('$timestamp')"; $result = mysqli_query($conn, $query); } } else { echo 'error1'; } } else { if (isset($_get['id']) && is_numeric($_get['id']) && $_get['id'] > 0) { $id = $_get['id']; $result = mysqli_query($conn, "select * arc.log id=$id") or die(mysql_error()); $row = mysqli_fetch_array($result); if($row) { $owner = $row['owner']; $attendance = $row['attendance']; $comments = $row['comments']; renderform($id, $owner, $attendance, $comments, ''); } else // if no match, display result { echo "no results!"; } } else { echo 'error2'; } } ?> 

mysql:

enter image description here

thank in advance.

update arc.log set comments='$comments' id = $_post['id']

note should escape post parameter, , not blindly copy this.

for timestamp issue. if don't want insert new record, instead update existing one, use update , not insert.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -