Forum Moderators: coopster

Message Too Old, No Replies

Trouble with an image upload script

         

jyogit

4:57 pm on Feb 15, 2008 (gmt 0)

10+ Year Member




System: The following 6 messages were cut out of thread at: http://www.webmasterworld.com/php/3572560.htm [webmasterworld.com] by jatar_k - 6:19 pm on Feb. 15, 2008 (est -5)


hey wheelie do u think u could help me with my similar problem?

ill go get the original post for you.

jyogit

4:58 pm on Feb 15, 2008 (gmt 0)

10+ Year Member



hey wheelie do u think u could help me with my similar problem?

ill go get the original post for you.
i have the begining of what i need which is this...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "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=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-color: #000000;
}
body,td,th {
color: #9900FF;

}
-->
</style>
<div align="center">
<?php
$con = mysql_connect("mysql#*$!#*$!#*$!#*$!#*$!", "#*$!#*$!#*$!#*$!", "#*$!#*$!#*$!x");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("#*$!#*$!#*$!", $con);

$result = mysql_query("SELECT * FROM geri ORDER BY cd");

while($row = mysql_fetch_array($result)){
echo $row['cd'];
echo "<br />";

}

mysql_close($con);
?></head>

<body>

<div align="center"><tr><td><img src="<?= $row[cd] ?>"></td></tr></div>
</body>
</html>

i left in the echo $row['cd']; line just to check that im getting the right information back from the database and thats fine.

it adds a blank image box though instead of an image.
and i want to see all images in a row underneath each other in the site.

cant seem to figure that bit out yet.

the image name in the database should be all i need to show the image surely?
ive submitted the full path and the local path but i still get a blank image placed on screen.

heres what im getting when i goto the page... <snip>

ive had a few suggestions from someone but i still cant get it to work.

the images are all the same size and will fit into a table down the middle of the site.

hope someone can help

jeff

wheelie34

7:20 pm on Feb 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



what string does echo $row['cd']; produce

jyogit

7:48 pm on Feb 15, 2008 (gmt 0)

10+ Year Member



the string produces whatever string i add in the database which has been /images/redress.jpg

so that should be what it adds in the img src line yes?

wheelie34

9:02 pm on Feb 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try this


<?php
$con = mysql_connect("mysql#*$!#*$!#*$!#*$!#*$!", "#*$!#*$!#*$!#*$!", "#*$!#*$!#*$!x");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("#*$!#*$!#*$!", $con);

$result = mysql_query("SELECT * FROM geri ORDER BY cd");
while($row = mysql_fetch_array($result)){
$x = $row['cd'];
print "<table width=\"100%\" border=\"0\">
<tr>
<td align=\"center\"><img src=\"$x\"></td>
</tr>
</table>";
}
mysql_close($con);
?>

If the images dont show up, right click on the place holder where they should be and click properties and look at the path, see if it does point to the actual image

jyogit

10:16 pm on Feb 15, 2008 (gmt 0)

10+ Year Member



thank you u are a true star.

that works straight away.
i can now get on and do some serious work on the database entries.

ill now take a close look at it and see where i was going wrong.

jeff

wheelie34

9:27 am on Feb 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



as you are calling multiple rows from the database you need to print them during the while loop, you were only echoing the string during the loop which would have given the correct details BUT not linking to any images.

Your table bits were after everything has finished which would have only printed the last rows data.


$x = $row['cd'];
print "<table width=\"100%\" border=\"0\">
<tr>
<td align=\"center\"><img src=\"$x\"></td>
</tr>
</table>";

The above lays out each row (image) in its own table, you could get a bit fancier and print the opening table bits before the loop and each <td> during the loop then close the table afterwards.

jyogit

3:55 pm on Feb 16, 2008 (gmt 0)

10+ Year Member



thanks wheelie

if you have the time could you also tell me how to use a link-button to alter the table name or catagory without having to make a new page for each catagory?

thats my next project..... lol

wheelie34

7:47 pm on Feb 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



sure but you'll have to make a start so we can see how to help.

First thoughts though, if I understand your question, would be category links (buttons or text) passing a variable to a template page


<a href=template.php?category=$x>Visit Category X</a>

and use the same variable in your MySql statement to select data from that category


select * from table where column=$x

Is that what you are looking for

jyogit

1:19 pm on Feb 17, 2008 (gmt 0)

10+ Year Member



heres what i have so far.
i have left the links blank and tried what you wrote in the above reply.

do i add the link back to the page itself?
and can i add select *from geri where column=$x order by $x ?
as i need to alphabetise the images before adding them to teh page.

if you could point me in teh right direction as to which bits to change...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "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=iso-8859-1" />
<title>SPICE GIRLS COLLECTION ... THIS IS MY COLLECTION OF MEMORABILIA.</title>
<style type="text/css">
<!--
body,td,th {
color: #000000;
}
body {
background-color: #DC718F;
}
.style2 {color: #FFFFFF}
.style3 {font-size: 12px}
-->
</style></head>

<body>
<table width="900" border="0" align="center" bgcolor="#FFFFFF">
<tr>
<td><p align="center"><?php
require("topbanner.php")

?>&nbsp;</td>
</tr>
<tr>
<td><p align="center"><?php
require("topmenu.php")

?>&nbsp;</td>
</tr>
<tr>
<td><table width="900" height="700" border="0">
<tr>
<td width="170" height="2">&nbsp;</td>
<td width="550" height="2">&nbsp;</td>
<td width="170" height="2">&nbsp;</td>
</tr>
<tr>
<td width="170" height="700" align="center" valign="top" bgcolor="#FFFFFF"><div align="left">
<table width="170" height="700" border="0" background="images/COLLECTION CDS/WEBSIDEBANNER600.jpg">
<tr>
<td height="220">&nbsp;</td>
</tr>
<tr>
<td height="40"><div align="center">
<h3 class="style2"><strong>CATEGORY</strong></h3>
</div></td>
</tr>
<tr>
<td height="400" valign="top"><div align="center">
<p>&nbsp;</p>
<p><a href="#">spice girls</a></p>
<p><a href="#">geri</a></p>
</div>
<p align="center"><a href="#">victoria</a></p>
<p align="center"><a href="#">emma</a></p>
<p align="center"><a href="#">mel b</a></p>
<p align="center"><a href="#">mel c</a></p></td>
</tr>
</table>
</div></td>
<td width="550" valign="top"><div align="center">
<h2>WELCOME TO MY COLLECTION PAGES</h2>
<p class="style3"><strong>FIRST SELECT THE BAND OR BAND MEMBER YOU WANT</strong></p>
<p class="style3"><strong>TO VIEW ITEMS OF.</strong></p>
<p class="style3"><strong>THEN CLICK ON THE ITEM CATEGORY ON THE RIGHT </strong></p>
<p class="style3"><strong>TO VIEW THE ITEMS </strong></p>
<p class="style3">&nbsp;</p>
<table width="500" border="0" align="center">
<tr>
<td><div align="center"><?php
$con = mysql_connect("mysql#*$!#*$!#*$!#*$!#*$!x", "#*$!#*$!#*$!x", "#*$!#*$!#*$!#*$!x");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("#*$!#*$!#*$!#*$!xx", $con);

$result = mysql_query("SELECT * FROM geri ORDER BY cd");
while($row = mysql_fetch_array($result)){
$x = $row['cd'];
print "<table width=\"100%\" border=\"0\">
<tr>
<td align=\"center\"><img src=\"$x\"></td>
</tr>
</table>";
}
mysql_close($con);
?></div></td>
</tr>
</table>
<p class="style3">&nbsp;</p>
<p class="style3">&nbsp;</p>
<p class="style3">&nbsp;</p>
</div>
<div align="center"></div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p></td>
<td width="170" height="690" valign="top"><table width="170" height="700" border="0" background="images/COLLECTION CDS/WEBSIDEBANNER600.jpg">
<tr>
<td height="220">&nbsp;</td>
</tr>
<tr>
<td height="40"><div align="center">
<h3 class="style2"><strong>CATEGORY</strong></h3>
</div></td>
</tr>
<tr>
<td height="400" valign="top"><div align="center">
<p>&nbsp;</p>
<p><a href="#">cd</a></p>
<p><a href="#">dvd</a></p>
<p><a href="#">video</a></p>
<p><a href="#">awards</a></p>
<p><a href="#">memorabilia</a></p>
<p><a href="#">clothing</a></p>
<p><a href="#">magazines</a></p>
<p><a href="#">jewellery</a></p>
<p><a href="#">autographs</a></p>



<p>&nbsp;</p>
</div></td>
</tr>
</table></td>
</tr>


</table></td>
</tr>
<tr>
<td><div align="center">
<?php
require("bottombanner.php")

?>
</div></td>
</tr>
</table>
</body>
</html>

wheelie34

4:59 pm on Feb 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ok I am no boffin at PHP but if you want to run all your options to one page you will need code at the top of the page to see what's coming in, that way it knows what to show you, if, for example it was the first load of the page there would be no data to process except the sql statement as its choices are hard coded.


("SELECT * FROM geri ORDER BY cd")

As you (like me) seem newish to PHP the way I would work is seperate pages so the links would go to a results page which has its own sql function, hard code it first then change it to accept different NAMES.

Then move onto a page for categories, get it working how you want then if you want to run from one page work out how many if() else statements you will need to handle different sets of data ALL posabilities.

Your links to each singer or category, I would call them from the database and build the links for zero maintenance later ie


SELECT name FROM spice_girls ORDER BY DESC
then
$x = $row['name'];
print <a href="results.php?name=$x>$x</a>
which would produce
results.php?name=Geri">Geri</a

And Geri would be past to the results page so your sql statement would receive it like


SELECT * FROM spice_girls WHERE name ='$x'

Work on one page at a time, it'll keep your post lengths down too ;) HTH

jyogit

4:44 pm on Feb 18, 2008 (gmt 0)

10+ Year Member



i have thought about the blank page first the redirect to one which then has the correct info in it.
As each girl will have her own page i could use the first page as an introduction to the girl and the links will redirect from there on in.

trying to fathom that one now.
each database table has its own girls name and a spicegirls one seperate.
so i have 6 tables with 10 categories in.

this has been suggested
$search_option = "cd";
if ($_POST['search_for'] == "dvd") { $search_option = "dvd"; }

$sql = "SELECT ".$search_option." FROM victoria ORDER BY ".$search_option;

would i simply just add 10 lines of the if statement line changing the category in each one?
and would i do this at the top of my html page or actually where i need the images printing in my page?

would <a href=template.php?category=$x>cd </a> be my button html?

does anyone know any good books on this subject?
as i feel helpless and unarmed at some of the replies in here.

i appreciate teh time u guys are taking to try and help out though.

wheelie34

6:57 pm on Feb 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The simplest way to understand it would be, lets say you are passing one of the following variations

$name (which could hold Victoria)
OR
$name $dvd (which could hold Victoria and a DVD of hers)

if isset($_POST['name'] && !$_POST['dvd']) # only name
{
$sql = "SELECT * FROM $name";
}
if isset($_POST['name'] && $_POST['dvd']) # both
{
$sql = "SELECT dvd FROM $name";
}

$result = mysql_query($sql, $con) or die("error");
while ($row = mysql_fetch_array($result))
{
$x = $row['name'];
$y = $row['dvd'];

print "$x $y";
}

You should also have code in place to catch a page called to a browser empty, either using

header(Location:
OR
A default sql statement that loads content

If you gather your variables at the top of the page you can use them in your title and description tags too like this

<title><?PHP print $name?> is one of the girls</title>

Hope that helps a bit, I havent tested any of the code;)

jyogit

7:21 pm on Feb 18, 2008 (gmt 0)

10+ Year Member



thanks again wheelie.
i think for the moment ill end up making 10 different pages for each girl etc as i cant seem to get a grip on this way around it.

i think i understand the logics of it but making them work is beyond me at the moment.

the nets not very helpful on these matters without using forums set up by people like yourselves,so thanks everyone who posts advice.