Hallo, Ich bin PHP Anfäger! Ich habe auch hier eine Problem. Vielleicht könntest ich hier auch geholfen werden.
Ich möchte Datensätze (ID'S) aus einem andere tabelle aus, in neue table schreiben lassen. Parameter übergeben. Ich weiß nicht was ich falsch mache ob ich Session varial benutzen muss oder nicht. jedoch bekomme ich fehlermeldung. Vielleicht könnte einer von Euch es für mich umschreiben.
Es soll auch bild hoch geladen werden.
"Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES ('8', 'on', 'on', 'on', 'Pipo del Sol', '2', 'F9865713', 'Wohnen am Mee' at line 5"
////////////////////////////<Form>//////////////////////////////////
<?php
$username = "root";
$password = "";
$host = "localhost";
$database = "prealstat";
$table = 'region';
mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
mysql_select_db($database) or die("Can not select the database: ".mysql_error());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//DE" "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>Zufügen</title>
<!---Rich Text Editor--->
<!----Images Upload----->
<?php
// img_up.php: Ein Bild hochladen
require_once 'connect.inc.php';
if (array_key_exists('img',$_FILES)) {
$tmpname = $_FILES['img']['tmp_name'];
$type = $_FILES['img']['type'];
$hndFile = fopen($tmpname, "r");
$data = addslashes(fread($hndFile, filesize($tmpname)));
$strQuery = "INSERT INTO images
(imgdata,imgtype) VALUES
('$data','$type')" ;
if (!mysql_query( $strQuery))
die(mysql_error());
}
?>
<!---------->
</head>
<body>
<table width="100%">
<tr>
<td> </td>
</tr>
<tr>
<td align="center"><h1>Objekt Zufügen</h1></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<table width="100%" bgcolor="#999999">
<tr>
<td width="22%" height="401" valign="top">
<table width="100%" border="0">
<tr>
<td> </td>
</tr>
</table>
</td>
<td width="25%" valign="top">
<table bgcolor="#CC3366" border="0">
<tr><td> </td></tr>
<tr bgcolor="#CCCCCC">
<td align="right" bgcolor="#CCCCCC"><b>Objekt</b> <br /></td>
<td bgcolor="#CCCCCC">
<!-----------Form--------------->
<form method="post" action="connect_post.php" enctype="multipart/form-data">
<select name="obj">
<option>Objekt wählen</option>
<?php
$sql = "SELECT `objID`, `obj_art` FROM tbl_object";
$result = mysql_query($sql)
or die("<font color=\"#FF0000\">Query Error</FONT>".mysql_error());
while ( $row = mysql_fetch_array($result) ){
echo '<OPTION
value="'.$row['objID'].'">'.$row['obj_art'].'</OPTION>'."\r\n";
}
?>
</select></td>
</tr>
<tr><td bgcolor="#666666"> </td></tr>
<tr>
<td align="right" bgcolor="#CCCCCC"><b>Region</b> </td>
<td bgcolor="#CCCCCC"><SELECT id="" name="regi_type" style="width:150px"><option>Region wählen</option>
<?php
$sql = "SELECT `regID`, `regiName` FROM region";
$result = mysql_query($sql)
or die("<font color=\"#FF0000\">Query Error</FONT>".mysql_error());
while ( $row = mysql_fetch_array($result) ){
echo '<OPTION
value="'.$row['regID'].'">'.$row['regiName'].'</OPTION>'."\r\n";
}
?>
</SELECT></td>
</tr>
<tr><td bgcolor="#666666"> </td></tr>
<tr bgcolor="#CCCCCC"><td align="right" bgcolor="#CCCCCC"><b>Ort</b> </td>
<td bgcolor="#CCCCCC"><SELECT id="" name="obj_ort" style="width:150px"><option>Ort wählen</option>
<?php
$sql = "SELECT `ortID`, `Name` FROM `tbl_ort`";
$result = mysql_query($sql)
or die("<font color=\"#FF0000\">Query Error</FONT>".mysql_error());
while ( $row = mysql_fetch_array($result) ){
echo '<OPTION
value="'.$row['ortID'].'">'.$row['Name'].'</OPTION>'."\r\n";
}
?>
</SELECT></td>
</tr>
<tr>
<td bgcolor="#666666"> </td>
</tr>
<tr bgcolor="#CCCCCC">
<td width="292" bgcolor="#CCCCCC"><b>Objekt Name</b> <input name="ob_name" border="1" style="background-color:#FFF" type="text" size="80" maxlength="100000" accept="text/*"></td>
<td width="108" bgcolor="#CCCCCC" bordercolor="#000000"><b>Obj.Nummer</b>
<input name="obnr" border="1" style="background-color:#FFF" type="text" size="10" maxlength="10" accept="text/*"></td>
</tr>
<tr><td bgcolor="#666666"> </td></tr>
<tr>
<td bgcolor="#CCCCCC" align="center"><b>Anzahl der Zimmer</b></td><td align="center" bgcolor="#CCCCCC"><b>Anzahl d. Zimmer</b><br /> <input name="rnr" border="1" style="background-color:#FFF" type="text" size="10" maxlength="2" accept="text/*"></td>
</tr>
<tr><td bgcolor="#666666"> </td></tr>
<tr><td bgcolor="#CCCCCC" align="center"><b>Wohnfläche</b></td><td align="center"><b>Wohnfläche</b><br /><input name="wfla" border="1" style="background-color:#FFF" type="text" size="15" maxlength="6" accept="text/*"> m<sup>2</sup></td></tr>
<tr><td bgcolor="#666666"> </td></tr>
<tr><td bgcolor="#CCCCCC" align="center"><b>EXTRAS</b></td><td align="center" bgcolor="#CCCCCC"><b>Pool</b><br /><input type="checkbox" name="pool"><br /><br /><b>Strandnähe</b><br /><input type="checkbox" name="stra"><br /><br /><b>Meerblick</b><br /><input type="checkbox" name="meerb"></td></tr>
<tr>
<td bgcolor="#CCCCCC"><br /><b>Überschrift</b> <input name="obstext" border="1" style="background-color:#FFF" type="text" size="80" maxlength="100000" accept="text/*"></td>
<td> </td>
</tr>
<tr><td bgcolor="#666666"> </td></tr>
<tr>
<td align="right" bgcolor="#CCCCCC"><b>Preis</b> </td>
<td align="center" bgcolor="#CCCCCC"> <input name="preis" border="1" style="background-color:#FFF" type="text" size="10" maxlength="7" accept="text/*"> €</td>
</tr>
<tr><td bgcolor="#666666" align="center"><font size="+2" color="#FFFFFF">Beschreibung</font></td></tr>
<tr>
<td>
<p>
<div>
<textarea id="txrea" name="txrea" rows="15" cols="80" style="width: 80%">
</textarea>
</div>
<br />
<input type="submit" name="save" value="Submit" />
<input type="reset" name="reset" value="Reset" />
</div>
</p></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</td>
<!---->
<td width="6%" valign="top">
<table>
<tr>
<td> </td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</td>
<!----->
<td width="33%" valign="top">
<table>
<tr>
<td><h1>Bilder Upload</h1></td>
</tr>
<tr>
<td height="48">
<p>Foto 1<br>
<input name="bild1" type="file" size="50" maxlength="100000" accept="text/*">
</p>
</td>
</tr>
<tr>
<td>
<p>Foto 2<br>
<input name="bild2" type="file" size="50" maxlength="100000" accept="text/*">
</p>
</td>
</tr>
<tr>
<td>
<p>Foto 3<br>
<input name="bild3" type="file" size="50" maxlength="100000" accept="text/*">
</p>
</td>
</tr>
<tr>
<td>
<p>Foto 4<br>
<input name="bild4" type="file" size="50" maxlength="100000" accept="text/*">
</p>
</td>
</tr>
<tr>
<td>
<p>Foto 5<br>
<input name="bild5" type="file" size="50" maxlength="100000" accept="text/*">
</p>
</td>
</tr>
<tr bgcolor="#CCCCCC">
<td>
<p>Video<br>
<input name="video" type="file" size="50" maxlength="100000" accept="text/*">
</p>
<p></p>
</form>
</td>
</tr>
</table>
</td>
<td width="14%" valign="top">
<table width="65%" border="0">
<tr>
<td> </td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
///////////////////////////Ende///////////////////////////////////
///////////////////Insert mit Select///////////////////////////
<?php
$con = mysql_connect("localhost","ab","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("prealstat", $con);
$sql="INSERT INTO tbl_object (`zim_zahl`, `strand`, `pool`, `meer`, `objName`, `obj_art`, `objNummer`, `ObjHText`, `objPreis`, `objLText`, `wfla`, `regID`, `ortID`)
select tbl_object.*, bl_ort.*, region.* FROM `tbl_object.objID`, `bl_ort.ortID`, `region.regID` WHERE tbl_object.objID = objID AND region.regiID=regID AND bl_ort.ortID = ortID
VALUES
('$_POST[rnr]', '$_POST[stra]', '$_POST[pool]', '$_POST[meerb]', '$_POST[ob_name]', '$_POST[obj]', '$_POST[obnr]', '$_POST[obstext]', '$_POST[preis]', '$_POST[txrea]', '$_POST[wfla]','$_POST[regi_type]', '$_POST[obj_ort]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>