I want to create a simpe MySQL database with Name, Surname and picture.
I create folloving code but this works only for name and surname. What I need to do is to upload pictures to
server and then to call it in to search results.
Sorry, but parts of code is on Croatian language.
here is the code: (4 files):
********1'st file** enter_data.php**********
<HTML>
<HEAD>
<TITLE>T i t l e</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" background="smoothyellow.jpg">
<h3 align="center">
<font face="Georgia, Times New Roman, Times, serif">some text </font></h3>
<FORM METHOD=POST ACTION="add1.php3">
<p align="center">
<input type="hidden" name="id" value="NULL">
</p>
<table width="50%" border="1" align="center">
<tr>
<td width="32%">Ime (first name)</td>
<td width="68%">
<input type="text" name="ime" size="10">
</td>
</tr>
<tr>
<td width="32%">Prezime (last name)</td>
<td width="68%">
<input type="text" name="prezime" size="10">
</td>
</tr>
<tr>
<td width="32%">Slika (Image)</td>
<td width="68%">
Here I want to browse local Hard disc and select image to upload
<input type="text" name="image_path">
</td>
</tr>
</table>
<p align="center">
<input type="submit" value="submit" name="submit">
</p>
</FORM>
</BODY>
</HTML>
**2'nd file*******add1.php3***
<html>
<head>
<title>potvrda zaprimanja oglasa</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
</head>
<body bgcolor="#FFFFFF" text="#000000" background="smoothyellow.jpg">
<?
$DBhost = "localhost";
$DBuser = "user";
$DBpass = "password";
$DBName = "dbname";
$table = "test";
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
@mysql_select_db("$DBName") or die("Unable to select database $DBName");
$sqlquery = "INSERT INTO $table VALUES('$id','$ime','$prezime','$imgdata')";
$results = mysql_query($sqlquery);
mysql_close();
print "<HTML><TITLE> Potvrda zaprimanja oglasa </TITLE>";
print "<p>Podaci su ispravno unešeni u bazu <p>";
?>
<table width="50%" border="0" cellspacing="1">
<tr>
<td><a href="enter_data.php">Povratak na predaju oglasa</a></td>
<td><a href="search.php3">Pretraživanje oglasa</a></td>
</tr>
</table>
</body>
</html>
**********3'rd filesearch.php3****
<html>
<head>
<title>rezultat pretrage</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
</head>
<body bgcolor="#FFFFFF" text="#000000" background="smoothyellow.jpg">
<p></p>
<p><b><font face="Verdana, Arial, Helvetica, sans-serif">Sa padajuæeg izbornika
odaberite mjesto u kojem tražite sobu ili apartman.</font></b></p>
<p><form name="form1" method="post" action="rezultat1.php3">
<?
$DBhost = "localhost";
$DBuser = "username";
$DBpass = "password";
$DBName = "dbname";
$table = "tablename";
$link = mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
mysql_select_db("$DBName") or die("Ne mogu se spojiti na bazu podataka");
$sql = "SELECT * FROM test ORDER BY prezime";
$result = mysql_query($sql);
if (mysql_num_rows($result) > 0) {
echo "<select name=\"traziprezime\">";
while ($hasil = mysql_fetch_array($result)) {
echo "<option value=\"".$hasil['prezime']."\">".$hasil['prezime']."</option>";
}
echo "</select>";
}
mysql_close($link);
?>
<br>
<input type="submit" name="Submit" value="Submit">
</body>
</HTML>
*4'th filerezultat1.php3******
<html>
<head>
<title>rezultat pretrage</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
</head>
<body bgcolor="#FFFFFF" text="#000000" background="smoothyellow.jpg">
<?
$DBhost = "localhost";
$DBuser = "username";
$DBpass = "password";
$DBName = "dbname";
$table = "tablename";
$link = mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
mysql_select_db("$DBName") or die("Ne mogu se spojiti na bazu podataka");
$sql = "SELECT * FROM test WHERE mjesto='$traziprezime' ORDER BY id";
$result = mysql_query($sql);
mysql_close($link);
// print the table
print"<table width=436 border=1 bgcolor=#FFFFFF>";
//print "<TABLE BORDER=1 CELLPADDING=5 CELLSPACING=1>";
// print a row for each result
$even = 0;
// loop through $result.. each time the loop is executed,
// $row is an array containing all the data for that given row
while ($row = mysql_fetch_array($result)) {
// Alternate the bgcolor of each row for visibility
($even % 2) == 0 ? $bgcolor = "#EFEFEF" : $bgcolor = "#FFFFFF";
$even = $even + 1;
// print the actual row
print "
<tr>
<td bgcolor=#EFEFEF align=left>ID: $row[id]</TD>
</tr>
<tr>
<TD align=left>ime i prezime: <font color=#0000FF><b>$row[ime] $row[prezime]</b></font></TD>
</tr>
<tr>
<TD align=left>Slika: $row[imgdata]</TD>
</TR>
<tr>
<TD </TD>
</TR>
";
} // end while
print"</table>";
?>
</body>
</html>