Hi all:
I am trying to:
1. Let the user place in there info
2. upload there picture
3. Take them to the page to see list of schools..
Now here is my code so far but what I do not know how to do is:
1. upload the picture storing it in my sphotos folder?
2. letting the use view a list with there school info and viewing there school picture with it in a list..
Please help???
I am trying to:
1. Let the user place in there info
2. upload there picture
3. Take them to the page to see list of schools..
Now here is my code so far but what I do not know how to do is:
1. upload the picture storing it in my sphotos folder?
2. letting the use view a list with there school info and viewing there school picture with it in a list..
Code:
<?php
$hostname = "localhost"; // usually is localhost, but if not sure, check with your hosting company, if you are with webune leave as localhost
$db_user = "lala"; // change to your database password
$db_password = "password"; // change to your database password
$database = "lala"; // provide your database name
$db_table = "school"; // leave this as is
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database,$db);
// Set global variables to easier names
$name = $_POST['school'];
$site = $_POST['site'];
$street = $_POST['street'];
$street2 = $_POST['street2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$speciality=$_POST['comments'];
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
//echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("sphotos/" . $name . "_" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"sphotos/" . $name . "_" . $_FILES["file"]["name"]);
echo "Stored in: " . "sphotos/" . $name . "_" . $_FILES["file"]["name"];
$photo = $_POST['/sphotos/' . $name . '_' . $_FILES['file']['name']'];
}
}
}
else
{
echo "Invalid file";
}
$sql = "INSERT INTO $db_table (name,site,street,street2,city,state,zip,email,phone,photo) values ('{$name}','{$site}','{$street}','{$street2}','{$city}','{$state}','{$zip}','{$email}','{$phone}','{$photo}');";
if($result = mysql_query($sql ,$db)) {
echo '<h1>Thank you , Your School has been entered into our database - <a href="/schools.php"><b>See your School</b></a></h1><br><br>';
} else {
echo "ERROR: ".mysql_error();
}
?>