- Joined
- Apr 3, 2006
- Location
- Dublin, Ireland
I'm trying to use a SQL database and PHP webpages to create a catalogue of my book collection. So far I have a DB with a table, and I have some HTML/PHP pages that allow me to add records to the DB via a form.
I want to be informed if a record already exsists and have the option of actully creating two similar records with an OK or Cancel button.
I want to be informed if I try adding a record with all fields empty, this is to prevent accidentally adding blank records. I don't mind if all but one field are empty.
Trying to do this might be beyond my current understanding!
Here is the code I'm using, the insert file where the data is input (there is a bit more html code to colour etc. to the page):-
The insert file with the action has been confirmed:-
I want to be informed if a record already exsists and have the option of actully creating two similar records with an OK or Cancel button.
I want to be informed if I try adding a record with all fields empty, this is to prevent accidentally adding blank records. I don't mind if all but one field are empty.
Trying to do this might be beyond my current understanding!
Here is the code I'm using, the insert file where the data is input (there is a bit more html code to colour etc. to the page):-
Code:
<html>
<body>
<form action="insert.php" method="post">
Title: <input type="text" name="title" />
Author: <input type="text" name="author" />
Year: <input type="text" name="year" />
<input type="submit" />
</form>
</body>
</html>
The insert file with the action has been confirmed:-
Code:
<?php
$con = mysql_connect("192.168.1.110","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("lib", $con);
$sql="INSERT INTO lic (Title, Author, Year)
VALUES
('$_POST[title]','$_POST[author]','$_POST[year]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>