I have a database and a form that submits person info into the database. I wrote script that connects to the database, and
stores values into the database. I wrote this script in the same file where the application form is like so:
submit_application.php
<?php
$con = mysql_connect("mysql3.000webhost.com","a4457578_peeps","pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("a4457578_people", $con);
$sql="INSERT INTO person (first, last, phone, country, city, age) VALUES (' $_POST[first] ','$_POST[last]','$_POST[phone]','$_POST[country]','$_POST[city]','$_POST[age]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
mysql_close($con)
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
h1 {
font:15px Arial, Helvetica, sans-serif;
color:#666;
width:600px;
}
body {
margin:0px;
}
#mainWrap {
width:900px;
margin-left:auto;
margin-right:auto;
}
#header {
height:30px;
}
#topNav {
float:right;
width:300px;
}
#main {
height:300px;
}
</style>
</head>
<body>
<div id="mainWrap">
<div id="header">
<div id="topNav">
</div>
</div>
<div id="main">
<div id="messageBox">
<div id="formBox">
<form action="submit_application.php" method="post" >
Firstname: <input type="text" name="first" /><br><br>
Lastname: <input type="text" name="last" /><br><br>
City: <input type="text" name="city" /><br><br>
Country: <input type="text" name="country" /><br><br>
Phone Number <input type="text" name="phone" /><br /><br />
Age: <input type="text" name="age" /><br><br>
Upload Image: <input name="img1" type="file" /><br /><br /><br /><br />
<input type="submit" />
</form>
</div>
</div>
</div>
</div>
</body>
</html>
Now on index.php I have a search form that searches the database by name and outputs info on the browser it works good. However, what I am trying to do is
add a file upload filed where a person can also upload a photo and the photo would be displayed along with the info. Is there a way to add a file upload field function to my
existing script or do I have to rewrite the entire script accordingly???
This is the index page code where it searches and outputs:
<?php
mysql_connect("mysql3.000webhost.com", "a4457578_peeps", "iamrich120") or die("Error connecting to database: ".mysql_error());
mysql_select_db("a4457578_people") or die(mysql_error());
?>
<a href="submit_application.php">Submit application to be notified </a><br /><br /><br /><br /><br />
<p>or search for existing spaces</p>
<br />
<form action="index.php" method="GET">
<input type="text" name="query" placeholder="Search by name, city, country" style="width:500px; padding-left:30px; height:50px;" />
<input type="submit" value="Search" />
</form>
<?php
$query = $_GET['query'];
$min_length = 3;
if(strlen($query) >= $min_length){
$query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
$raw_results = mysql_query("SELECT * FROM person
WHERE (ID LIKE '%".$id."%') OR(`first` LIKE '%".$name."%') OR ('last' LIKE '%".$query."%') OR ('city' LIKE '%".$query."%') OR ('country' LIKE '%".$query."%') OR ('age' LIKE '%".$query."%')") or die(mysql_error());
if(mysql_num_rows($raw_results) > 0){
while($results = mysql_fetch_array($raw_results)){
echo '<br/> First Name: '.$results['first'];
echo '<br/> Last Name: '.$results['last'];
echo '<br/> Phone: '.$results['phone'];
echo '<br/> Last Name: '.$results['country'];
echo '<br/> Phone: '.$results['city'];
echo '<br/> Last Name: '.$results['age'];
echo '<br/>';
}
}
else{
echo "No results";
}
}
else{
echo "Minimum length is ".$min_length;
}
?>
Thank you