Jump to content

Recommended Posts

Hi there

 

I have a simple form where I submit notes attached to a customer. The code I am using is below.

 

$q_notes = "SELECT notes, entryDate FROM emp_notes WHERE employer='$employer' ORDER BY id DESC";

$r_notes = mysqli_query($dbc, $q_notes);

$row_notes = mysqli_fetch_array($r_notes);

 

echo '

<div id="right">

 

<h2>Past Activity</h2>

 

<br />';

 

echo '

<div id="notes">';

 

if ($row_notes) {

 

do {

 

//1. Remove time from Timestamp

$date = substr($row_notes['entryDate'], 0, 10);

 

//2. Convert the date to time

$time = strtotime($date);

 

echo '

<p><strong>Date added - ' . date("d, F Y", $time) . '</strong></p>

 

<p>' . $row_notes['notes'] . '</p><br /><br />';

 

} while ($row_notes = mysqli_fetch_array($r_notes));

 

} else {

 

echo '<p>No activity has taken place to date.</p>';

 

}

 

echo '

</div><!--end of notes -->';

 

echo '<p>' . $sic_code_list . '</p>';

 

if (isset($_POST['submitted2'])) {

 

// Initialize an error array.

$errors = array();

 

$employer = $_GET['id'];

 

if (empty($_POST['add_note'])) {

$errors[] = 'You forgot to enter a new note.';

} else {

$notes = mysqli_real_escape_string($dbc, trim($_POST['add_note']));

}

 

$notes = "INSERT INTO emp_notes (id, employer, notes, entryDate) VALUES (NULL, '$employer', '$notes', CURRENT_TIMESTAMP) ";

$run_notes = mysqli_query($dbc, $notes);

 

}//end of main if statement

 

echo '

<br /><br />

 

<form name="form2" method="post" action="update.php?id=' . $_GET['id'] . '" >

<table border="0" cellspacing="0" cellpadding="5">

<tr>

<td><textarea name="add_note" cols="50" rows="5"></textarea></td>

</tr>

<tr>

<td> </td>

</tr>

<tr>

<td><input type="submit" value="Add New Activity" /><input type="hidden" name="submitted2" value="TRUE" /></td>

</tr>

</table>

</form>

 

</div><!--end of right -->';

 

The problem is that when I submit the form the data I have just entered does not show on the page. It writes to the database but does not display. If I post another 'note' the previous one then shows.

 

How can I amend the code to make sure that it posts then displays straight away?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/181703-displaying-data/
Share on other sites

first write to database and after thet show data

move this part to begin

cho '<p>' . $sic_code_list . '</p>';

if (isset($_POST['submitted2'])) {

// Initialize an error array.
$errors = array();

$employer = $_GET['id'];

if (empty($_POST['add_note'])) {
$errors[] = 'You forgot to enter a new note.';
} else {
$notes = mysqli_real_escape_string($dbc, trim($_POST['add_note']));
}

$notes = "INSERT INTO emp_notes (id, employer, notes, entryDate) VALUES (NULL, '$employer', '$notes', CURRENT_TIMESTAMP) ";
$run_notes = mysqli_query($dbc, $notes);

}//end of main if statement

Link to comment
https://forums.phpfreaks.com/topic/181703-displaying-data/#findComment-958409
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.