Forum Moderators: coopster

Message Too Old, No Replies

criminal database

         

greekstudent

2:46 pm on Jan 31, 2008 (gmt 0)

10+ Year Member



dear coders i am a 3rd year student computer science on a project. one part of my project is to create a database with criminals. i have created the database.

the table is

CREATE TABLE `criminal` (
`criminalID` int(11) NOT NULL auto_increment,
`first_name` varchar(20) NOT NULL,
`last_name` varchar(20) NOT NULL,
`Date_Of_Birth` date NOT NULL,
`Race` varchar(20) NOT NULL,
`Description` text NOT NULL,
`Institution` varchar(20) NOT NULL,
`Crime` varchar(20) NOT NULL,
`Picture` varchar(30) NOT NULL,
PRIMARY KEY (`criminalID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

here is the code i used to insert records

<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("forensics", $con);

$sql="INSERT INTO criminal (first_name, last_name, date_of_birth, race, description, institution, crime, picture)
VALUES
('$_POST[first_name]','$_POST[last_name]','$_POST[date_of_birth]','$_POST[race]', '$_POST[description]', '$_POST[institution]', '$_POST[crime]', '$_POST[picture]' )";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Criminal record successfully added to database";

mysql_close($con)
?>

i put this in a seperate file insert.php

the actual submit is from this file insert.html

<html>
<body>
<div align="center"><center><table border="1" width="90%">

<form action="insert.php" method="post">

<tr>
<th width="30%" nowrap>First Name</th>
<td width="70%"><input type="text" name="first_name"
size="20" maxlength="20"></td>

<tr>
<th width="30%" nowrap>Last Name</th>
<td width="70%"><input type="text" name="last_name"
size="20" maxlength="20"></td>

<tr>
<th width="30%" nowrap>Date Of Birth</th>
<td width="70%"><input type="text" name="date_of_birth"
size="20" maxlength="20"></td>

<tr>
<th width="30%" nowrap>Race</th>
<td width="70%"><input type="text" name="race"
size="20" maxlength="20"></td>
<tr>
<th width="30%" nowrap>Description</th>
<td width="70%"><input type="text" name="description"
size="20" maxlength="20"></td>

<tr>
<th width="30%" nowrap>Institution</th>
<td width="70%"><input type="text" name="institution"
size="20" maxlength="20"></td>

<tr>
<th width="30%" nowrap>Crime</th>
<td width="70%"><input type="text" name="crime"
size="20" maxlength="20"></td>
<tr>
<th width="30%" nowrap>Picture</th>
<td width="70%"><input type="text" name="picture"
size="20" maxlength="20"></td>
<input type="submit" />

</form>

</body>
</html>

i have two questions. what is the code to insert a picture. i dont want to use blob but display it as a varchar. then i want to create a file that displays a list of the records displaing the criminaliD, firstname and lastname. then clicking on one record i want each record to be displayed on its own in a new window showing the full information of the record.

[edited by: coopster at 3:35 pm (utc) on Jan. 31, 2008]
[edit reason] generalized password [/edit]

whoisgregg

5:47 pm on Jan 31, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld [webmasterworld.com], greekstudent!

If you want to allow pictures to be uploaded, then a good start is the PHP manual section on handling file uploads [php.net]. For the database portion, you are right to avoid BLOB. Folks typically just store the filename/path to the image that was uploaded (not the filename the user provides mind you, but the filename you choose to store it at) then echo that value into an <img> element.

For displaying records from the database, our library thread Basics of extracting data from MySQL using PHP [webmasterworld.com] should be quite helpful.

If you run into trouble, post back a description of the problem with a short code snippet that illustrates where you are having trouble and we'll take a look. :)