upload/instert into velden blijven leeg
gwenn - 28/02/2007 16:18 (laatste wijziging 28/02/2007 16:45)
Grafische interesse
Dit is mijn upload script nu het lukt me een mijn file te uploaden en deze id.Jpg te geven maar nu komen er in mijn database geen gegevens hij maakt wel een regel aan maar mijn velden blijven leeg.
Iemand enig idee wat ik verkeerd doe?
<?php
session_start();
if (isset($_SESSION['user_id']) && $_SESSION['user_id']>0) {
include("header.php");
echo'<div id="left"><h1>Stock wijzigen</h1></div><div id="right">';
include("menu.php");
echo'</div><br /><br /><br /><br />';
if(IsSet($_POST['submit']) && $_FILES['userfile']['size'] > 0) {
if(!get_magic_quotes_gpc()) {
$fileName = addslashes($fileName);
$content = addslashes($content);
}
// Maak query om gegevens in tabel te stoppen
$query = "INSERT INTO stock (id) VALUES
(NULL)";
// Voer query uit
mysql_query($query) or die ("query mislukt");
// De ID van deze insert
$id = mysql_insert_id();
echo "Uw bericht is succesvol gepost u kan het nu gaan bekijken. <META HTTP-EQUIV=\"REFRESH\" CONTENT=\"2; URL=index.php\">";
$uploadDir = 'stock/';
$file = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fileName = $file;
$fileName = $id.".jpg";
// the files will be saved in filePath
$content = $uploadDir . $fileName;
// move the files to the specified directory
// if the upload directory is not writable or
// something else went wrong $result will be false
$result = move_uploaded_file($tmpName, $content);
if (!$result) {
echo "Error uploading file";
exit;
}
} else {
$query = "INSERT INTO stock (id, soort, prijs, details, kweker, lengte, video, name, size, type, content) VALUES (LAST_INSERT_ID(), '$_POST[soort]', '$_POST[prijs]', '$_POST[details]', '$_POST[kweker]', '$_POST[lengte]', '$fileName', '$fileSize', '$fileType', '$content')";
echo"
<FORM ACTION=\"stock_nieuw.php\" METHOD=\"post\" enctype=\"multipart/form-data\">
<table>
<tr>
<td><b>Soort:</b></td><td><INPUT TYPE=\"text\" NAME=\"soort\" SIZE=30 MAXLENGTH=150></td>
</tr>
<tr>
<td><b>Prijs in Euro:</b></td><td><INPUT TYPE=\"text\" NAME=\"prijs\" SIZE=30 MAXLENGTH=150></td>
</tr>
<tr>
<td><b>Details:</b></td><td><INPUT TYPE=\"text\" NAME=\"details\" SIZE=30 MAXLENGTH=150></td>
</tr>
<tr>
<td><b>Kweker:</b></td><td><INPUT TYPE=\"text\" NAME=\"kweker\" SIZE=30 MAXLENGTH=150></td>
</tr>
<tr>
<td><b>Lengte in cm:</b></td><td><INPUT TYPE=\"text\" NAME=\"lengte\" SIZE=30 MAXLENGTH=150></td>
</tr>
<tr>
<td><b>Foto:</b></td><td><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"2000000\">
<INPUT TYPE=\"file\" NAME=\"userfile\" SIZE=30 MAXLENGTH=150 id=\"userfile\"></td>
</tr>
<tr>
<td><input type=\"submit\" value=\"toevoegen\" name=\"submit\"></td>
</tr>
</table>
</FORM> ";
}
include("footer.php");
}
?>
<?php
if ( isset ( $_SESSION [ 'user_id' ] ) && $_SESSION [ 'user_id' ] > 0 ) {
include ( "header.php" ) ;
echo '<div id="left"><h1>Stock wijzigen</h1></div><div id="right">' ;
include ( "menu.php" ) ;
echo '</div><br /><br /><br /><br />' ;
if ( IsSet ( $_POST [ 'submit' ] ) && $_FILES [ 'userfile' ] [ 'size' ] > 0 ) {
}
// Maak query om gegevens in tabel te stoppen
$query = "INSERT INTO stock (id) VALUES
(NULL)" ;
// Voer query uit
// De ID van deze insert
echo "Uw bericht is succesvol gepost u kan het nu gaan bekijken. <META HTTP-EQUIV=\" REFRESH\" CONTENT=\" 2; URL=index.php\" >" ;
$uploadDir = 'stock/' ;
$file = $_FILES [ 'userfile' ] [ 'name' ] ;
$tmpName = $_FILES [ 'userfile' ] [ 'tmp_name' ] ;
$fileSize = $_FILES [ 'userfile' ] [ 'size' ] ;
$fileType = $_FILES [ 'userfile' ] [ 'type' ] ;
$fileName = $file ;
$fileName = $id . ".jpg" ;
// the files will be saved in filePath
$content = $uploadDir . $fileName ;
// move the files to the specified directory
// if the upload directory is not writable or
// something else went wrong $result will be false
if ( ! $result ) {
echo "Error uploading file" ; }
} else {
$query = "INSERT INTO stock (id, soort, prijs, details, kweker, lengte, video, name, size, type, content) VALUES (LAST_INSERT_ID(), '$_POST[soort] ', '$_POST[prijs] ', '$_POST[details] ', '$_POST[kweker] ', '$_POST[lengte] ', '$fileName ', '$fileSize ', '$fileType ', '$content ')" ;
<FORM ACTION=\" stock_nieuw.php\" METHOD=\" post\" enctype=\" multipart/form-data\" >
<table>
<tr>
<td><b>Soort:</b></td><td><INPUT TYPE=\" text\" NAME=\" soort\" SIZE=30 MAXLENGTH=150></td>
</tr>
<tr>
<td><b>Prijs in Euro:</b></td><td><INPUT TYPE=\" text\" NAME=\" prijs\" SIZE=30 MAXLENGTH=150></td>
</tr>
<tr>
<td><b>Details:</b></td><td><INPUT TYPE=\" text\" NAME=\" details\" SIZE=30 MAXLENGTH=150></td>
</tr>
<tr>
<td><b>Kweker:</b></td><td><INPUT TYPE=\" text\" NAME=\" kweker\" SIZE=30 MAXLENGTH=150></td>
</tr>
<tr>
<td><b>Lengte in cm:</b></td><td><INPUT TYPE=\" text\" NAME=\" lengte\" SIZE=30 MAXLENGTH=150></td>
</tr>
<tr>
<td><b>Foto:</b></td><td><input type=\" hidden\" name=\" MAX_FILE_SIZE\" value=\" 2000000\" >
<INPUT TYPE=\" file\" NAME=\" userfile\" SIZE=30 MAXLENGTH=150 id=\" userfile\" ></td>
</tr>
<tr>
<td><input type=\" submit\" value=\" toevoegen\" name=\" submit\" ></td>
</tr>
</table>
</FORM> " ;
}
include ( "footer.php" ) ;
}
?>
5 antwoorden
Gesponsorde links
Voldemort - 28/02/2007 16:26
PHP ver gevorderde
Je haalt het id op van een net ingevoerde lege rij, maar dan later in de code insert je nogmaals. Ik denk dat het zo zit:
Bij de tweede INSERT query bij de tabel stock:
1) UPDATE gebruiken op de net ingevoerde rij
2) Variablen buiten de quotes halen
gwenn - 28/02/2007 16:27 (laatste wijziging 28/02/2007 16:31)
Grafische interesse
ok maar hoe doe ik die update juist voorbeeldje??
Zoiets?
<?php
$query = "UPDATE stock SET soort='".$_POST['soort']."', prijs='".$_POST['prijs']."', details='".$_POST['details']."', kweker='".$_POST['kweker']."', lengte='".$_POST['lengte']."', '$fileName', '$fileSize', '$fileType', '$content' ";
mysql_query($query) or die(mysql_error());
?>
<?php
$query = "UPDATE stock SET soort='" . $_POST [ 'soort' ] . "', prijs='" . $_POST [ 'prijs' ] . "', details='" . $_POST [ 'details' ] . "', kweker='" . $_POST [ 'kweker' ] . "', lengte='" . $_POST [ 'lengte' ] . "', '$fileName ', '$fileSize ', '$fileType ', '$content ' " ;
?>
roelh - 28/02/2007 16:41
PHP gevorderde
lengte='".$_POST['lengte']."', '$fileName', '$fileSize', '$fileType', '$content'
lengte= '".$_POST[' lengte']."' , '$fileName' , '$fileSize' , '$fileType' , '$content'
Tot lengte is het goed, maar daarna geef je geen velden meer aan?
gwenn - 28/02/2007 16:44 (laatste wijziging 28/02/2007 16:45)
Grafische interesse
Mss moet je mijn code toch is beter bekijken..
SQL
CREATE TABLE `stock` (
`id` smallint( 10 ) NOT NULL AUTO_INCREMENT ,
`soort` varchar( 250 ) NOT NULL default '',
`prijs` varchar( 250 ) NOT NULL default '',
`details` varchar( 250 ) NOT NULL default '',
`kweker` varchar( 250 ) NOT NULL default '',
`lengte` varchar( 250 ) NOT NULL default '',
`video` varchar( 250 ) NOT NULL default '',
`name` VARCHAR(30) NOT NULL,
`type` VARCHAR(30) NOT NULL,
`size` INT NOT NULL,
`content` MEDIUMBLOB NOT NULL,
PRIMARY KEY ( `id` )
) TYPE = MYISAM ;
<tr>
<td><b>Foto:</b></td><td><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"2000000\">
<INPUT TYPE=\"file\" NAME=\"userfile\" SIZE=30 MAXLENGTH=150 id=\"userfile\"></td>
</tr>
< tr>
< td>< b> Foto:</ b></ td>< td>< input type= \"hidden\" name=\" MAX_FILE_SIZE\" value=\" 2000000\" >
<INPUT TYPE=\" file\" NAME=\" userfile\" SIZE=30 MAXLENGTH=150 id=\" userfile\" ></td>
</tr>
Gesponsorde links
Dit onderwerp is gesloten .