ik heb een script gemaakt waarmee je met een form gegevens kan toevoegen in een database, nou moet er in de form dus ook gelijk een foto upgeload worden zodat de filenaam ook in mysql kan worden toegevoegd in de zelfde mysqltabel zodat de gegevens en foto gelijk worden kunnen weergeven, nou heb ik alle 2 scripts en werken ze ook, de insert form heb ik zelf gemaakt, en de upload form heb ik van internet omdat ik nog nie precies weet hoe dat in mekaar zit, nou moet dus de 2 scripten 1 script worden zeg maar. Want als ik nu dus ze apart uitvoer, zet die in de tabel alleen de gegevens en al doe ik daarna de upload, maakt die nog een tabel, zonder de gegevens, alleen de foto bestandsnaam. Ik heb het meerdere malen geprobeerd om ze samen te voegen maar dan geeft die altijd een foutmelding aan.
De insertscript:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#280000">
<form action="<?=$php_self?>" method="post"><font face="arial" size="1" color="#FFFFFF"> <small>
<table cellpadding="0" cellspacing="2">
<tr>
<td>
<font size="2" color="#FFFFFF">Street</td>
<td>
<table cellpadding="0" cellspacing="0" width="100%">
<td width="61%"><input name="street" type="text" size="18" style="color: #FFFFFF; font-family: arial, helvetica; font-size: 10 pt; background-color: #280000; border: 1 solid #c0c0c0">
</td>
<td width="39%" align="right" ><font size="2" color="#FFFFFF">No:</td>
<td><input name="no" type="text" size="2" style="color: #FFFFFF; font-family: arial, helvetica; font-size: 10 pt; background-color: #280000; border: 1 solid #c0c0c0">
</table>
</td>
</tr>
<tr>
<td>
<font size="2" color="#FFFFFF">Zip:</td>
<td>
<input type="text" name="zip" size="30" style="color: #FFFFFF; font-family: arial, helvetica; font-size: 10 pt; background-color: #280000; border: 1 solid #c0c0c0"></td>
</tr>
<tr>
<td>
<font size="2" color="#FFFFFF">City:</td>
<td>
<input name="city" type="text" id="zip" size="30" style="color: #FFFFFF; font-family: arial, helvetica; font-size: 10 pt; background-color: #280000; border: 1 solid #c0c0c0"></td>
</tr>
<tr>
<td>
<font size="2" color="#FFFFFF">Status</td>
<td>
<input name="status" type="text" size="30" style="color: #FFFFFF; font-family: arial, helvetica; font-size: 10 pt; background-color: #280000; border: 1 solid #c0c0c0"></td>
</tr>
<tr><td><font size="2" color="#FFFFFF">Type:</td>
<td><select name="type" style="color: #FFFFFF; font-family: arial, helvetica; font-size: 10 pt; background-color: #280000; border: 1 solid #c0c0c0">
<option value="apartment">Apartment</option>
<option value="house">House</option>
<option value="studio">Studio</option>
</select></td></tr>
<tr><td><font size="2" color="#FFFFFF">Area:</td>
<td><select name="area" style="color: #FFFFFF; font-family: arial, helvetica; font-size: 10 pt; background-color: #280000; border: 1 solid #c0c0c0">
<option value="amstelveen">Amstelveen</option>
<option value="amsterdam-centre">Amsterdam-Centre</option>
<option value="amsterdam-jordaan">Amsterdam-Jordaan</option>
<option value="amsterdam-oudwest">Amsterdam-Oud West</option>
<option value="amsterdam-pijp">Amsterdam-Pijp</option>
<option value="amsterdam-south">Amsterdam-South</option>
</select></td></tr>
<tr>
<td>
<font size="2" color="#FFFFFF">Available</td>
<td>
<table cellpadding="0" cellspacing="0" width="100%">
<td width="61%"><input name="available" type="text" size="10" style="color: #FFFFFF; font-family: arial, helvetica; font-size: 10 pt; background-color: #280000; border: 1 solid #c0c0c0">
</td>
<td width="39%" align="right" ><font size="2" color="#FFFFFF">To:</td>
<td><input name="tos" type="text" size="10" style="color: #FFFFFF; font-family: arial, helvetica; font-size: 10 pt; background-color: #280000; border: 1 solid #c0c0c0">
</table>
<tr><td><font size="2" color="#FFFFFF">Parking:</td>
<td><select name="parking" style="color: #FFFFFF; font-family: arial, helvetica; font-size: 10 pt; background-color: #280000; border: 1 solid #c0c0c0">
<option value="permit immediately">Permit immediately</option>
<option value="permit waiting list">Permit waiting list</option>
<option value="other see notes">Other see notes</option>
</select></td></tr>
<tr>
<tr><td><font size="2" color="#FFFFFF">Kitchen:</td>
<td><select name="kitchen" style="color: #FFFFFF; font-family: arial, helvetica; font-size: 10 pt; background-color: #280000; border: 1 solid #c0c0c0">
<option value="seperate">Seperate</option>
<option value="open">open</option>
<option value="half open">Half open</option>
</select></td></tr>
<tr><td><font size="2" color="#FFFFFF">Toilet:</td>
<td><select name="toilet" style="color: #FFFFFF; font-family: arial, helvetica; font-size: 10 pt; background-color: #280000; border: 1 solid #c0c0c0">
<option value="seperate">Seperate</option>
<option value="bathroom">In bathroom</option>
</select></td></tr>
<tr><td><font size="2" color="#FFFFFF">Furnised:</td>
<td><select name="furnised" style="color: #FFFFFF; font-family: arial, helvetica; font-size: 10 pt; background-color: #280000; border: 1 solid #c0c0c0">
<option value="complete">Complete</option>
<option value="unfurnised">Unfurnised</option>
<option value="other see notes">Other see notes</option>
</select></td></tr>
<tr>
<td><font size="2" color="#FFFFFF">Notes:</td>
<td><textarea name="notes" cols="24" style="color: #FFFFFF; font-family: arial, helvetica; font-size: 10 pt; background-color: #280000; border: 1 solid #c0c0c0"></textarea></td>
</tr>
<tr><td><input type=file name=file size=30></td></tr>
<td><input type="submit" name="Submit" value="Submit" style="color: #FFFFFF; font-family: arial, helvetica; font-size: 10 pt; background-color: #280000; border: 1 solid #c0c0c0">
</td>
</tr>
</table>
<?php
include("config.php");
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$insert = "INSERT INTO property (street, no, zip, city, status, type, area, available, tos, parking, kitchen, toilet, furnised, notes) VALUES ('$_POST[street]', '$_POST[no]', '$_POST[zip]', '$_POST[city]', '$_POST[status]', '$_POST[type]', '$_POST[area]', '$_POST[available]', '$_POST[tos]', '$_POST[parking]', '$_POST[kitchen]', '$_POST[toilet]', '$_POST[furnised]', '$_POST[notes]')";
mysql_query($insert) or die (mysql_error());
echo "<b>De gegevens zijn succesvol toegevoegd in de database</b>";
}
?>
</body>
</html>
upload script:
<link rel = "stylesheet" type = "text/css" href = "scheme.css">
<?
//#########################################################################
//######### Vul hieronder de waardes in voor het upload script ############
//#########################################################################
//de server waarop de database is geinstaleerd
$gebruiker = "naam"; //de gebruikersnaam van de database
$password = "password"; //het wachtwoord voor de database horende bij de ingevulde gebruiker
$database = "owndata_HP"; //de naam van de database
$toegestaan = array('jpg', 'gif', 'png', 'bmp'); //vul in deze array de toegestane extensies in gescheiden door een comma
$maxfilesize = 2; //vul hier de toegestane filesize in MB's in
$maxwidth = 10000; //de maximale breedte van het geuploade bestand
$maxheight = 10000; //de maximale hoogte van het geuploade bestand
$directory = "uploads/"; //de map waar de upload in moeten komen, inclusief slashes
$tabelnaam = "property"; //de naam van de tabel waar de upload in moet komen
//########################################################################
//################ Verander onder deze lijn niets ########################
//########################################################################
?>
<html>
<head>
<title>Upload Script:</title>
</head>
<body bgcolor="#99CCFF">
<?php
//verbinding maken met de database:
include ("config.php");
//code alleen uitvoeren wanneer er op submit is geklikt:
if(isset($_POST['submit'])) {
if($_FILES['file']['name'] == "") { echo("<script language=\"javascript\">alert('U bent vergeten een file te selecteren');</script>"); }else{
//extensies controleren:
$extensie = explode(".", $_FILES['file']['name']);
$extcount = count($toegestaan);
$extcount2 = count($toegestaan);
for($a=0;$a<$extcount;$a++) {
if(strtolower($extensie[1]) == $toegestaan[$a]) {
$extok = true;
$a = count($toegestaan);
}else{
$extok = false;
}
}
if($extok == false) {
echo("<script language=\"javascript\">alert('Deze extensie is niet geldig. Geldige extensies zijn:\\n");
for($b=0;$b<$extcount;$b++) {
$extup = strtoupper($toegestaan[$b]);
if($b == $extcount - 1) {
echo("$extup");
}else{
echo("$extup, ");
}
}
echo("');</script>");
}else{
//bestandsgrootte controleren:
$filesize = $_FILES['file']['size'];
$filesize2 = ("".ROUND($filesize / 1024, 1)." KB");
if($filesize > 1024) { $filesize2 = ("".ROUND($filesize2 / 1024, 1)." MB"); }
if($filesize > 1073741824) { $filesize2 = ("".ROUND($filesize2 / 1024 / 1024 / 1024, 1)." GB"); }
$maxfilesize2 = $maxfilesize * 1024 * 1024;
if($_FILES['file']['size'] > $maxfilesize2) {
echo("<script language=\"javascript\">alert('Dit bestand is te groot voor de upload\\nToegstaan: $maxfilesize MB');</script>");
}else{
//op dubbele files controleren:
$filenaam = $_FILES['file']['name'];
if(file_exists("$directory$filenaam")) {
echo("<script language=\"javascript\">alert('De bestandnaam ($filenaam) is al in gebruik');</script>");
}else{
//image size controleren:
$size = getimagesize($_FILES['file']['tmp_name']);
$width = $size[0];
$height = $size[1];
if($width > $maxwidth || $height > $maxheight) {
echo("<script language=\"javascript\">alert('Het formaat van dit bestand is niet correct.\\nMag max zijn: $maxwidth x $maxheight');</script>");
}else{
//Wanneer alles correct is, file uploaden:
$pad = $directory;
if(isset($_POST['submit'])) {
$query = "INSERT INTO $tabelnaam(filenaam)
VALUES('$pad$filenaam')";
$result = mysql_query($query);
copy($file, "$pad".$_FILES['file']['name']."");
echo("<center><font color=red>File uploaded...</font></center>");
}
}
}
}
}
}
}
//Het formulier:
//string opbouwen voor in help alertbox.
$string = ("Maximale Grootte: $maxfilesize MB\\nFormaat: $maxwidth x $maxheight\\nExtensies:");
for($c=0;$c<$extcount2;$c++) {
$extup2 = strtoupper($toegestaan[$c]);
if($c == $extcount2 - 1 ) {
$string .=("$extup2\\n");
}else{
$string .=("$extup2, ");
}
}
$string .=("Geen dubbele bestandsnamen.");
echo("<center><table border=0 style=\"border-style: double; border-color=red\">
<form action=$_SERVER[PHP_SELF] method=POST name=\"uploadform\" enctype=\"multipart/form-data\"><tr>
<td><input type=file name=file size=42></td></tr><tr>
<td><table width=100%><tr><td width=33%> </td><td align=center width=33%>");
?>
</body>
</html>
828 views