Jump to content

Upload with database


incorrect

Recommended Posts

Hi at first I say sorry for my bad english :D

 

ok i have wrote a script to upload pictures an save them in a folder of my server! So long it works! But then I like to save the file of the picture or the name in a database!

Is Somebody of you able to help me with this problem? I wont present the script hear because I think it would be not helpful =)

so maybe you can post a short script what do what i want :D

thank you

Freddy

Link to comment
Share on other sites

Why not just create a new table in your database and simply record image uploads that way. For example a new image will create a new row in the table (the table may consist of: id;  IP/Username; imageurl) - To insert such data just do a simple SQL insert with the script data obviously in some PHP after your script. Therefore you have a record of all images uploaded.

 

To view your results just do a SQL Select statement to show your results in a table or so forth...

 

I hope that helps in some way if not im sure youl find the help you need sooner or later :)

 

Link to comment
Share on other sites

thank you for your answer!

but i forgot to tell you, that i have a table in my database where it saves other information about the picture, which is about a think you like to sell, a car or something like this. So i have a place where i can save this but i dont know how to upload the picture AND save the file where it had been save in the database!

is it now clearer what i like to have =)

thank you for your help

Link to comment
Share on other sites

? I wont present the script hear because I think it would be not helpful =)

I (and most likely others too) disagree. Try and post what you have so far for your upload script and people on the forum can help you / advice you how to correct or improve the script.

 

but i forgot to tell you, that i have a table in my database where it saves other information about the picture,

What does the table look like?

 

Link to comment
Share on other sites

At first i have to say that I'm german so dont wonder why i have german expressions in the script!

 

CREATE TABLE IF NOT EXISTS `artikel` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `hauptkat` int(100) NOT NULL,
  `nebenkat` int(100) NOT NULL,
  `name` varchar(25) CHARACTER SET utf8 NOT NULL,
  `beschreibung` varchar(200) CHARACTER SET utf8 NOT NULL,
  `bild` varchar(100) CHARACTER SET utf8 NOT NULL,
  `preis` int(200) NOT NULL,
  `date` int(200) NOT NULL,
  `user` varchar(100) CHARACTER SET utf8 NOT NULL,
  `zustand` varchar(100) CHARACTER SET utf8 NOT NULL,
  `bild2` varchar(100) CHARACTER SET utf8 NOT NULL,
  `bild3` varchar(100) CHARACTER SET utf8 NOT NULL,
  `bild4` varchar(100) CHARACTER SET utf8 NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=380 ;

this is the sql script of my table!

and bild , bild2 , bild3 , bild4 have to be the file where the picture is saved!

and my upload script looks like  this:

 

$_GET['kategorie'];
	echo '<h1>Anzeige einstellen</h1>';

	echo '<form action="index.php?seite=artikeleinstellen2" enctype="multipart/form-data" method="POST"><br/>';
		echo 'Kategorie:<br/>';

			$ksql= "SELECT * FROM menu WHERE nebenkat=0";
			$kresult = mysql_query($ksql);
	//SELECT START
		echo '<select name="kategorie">';
			while ( $kat = mysql_fetch_array($kresult) ){
			//Hauptkategorie
				echo '<optgroup label="'.$kat[3].'">';
				$hk = $kat[1];
				$uksql = "SELECT * FROM menu WHERE hauptkat=$hk AND nebenkat!=0";
				$ukresult = mysql_query($uksql);
					while ( $u_kat = mysql_fetch_array($ukresult) ){
				//Nebenkategorie
						echo '<option value="'.$u_kat[1].'-'.$u_kat[2].'">'.$u_kat[3].'</option>';
					}
				echo '</optgroup>';
			}
		echo '</select>';	
	//SELECT ENDE
		echo '<br/><br/>';

		echo 'Zustand:  ';
		echo '<select name="zustand">';
			echo '<option value="Neu">Neu</option>
				<option value="Gebraucht">Gebraucht</option>';
		echo '</select><br/><br/>';

		echo 'Artikelname<br/>';
		echo '<input type="text" size="50" maxlength="50" name="name" /><br/><br/>';

		echo 'gewünschter Preis:<br/>';
		echo '<input type="text" size="10" maxlength="20" name="preis" /> EURO<br><br>';

		echo 'Bild 1*:<br/>';
		echo '<input type="file" size="50" maxlength="150" name="bild1" /><br/>';

		echo 'Bild 2*:<br/>';
		echo '<input type="file" size="50" maxlength="150" name="bild2" /><br/>';

		echo 'Bild 3*:<br/>';
		echo '<input type="file" size="50" maxlength="150" name="bild3" /><br/>';

		echo 'Bild 4*:<br/>';
		echo '<input type="file" size="50" maxlength="150" name="bild4" /><br/>';

		echo '<br/>';

		echo 'genaue Beschreibung:<br/>';
		echo '<textarea name="beschreibung" cols="50" rows="10"></textarea><br/>';

		$zeit = time (); // Aktuelle Zeit in Sekunden

		$datum = getdate ( $zeit );
		$date = $datum[0];
		echo '<input name="date" value="'.$date.'" class="versteckt" /><br/>';

	echo '<input type="submit" value="Artikel einstellen">';
	echo '</form>';

this is the first part and the second part is like this:

$eintrag = "INSERT INTO artikel (hauptkat, nebenkat, name, preis, beschreibung, date, user, zustand)
		VALUES ('$hkat', '$nkat', '$name', '$preis', '$beschreibung', '$date', '$user', '$zustand')";

and I know the comment to upload the picture its:

move_uploaded_file

but now I dont know how to deal with this!

ok?

Link to comment
Share on other sites

yes bild = picture

 

and it right i have this 4 times!

and i send it with $eintragen

 

if i use $_FILES or not i dont know beacause i dont know how to use it xD

i dont know how to save the file and give him a name!

I know how to save the file in the database!

you know what i mean? :D

Link to comment
Share on other sites

if i use $_FILES or not i dont know beacause i dont know how to use it xD

I find this sentence confusing do you or do you not use $_FILES ? If you don't know how to use it I suggest you check the manual with the link and maybe lookup some php file upload tutorials

 

I know how to save the file in the database!

you know what i mean? :D

  :confused: How do you mean that? can you elaborate?
Link to comment
Share on other sites

ok sorry =)

you told about upload tutorials!

but i searched for some but don't find anything whats like the thnig i like to have =) so maybe you can post a link to a verry nice tutorial and i will check this =)

ok? :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.