Skip to content

Instantly share code, notes, and snippets.

View barmgeat's full-sized avatar

Mustafa Hazim barmgeat

  • Berlin, Germany
View GitHub Profile
const postSchema = new mongosse.Schema({
title: {type: String, required: true},
des: {type: String, required: true},
body: {type: String, required: true},
tags: [{type: mongosse.Schema.Types.ObjectId, required: true, ref:'Tag'}]
});
router.get('/addPost', async(req, res) =>{
try {
// add post:
const post = new Post({
title: 'Post 3 title',
des: 'Post 3 Description',
body: 'Post 3 Body',
tags: ['5dba7d7ae842b83c84344755', '5dba7eab7fb2bf4fe0d1122d', 'another tag id and so on']
});
@barmgeat
barmgeat / posts.js
Last active October 31, 2019 08:15
router.get('/getOne', async(req, res) =>{
try {
if(!req.query.id){
throw {message: 'add the post id in the request'}
}
const id = req.query.id;
//be carful to add the the tags field name in the model
//and not the Model Name or ref
//create html element:
function eHtml(data) {
data.type ? e = $('<' + data.type + '>') : e = $('<div>');
if (data.class) {
e.addClass(data.class);
}
if (data.id) {
e.attr('id', data.id);
<?php
$servername = "HOSTNAME"; //Cpanel hostname to MySQL is: ****localhost**** .
$username = "USERNAME";
$password = "PASSWORD";
//Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
<?php
// Create database
$sql = "CREATE DATABASE myDB";
if ($conn->query($sql) === TRUE) {
echo "Database created successfully";
} else {
echo "Error creating database: " . $conn->error;
}
<?php
$conn->close();
?>
<?php
// sql to create table
$sql = "CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)";
@barmgeat
barmgeat / insert data.php
Last active December 27, 2020 21:07
add new data to the MySQL Table .
<?php
//insert new data to the table myGuests :
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', '[email protected]')";
//check if the statement successfully applicated :
if ($conn->query($sql) === TRUE) {
$last_id = $conn->insert_id;
echo "New record created successfully. Last inserted ID is: " . $last_id;
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {