I ahve just got the hang of using phpmyadmin to create tables and add records etc, Now im trying to add and view these records on a web page using php. But its not working :S here is the simple little code i am using:
<?php # script 7.3 - update.php
if (isset($_POST['submitted'])) {
$error = array();
if (empty($_POST['firstname'])) {
$error[] = 'You forgot to enter your Firstname';
} else {
$fn = trim($_POST['firstname']);
}
if (empty($_POST['surname'])) {
$error[] = 'You forgot to enter your Surname';
} else {
$sn = trim($_POST['surname']);
}
if (empty($error)) {
require_once ('mysql_connect.php');
$query = "INSERT INTO personel (firstname, surname)
VALUES ('$fn', '$sn'), NOW() )";
$result = @mysql_query ($query);
if ($result) {
echo 'Database updated';
} else {
echo 'Error could not be updated';
exit();
}
mysql_close();
} else {
echo 'Error';
}
echo 'Please try again';
}
?>
<form method="post" action="update.php">
First name: <input name="firstname" type="text" value="">
<br>
Last name: <input name="lastname" type="text" value="">
<br>
<input type="submit" name="submit" value="Submit">
</form>
what am i doing wrong?
<?php # script 7.3 - update.php
if (isset($_POST['submitted'])) {
$error = array();
if (empty($_POST['firstname'])) {
$error[] = 'You forgot to enter your Firstname';
} else {
$fn = trim($_POST['firstname']);
}
if (empty($_POST['surname'])) {
$error[] = 'You forgot to enter your Surname';
} else {
$sn = trim($_POST['surname']);
}
if (empty($error)) {
require_once ('mysql_connect.php');
$query = "INSERT INTO personel (firstname, surname)
VALUES ('$fn', '$sn'), NOW() )";
$result = @mysql_query ($query);
if ($result) {
echo 'Database updated';
} else {
echo 'Error could not be updated';
exit();
}
mysql_close();
} else {
echo 'Error';
}
echo 'Please try again';
}
?>
<form method="post" action="update.php">
First name: <input name="firstname" type="text" value="">
<br>
Last name: <input name="lastname" type="text" value="">
<br>
<input type="submit" name="submit" value="Submit">
</form>
what am i doing wrong?