kiwajibo Posted August 15, 2006 Share Posted August 15, 2006 HELP Please..Since this is my first database that i have created i am a little bit lost at the moment.The thing is that i dont really know ho to copy the string "img/blabla.gif" into the database.It works to upload the images into the folder, but i dont know hoe to copy the string.And without the it i dosnt workI have tried lots of stuff, but i dosnt work :-(Well anyway, i have to learn more about php, very funWould apreciate some help// Tony<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>This is my test ADMIN-PAGE</title><meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/></head><body><?php if (isset($_GET['addtable'])): // User wants to add a New Release?><form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"><label>Type your joke here:<br /><input type="hidden" name="newreleases"/><input type="hidden" name="name"/><input type="file" name="imgsrc" rows="1" cols="40"/></input><br /><textarea name="catalog" rows="1" cols="40"></textarea><br /><textarea name="releasedate" rows="1" cols="40"></textarea><br /><textarea name="artist" rows="1" cols="40"></textarea><br /><textarea name="title" rows="1" cols="40"></textarea><br /><textarea name="description" rows="10" cols="40"></textarea><br /></label><br /><input type="submit" value="SUBMIT"/></form><?php else: // Default page display// Connect to the database server$dbcnx = @mysql_connect('localhost', 'root', '');if (!$dbcnx) {exit('<p>Unable to connect to the ' .'database server at this time.</p>');}// Select the releases databaseif (!@mysql_select_db('releases', $dbcnx)) {exit('<p>Unable to locate the releases ' .'database at this time.</p>');}// If a description has been submitted,// add it to the database.if (isset($_POST['newreleases'])) {$imgsrc = $_POST['imgsrc'];$catalog = $_POST['catalog'];$releasedate = $_POST['releasedate'];$artist = $_POST['artist'];$title = $_POST['title'];$description = $_POST['description'];$sql = "INSERT INTO newreleases SETimgsrc='$imgsrc',catalog='$catalog',releasedate='$releasedate',artist='$artist',title='$title',description='$description',inputdate=CURDATE()";if (@mysql_query($sql)) {echo '<p>Your description has been added.</p>';} else {echo '<p>Error adding submitted description: ' .mysql_error() . '</p>';}}// If a table has been deleted,// remove it from the database.if (isset($_GET['deletetable'])) {$newreleasesid = $_GET['deletetable'];$sql = "DELETE FROM newreleasesWHERE id=$newreleasesid";if (@mysql_query($sql)) {echo '<p>The table has been deleted.</p>';} else {echo '<p>Error deleting table: ' .mysql_error() . '</p>';}}echo '<p> Here are all the description tags in our database: </p>';// Request the ID and text of all the tables$result = @mysql_query('SELECT id, imgsrc, catalog, releasedate, artist, title, description FROM newreleases');if (!$result) {exit('<p>Error performing query: ' .mysql_error() . '</p>');}// Display the text of each table in a paragraph// with a "Delete this table" link next to each.while ($row = mysql_fetch_array($result)) {$newreleasesid = $row['id'];$imgsrc = $row['imgsrc'];$catalog = $row['catalog'];$releasedate = $row['releasedate'];$artist = $row['artist'];$title = $row['title'];$description = $row['description'];echo '<p>' . $imgsrc .'<br>' . $catalog .'<br>' . $releasedate .'<br>' . $artist .'<br>' . $title .'<br>' . $description .' <a href="' . $_SERVER['PHP_SELF'] .'?deletetable=' . $newreleasesid . '">' .'Delete this TABLE</a></p>';}// When clicked, this link will load this page// with the New Release submission form displayed.echo '<p><a href="' . $_SERVER['PHP_SELF'] .'?addtable=1">Add a New Release [table sql]!</a></p>';endif;if (isset($_POST['newreleases'])) { $file=$_FILES['imgsrc']['name']; $filetype=substr($file,-4); if($filetype=="jpeg"){ copy($_FILES['imgsrc']['tmp_name'],"images/".$_FILES['imgsrc']['name']) or die("Could not copy"); echo"<br>Upload Complete"; echo"<br>Name: ".$_FILES['imgsrc']['name'].""; echo"<br>Size: ".$_FILES['imgsrc']['size'].""; echo"<br>Type: ".$_FILES['imgsrc']['type']."<br>"; }elseif($filetype==".jpg"){ copy($_FILES['imgsrc']['tmp_name'],"images/".$_FILES['imgsrc']['name']) or die("Could not copy"); echo"<br>Upload Complete"; echo"<br>Name: ".$_FILES['imgsrc']['name'].""; echo"<br>Size: ".$_FILES['imgsrc']['size'].""; echo"<br>Type: ".$_FILES['imgsrc']['type']."<br>"; }elseif($filetype==".png"){ copy($_FILES['imgsrc']['tmp_name'],"images/".$_FILES['imgsrc']['name']) or die("Could not copy"); echo"<br>Upload Complete"; echo"<br>Name: ".$_FILES['imagefile']['name'].""; echo"<br>Size: ".$_FILES['imagefile']['size'].""; echo"<br>Type: ".$_FILES['imagefile']['type']."<br>"; }elseif($filetype==".gif"){ copy($_FILES['imgsrc']['tmp_name'],"images/".$_FILES['imgsrc']['name']) or die("Could not copy"); echo"<br>Upload Complete"; echo"<br>Name: ".$_FILES['imgsrc']['name'].""; echo"<br>Size: ".$_FILES['imgsrc']['size'].""; echo"<br>Type: ".$_FILES['imgsrc']['type']."<br>"; }else{ echo"<br>Upload Error"; echo"<br>Could Not Copy, Wrong Filetype (".$_FILES['imgsrc']['name'].")<br>"; }}?></body></html> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.