' : Notes">

NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

<?php
$pdo = new PDO('mysql:dbname=csy2028c;host=localhost', 'student', 'student');

if(isset($_POST['update'])){
$stmt = $pdo->prepare("UPDATE tbl_message SET msgText = :msgText, userId = :userId WHERE id = :id");
unset($_POST['update']);
echo '<pre>'; print_r($_POST); die();
if($stmt->execute($_POST)){
header('Location:addmsg.php?msg=Message Updated Successfully');
}
}

if(isset($_GET['editId'])){

// get list of users
$users = $pdo->prepare("SELECT id, fullName FROM tbl_user");
$users->execute();

$stmt = $pdo->prepare("SELECT * FROM tbl_message WHERE id = :id");
$criteria = [
'id' => $_GET['editId']
];
$stmt->execute($criteria);
$msg = $stmt->fetch();
?>
<h3>Edit Message</h3>
<form action="editmsg.php" method="POST">
<input type="hidden" name="id" value="><?php echo $_GET['editId'] ?>">
<label>Message Text : </label><textarea name="msgText"><?php echo $msg['msgText'];?></textarea><br><br>
<label>Sender : </label>
<select name="userId">
<?php
foreach ($users as $row) {?>
<option value="<?php echo $row['id']?>" <?php if($msg['userId'] == $row['id']) echo 'selected';?>>
<?php echo $row['fullName']?>
</option>
<?php }
?>
</select><br><br>
<input type="submit" name="update" value="Update">
</form>

<?php }?>

//addmsg.php

<?php
$pdo = new PDO('mysql:dbname=csy2028c;host=localhost', 'student', 'student');
if(isset($_POST['save'])){
$sql = "INSERT INTO tbl_message(msgDate, msgText, userId)
VALUES(:msgDate, :msgText, :userId)";
$stmt = $pdo->prepare($sql);
$_POST['msgDate'] = date('Y/m/d');
unset($_POST['save']);
if($stmt->execute($_POST)) echo '<p>Inserted Successfully</p>';
}

// delete a record
if(isset($_GET['delId'])){
$stmt = $pdo->prepare("DELETE FROM tbl_message WHERE id = :id");
$criteria = [
'id' => $_GET['delId']
];
if($stmt->execute($criteria)) echo '<p>Message Deleted Successfully</p>';
}
// delete a record end

// get list of users
$users = $pdo->prepare("SELECT id, fullName FROM tbl_user");
$users->execute();
?>
<h4>Add a Message</h4>
<form action="addmsg.php" method="POST">
<label>Message Text : </label><textarea name="msgText"></textarea><br><br>
<label>Sender : </label>
<select name="userId">
<?php
foreach ($users as $row) {
echo '<option value="'.$row['id'].'">'.$row['fullName'].'</option>';
}
?>
</select><br><br>
<input type="submit" name="save" value="Save">
</form>
<?php
$sql = "SELECT tbl_message.id as msgId,msgDate,msgText,fullName
FROM tbl_message JOIN tbl_user ON tbl_message.userId = tbl_user.id ORDER BY msgId";
$msg = $pdo->prepare($sql);
$msg->execute();
?>
<table border="2">
<tr>
<th>SN</th><th>Msg Date</th><th>Msg Text</th><th>Sender</th><th>Action</th>
</tr>
<?php
$sn = 1;
foreach ($msg as $row) {
echo '<tr>';
echo '<td>'.$sn++.'</td>';
echo '<td>'.$row['msgDate'].'</td>';
echo '<td>'.$row['msgText'].'</td>';
echo '<td>'.$row['fullName'].'</td>';?>
<td>
<a href="#" onClick="javascript: if(confirm('Are you sure?')){ document.location='addmsg.php?delId=<?php echo $row['msgId']?>'; }">
Delete
</a> |
<a href="editmsg.php?editId=<?php echo $row['msgId'];?>">Edit</a>
</td>
<?php echo '</tr>';
}
?>
</table>


     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.