I have 2 php files. One of them creates a table and inserts data into MySql using php. The other php selects the table in the database and outputs the data from the table. The table is outputting 0 results as in there aren't any record being stored into the table.
Need help, Thanks!
//select from table
$sql = "SELECT * FROM post02";
$result = mysql_query($link, $sql);
echo 'selecting table works';
//output from table
if (mysql_num_rows($result) > 0) {
while($row = mysql_fetch_assoc($result)) {
echo "id: " . $row["id"]. " - Name: " . $row["title"]. " " . $row["content"]. "" . $row["date"]."<br>";
}
} else {
echo "0 results";
}
// create a table
$sql="create table post02(id INT(6) unsigned auto_increment primary key , title varchar(30) not null, content varchar(255) not null, date TIMESTAMP)";
$result = mysql_query($sql);
if (! $result ) {
die ( 'Cant create table : ' . mysql_error ());
}
echo 'Created a table successfuly' ;
//insert to table
echo'insert table - initializing';
if($_POST['submit']){
$title = $_POST['title'];
$content = $_POST['content'];
$date = date('l jS \of F Y h:i:s A');
}
$sql = "INSERT INTO post02(title, content, date) VALUES ($title, $content,$date))";
if($title =="" || $content=="" ){
echo "please compelete your post!";
return;
}
echo'insert table completed';
mysql_query($db ,$sql);
header("location: viewblog.php");