-
Notifications
You must be signed in to change notification settings - Fork 0
/
insertPost.php
46 lines (36 loc) · 1.38 KB
/
insertPost.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
require 'config.php';
// Connect to server and select databse.
$link = mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// To protect MySQL injection (more detail about MySQL injection)
// $myusername = stripslashes($myusername);
// $mypassword = stripslashes($mypassword);
// $myusername = mysql_real_escape_string($myusername);
// $mypassword = mysql_real_escape_string($mypassword);
// CREATE TABLE `members` (
// `id` int(4) NOT NULL auto_increment,
// `username` varchar(65) NOT NULL default '',
// `password` varchar(65) NOT NULL default '',
// PRIMARY KEY (`id`)
// ) TYPE=MyISAM AUTO_INCREMENT=2 ;
// INSERT INTO `members` VALUES (1, 'john', '1234');
$username=$_POST['username'];
$post=$_POST['post'];
// insert post into posts db
$mysqldate = date( 'Y-m-d H:i:s');
$sqlInsertEntry="INSERT INTO $tbl_namePosts (username,post,time) VALUES ('$username', '$post', '$mysqldate');";
mysql_query($sqlInsertEntry);
// query posts
$sqlSelect="SELECT post FROM $tbl_namePosts WHERE username='$username' AND post='$post';";
$selectResult=mysql_query($sqlSelect);
if(!$selectResult){
echo "Error: Could not successfully run $sqlSelect";
exit;
}
if(mysql_num_rows($selectResult) == 0){
echo "Error: Post failed to upload. Insert was $sqlInsertEntry and Query was $sqlSelect";
exit;
}
echo "Success";
?>