Hi there,
I am a noob to php and mysql, i have been working on this small database just to get my head around working with php and mysql...
My DB is setup and working, i can add info to the table through phpmyadmin, however when i try to add from a form it will not add and does not give me any error to help... SELECT works fine and i can see my data on the page, but POST does not seem to be adding data to the DB...
I will include the index.php, create.php and includes/connection.php scripts below.. i will also attach the database, this is only a small project i am doing to try learn so there is no private data or anything.
if anyone could shed any light i would be most grateful
Thanks
index.php
<?php
include 'includes/connection.php';
$query = "SELECT * FROM people";
$result = mysql_query($query);
while($person = mysql_fetch_array($result)) {
echo "<h3>" . $person['Name'] . "</h3>";
echo "<p>" . $person['Description'] . "</p>";
}
?>
<h1>Create a User</h1>
<form action="create.php" method="post">
Name: <input type="text" name="inputName" value="" /><br>
Description: <input type="text" name="inputDesc" value="" />
<br>
<br>
<input type="submit" value="Submit" />
</form>
create.php
<?php
include 'includes/connection.php';
$name = $_POST['inputName'];
$desc = $_POST['inputDesc'];
if(!$_POST['submit']) {
echo "Please fill out the form";
header('Location: index.php');
} else {
mysql_query("INSERT INTO people (`ID`,`Name`,`Description`)
VALUES(NULL,'$name','$desc')") or die(mysql_error());
echo "User has been added!";
header('Location: index.php');
}
?>
includes/connection.php
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$db = 'userdb';
$conn = mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($db);
?>
SQL Database
--
-- Database: `userdb`
--
-- --------------------------------------------------------
--
-- Table structure for table `people`
--
CREATE TABLE IF NOT EXISTS `people` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Name` varchar(25) NOT NULL,
`Description` varchar(150) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
--
-- Dumping data for table `people`
--
INSERT INTO `people` (`ID`, `Name`, `Description`) VALUES
(1, 'Bob', 'bob blah bob blah description'),
(2, 'Jeff', 'Jeff, description yo!'),
(3, 'tester', 'story horse');

Thanks for reading
H