I'm new to MySql so forgive me for any stupid errors but Basically i'm making a blog and i have a table which has 4 columns: post_id, post_text, post_user and post_date. I am unable to get my code to insert data into MySql, I'd be greatfull if you could have a look and let me know where I'm going wrong:
<?php
$host = "localhost";
$user="user";
$password="*********";
$db="myData";
$user_id = $_SESSION['user_id'];
ini_set('display_errors', 1); error_reporting(-1);
//can't find the user_id
$con=mysql_connect($host,$user,$password,"myData","posts");
if( $con === FALSE ) {
die('mysql connection error: '.mysql_error());
}
$post_text = mysqli_real_escape_string($con,$_POST["blog_entrance"]);
$post_date = mysqli_real_escape_string($con,date("y.m.d"));
$query = "INSERT INTO posts (post_text, post_user) VALUES ('$post_text','$user_id','$post_date')";
mysql_query($query,$con) or die('Can\'t post data atm: ' . mysql_error());
mysql_close($host,$user,$password,"myData","posts");
header('Location: ../index.php');
?>
the error message is this "Warning: mysql_connect() expects parameter 5 to be long, string given in /media/sdc1/Documents/Coding/Blog/www/core/submit.php on line 15 Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in /media/sdc1/Documents/Coding/Blog/www/core/submit.php on line 21 Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in /media/sdc1/Documents/Coding/Blog/www/core/submit.php on line 22 Notice: Undefined variable: user_id in /media/sdc1/Documents/Coding/Blog/www/core/submit.php on line 25 Warning: mysql_query() expects parameter 2 to be resource, null given in /media/sdc1/Documents/Coding/Blog/www/core/submit.php on line 26 Can't post data atm:"
I can see that all these errors seem to stem from the mysql_connect function, please could you tell me the error of my ways?
Also i'm unsure as to whether to use mysql or mysqli????