I'm building a MYSQL generated PHP application. I have a table called students and a table called notes. The notes table will be used to put in any extra information about the student being advised, so that the advisor can go back and look at the information the next time they advise the student. I'm not sure how to go about this.
I want the advisor just the see the notes of the specific student they're advising and not others. I'm using an inner join to join the two tables along with a SELECT statement. Information from both tables will be posted to the notes page in an HTML form. How would I insert the data so that it can be viewed correctly? Thanks for the help in advance.
This is my select query (not whole page). This page shows the notes.
<?php
$query = "
SELECT
notes.Note_Title,
notes.Note_Desc,
notes.Note_Cont,
notes.Note_Date
from notes
INNER JOIN students
ON notes.id = students.id
Where students.id = 'id'";
try {
$stmt = $db->prepare($query);
$stmt->execute();
}
catch(PDOException $ex)
{
die("Opps that Query didn't work out: " . $ex->getMessage());
}
while($row = $stmt->fetch()){
echo'<div>';
echo'<tr>';
echo '<td><h5><a href="notes_view.php?id='.$row['id'].'">'.$row['Note_Title'].'</a></h5></td>';
echo '<td><p>Note created on '.date('JS M Y H:i:s', strtotime($row['Note_Date'])).'</p></td>';
echo '<p>'.$row['Note_Desc'].'</p>';
echo '<p><a href="notes_view.php?id='.$row['id'].'">Read Note</a></p>';
echo '<p><a href="delete.php?id='.$row['id'].'">Delete note</a></p>';
echo '<p><a href="edit_notes.php?id='.$row['id'].'">Edit</a></p>';
echo '<hr width="100%">';
echo'</div>';
}
$query = "INSERT INTO notes (
id,
Note_Title,
Note_Desc,
Note_Cont,
Note_Date
) VALUES (
:id,
:Note_Title,
:Note_Desc,
:Note_Cont,
:Note_Date
)
";
$query_go = array(
':id' => $id,
':Note_Title' => $Note_Title,
':Note_Desc' => $Note_Desc,
':Note_Cont' => $Note_Cont,
':Note_Date' => date('Y-m-d H:i:s')
);
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_go);
}
catch(PDOException $ex)
{
die("Opps that query didn't work out: " . $ex->getMessage());
}
header('location: index.php?action=added');
exit;
}
}
?>
<form action='' method='POST'>
<input type='hidden' name='id' id='id' value='<?php if(isset($error)){echo $_POST['id'];}?>'>
<p><label>Note Title:</label><br />
<input type='text' name='Note_Title' value='<?php if(isset($error)){echo $_POST['Note_Title'];}?>'></p></td>
<p><label>Note description:</label><br />
<textarea name="Note_Desc" cols="40" rows="11"><?php if(isset($error)){echo $_POST['Note_Desc'];}?></textarea></p></td>
<p><label>Note content:</label><br />
<textarea name="Note_Cont" cols="70" rows="11"><?php if(isset($error)){echo $_POST['Note_Cont'];}?></textarea></p></td>
<p><input type="submit" name="submit" value="submit" ></p>
</form>