Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

database's

Status
Not open for further replies.

TrueJoker

Technical User
Jun 14, 2006
115
GB
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?
 
1) PHP questions should be asked in the PHP forum (forum436).
2) "It's not working" isn't very descriptive. Try to provide error messages whenever possible.
3) Something I noticed from a MySQL perspective is this:

Code:
INSERT INTO personel (firstname, surname)
     VALUES ('$fn', '$sn'), NOW() );

you are defining two fields then inserting three. it should be:

Code:
INSERT INTO personel (firstname, surname, datefieldname)
     VALUES ('$fn', '$sn', NOW() );



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top