HI everyone...I had this working at one time but must have changed something. I cant get the php to insert records into phpmyadmin. Can someone check if I have something wrong in my code. Thanks much.
Here is the code for selecting from the database:
PHP Code:
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("mydb");
?>
<html>
<head>
<title>Project 3 Blog</title>
</head>
<body>
PHP Code:
<?php
$sql = "SELECT * FROM posts";
$query = mysql_query($sql);
$result = mysql_fetch_array($query);
$title = $row['title'];
$description = $row['description'];
?>
<table border='1'>
<tr><td><?php echo $title; ?></td></tr>
<tr><td><?php echo $description; ?></td></tr>
</table>
</body>
</html>
Here is the code for inserting into the database:
PHP Code:
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("mydb");
?>
<html>
<head>
<title>Add new Post</title>
</head>
<body>
PHP Code:
<?php
if(isset($_POST['submit'])){
$title = $_POST['title'];
$description = $_POST['description'];
mysql_query("INSERT INTO posts (title, description) VALUES('$title','$description')");
}else{
?>
<form action='admin.php' method='post'>
Title: <input type='text' name='title' /><br>
Description: <textarea name='description'></textarea><br />
<input type='submit' name='submit' value='Post' />
</form>
</body>
</html>
Bookmarks