Skip to content

Instantly share code, notes, and snippets.

View barmgeat's full-sized avatar

Mustafa Hazim barmgeat

  • Berlin, Germany
View GitHub Profile
<?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
)";
<?php
$conn->close();
?>
<?php
// Create database
$sql = "CREATE DATABASE myDB";
if ($conn->query($sql) === TRUE) {
echo "Database created successfully";
} else {
echo "Error creating database: " . $conn->error;
}
<?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) {
//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);
@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
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']
});
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'}]
});
@barmgeat
barmgeat / expamle.js
Last active October 26, 2019 05:27
to create html elements
// Ex: create category container
/// add the consts in data obj can be not definde just the type is requseted
const catContainer = htmlE({
type: 'div', // type of the element
classes: 'first-class second-class', // css classes
id: elementId, // element id
container: container, // parent container to append to
onClick: catClick, // on element click function
params: [category] // on element click function params
});
@barmgeat
barmgeat / php requests function.js
Last active October 25, 2019 15:04
note extension for sure html but for markup i make it js
public static function postRequest($url, $postData, $headers){
//init curl:
$ch = curl_init($url);
// Configuring curl options
$options = array(
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $postData,
CURLOPT_HTTPHEADER => $headers
);