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.
[COLOR=”Red”]Here is the code for selecting from the database:
[code=php]<?php
mysql_connect(“localhost”, “root”, “”);
mysql_select_db(“mydb”);
?>
<html>
<head>
<title>Project 3 Blog</title>
</head>
<body>
[code=php]<?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>
[code=php]<?php
}
?>
</body>
</html>
[COLOR=”Red”]Here is the code for inserting into the database:
[code=php]<?php
mysql_connect(“localhost”, “root”, “”);
mysql_select_db(“mydb”);
?>
<html>
<head>
<title>Add new Post</title>
</head>
<body>
[code=php]<?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>
[code=php]<?php
}
?>
</body>
</html>