Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ldenman

macrumors regular
Original poster
Jul 20, 2005
229
0
Basically this is what i want:

A Form Where the User Inputs an Image Url.
After Submitting, The Image is Displayed.
The image url is going to be placed inside a database.

Thanks.
 
to clarify, I submit a URL which is then stored in a database, or the image file itself gets stored in the database?

Let me know and I can probably pull up some PHP code I have from leftover projects and post it here.
 
What i want is like, you enter in url to the image.
The url gets placed inside the database.
When the page calls the database, i want the image to be shown, not the address.
 
So to insert a URL into a database...
insert.php
PHP:
<html>
<head>
	<title>URL inserter</title>
	<style>
	body,td{
		font-family: verdana;
		font-size: 12px;
		color: black
		background: white;
	}
	input{
		font-family: verdana;
		font-size: 12px;
	}
	</style>
</head>
<body>
<b>URL inserter - <a href="http://www.rilet.com" target="_blank">www.rilet.com</a></b><br /><br />
<?
if(!empty($_POST['address']))
{
	@extract($_POST);
	$address = mysql_real_escape_string("$address");
	$name = mysql_real_escape_string("$name");
	
	if ($address == "http://www.site.com/image.jpg" || empty($name)){
		echo"Please make sure you have entered a valid name and URL.";
	}else{

		//insert into database...
		require("database.php");

		mysql_query("INSERT INTO image_addresses (name, address) VALUES('$name', '$address') ")
		or die(mysql_error());

		//Get the ID of the inserted image...

		$result = mysql_query("SELECT id FROM image_addresses WHERE name='$name' ORDER BY id DESC LIMIT 1")
		or die(mysql_error());

		while($row = mysql_fetch_array( $result )) {
		$id = $row['id'];
		print 'The image URL has been <a href="get_image.php?id='. $id .'">successfully added</a> to the database.<br><br>';
		}
	}
}
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
URL:<input type="text" value="http://www.site.com/image.jpg" name="address" maxlength="100" size="32">
Name:<input type="text" value="" name="name" maxlength="35"><br />
<input type="submit" value="Submit" onClick="this.value='Please wait...';">
</form>
</body></html>

get_image.php
PHP:
<html>
<head>
	<title>Image viewer</title>
	<style>
	body,td{
		font-family: verdana;
		font-size: 12px;
		color: black
		background: white;
	}
	input{
		font-family: verdana;
		font-size: 12px;
	}
	</style>
</head>
<body>

<form action="<?=$_SERVER['PHP_SELF']?>" method="get">
Image<select name="id">
<?php
require("database.php");

	$result = mysql_query("SELECT name,id FROM image_addresses")
	or die(mysql_error());

	while($row = mysql_fetch_array( $result )) {
		$name = $row['name'];
		$id = $row['id'];
	print'<option value="'.$id.'">'.$name.'</option>';
	}
?>
</select>
<input type="submit" value="View" onClick="this.value='Please wait...';">
</form>

<?php
@$id = $_GET['id'];
if (!empty($id)){
	
	// Get all the data from image_addresses
	$result = mysql_query("SELECT name,address FROM image_addresses WHERE id='$id'")
	or die(mysql_error());

	while($row = mysql_fetch_array( $result )) {
		$name = $row['name'];
		$address = $row['address'];
	print "$name ($address)<br><br>";
	print'<img src="'.$address.'" alt="'.$name.'" style="max-width:100%;">';
	}
}
?>
</body></html>
Database.php
PHP:
<?php
$username = "";
$password = "";
$hostname = "localhost";
$db = "";
	
$database = mysql_connect($hostname, $username, $password) 
	or die("Unable to connect to MySQL");
mysql_select_db($db, $database);

?>
MySQL Table:
PHP:
CREATE TABLE `image_addresses` (
  `id` int(4) NOT NULL auto_increment,
  `name` varchar(35) NOT NULL default '',
  `address` varchar(100) NOT NULL default '',
  KEY `id` (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;
 
I don't want to edit the above post, in case vBulletin messes the post up, but there's a demo at http://442.rilet.com/test/1/

It's pretty basic what I did, no way to delete an entry, but it gets the job done (if I understood you correctly). if you wanted something else, let me know...I'm pretty bored right now.

P.S. Cool! someone used it!
 
thejadedmonkey said:
P.S. Cool! someone used it!

I put in the three logos because, somehow, I just couldn't resist. What fun! :D

To the original poster, though, hot-linking offsite isn't always a well-regarded behavior. It'd be a good idea to remember that if that was your original intention. ;)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.