Unique entry + joined date
| From: | Oktay | Date: | Thu, 10 Aug 2000 05:34:22 +0000 |
| Subject: | Unique entry + joined date | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-11065@lists.php.net to get a copy of this message | ||
Unique entry + joined date
Greetings,
I am new with php and it is my first scripting experience.
I am trying to code a simple script which will be a very basic URL
directory.
I would much appreciate if anybody could help me with my below
challenges.
1. On the below code I don't know how to figure out to make url field
unique in mysql.
That means there should only be a single copy of the URL in my database.
2.And also for the joined field could you recommend me a simple function
that will print out the date so that it enters to
mydatabase as yyyymmmdddhhhmmmss instead of 0000000000.
3. Could you also please check my mysql database structure whether it is
OK with mysql.
I mean would a professional programmer do what I did or there is much
better way to do it.
I am asking this since I would like to avoid problems in advance which
may happen in the future with the MySql structure.
Thank you in advance and best regards.
Oktay
<?
if ((!$where) || (!$url)|| (!$title)|| (!$description)) {
header("Location: http://www.myhost.com/add.cgi");
exit;
}
?>
<?
/*
CREATE TABLE directory (
ID int(11) DEFAULT '0' NOT NULL auto_increment,
category text NOT NULL,
url varchar(255) NOT NULL,
title varchar(255) NOT NULL,
description text NOT NULL,
email varchar(50) NOT NULL,
joined datetime,
PRIMARY KEY (id)
);
*/
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Add a Site</TITLE>
</HEAD>
<BODY>
<h1>Adding your site to our directory</h1>
<?
$dbhost="localhost";
$dbuser="";
$dbname="";
$dbpasswd="";
$tablename="";
$sql = "INSERT INTO $tablename
(ID, category, url, title, description, email, joined)
VALUES
('$id', '$where', '$url', '$title',
'$description',
'$email', '$joined')";
$connection = mysql_connect("$dbhost","$dbuser","$dbpasswd")
or die ("Couldn't connect to server.");
$db = mysql_select_db("$dbname", $connection)
or die("Couldn't select database.");
$sql_result = mysql_query($sql,$connection)
or die("Couldn't add record.");
if (!$sql_result) {
echo "<P>Couldn't add record!";
} else {
echo "
<P>Record added!</p>
<table cellspacing=5 cellpadding=5>
<tr>
<td valign=top><strong>Title:</strong></td>
<td valign=top>$where</td>
</tr>
<tr>
<td valign=top><strong>Url:</strong></td>
<td valign=top>$url</td>
</tr>
<tr>
<td valign=top><strong>Description:</strong></td>
<td valign=top>$description</td>
</tr>
<tr>
<td valign=top><strong>Email:</strong></td>
<td valign=top>$email</td>
</tr>
</table>
";
}
?>
</BODY>
</HTML>
--
_______________________________
http://demokratik.net
ucretsiz isminiz@demokratik.net
formatinda eposta hesabi ve
"HERKESE AMA HERKESE SOZ HAKKI"