View Full Version : problem with this code
alexdog1805
02-09-2009, 01:52 PM
<?php
$host = "host";
$user = "user";
$pass = "password";
$con = mysql_connect($host , $user , $pass);
if(!$con)
{
die("Failed to connect to the server" . mysql_error());
}
$image = "images/advert.jpg";
$result = mysql_query("SELECT * FROM table WHERE image = $image");
while($row = mysql_fetch_array($result))
{
echo $row['image'];
?>
I created in database a table ''image" and i created in this table a decimal camp called 'image'. I put the image advert.jpg in image folder but it doesnt works.
It appears to me this message:
Parse error: syntax error, unexpected $end in /home/hosting/masterfifa/index.php on line 25
zeromadpeter
02-09-2009, 06:02 PM
<?php
$host = "host";
$user = "user";
$pass = "password";
$link = mysql_connect($host , $user , $pass);
if($link)
{
$db_selected = mysql_select_db("databasename",$link);
if ($db_selected)
{
$image = "images/advert.jpg";
$result = mysql_query("SELECT * FROM table WHERE image='".$image."'");
while($I = mysql_fetch_array($result))
{
echo "- entry: ".$I['image']."<br/>";
}
}
}
?>
expected
- entry: images/advert.jpg <br/>
repeated the number of times in the database
changes:
added database select
changed some names ^_^
updated the SQL to enclose the WHERE statment value in '
finished teh code
alexdog1805
02-09-2009, 06:50 PM
<?php
$host = "host";
$user = "user";
$pass = "password";
$link = mysql_connect($host , $user , $pass);
if($link)
{
$db_selected = mysql_select_db("databasename",$link);
if ($db_selected)
{
$image = "images/advert.jpg";
$result = mysql_query("SELECT * FROM table WHERE image='".$image."'");
while($I = mysql_fetch_array($result))
{
echo "- entry: ".$I['image']."<br/>";
}
}
}
?>
expected
- entry: images/advert.jpg <br/>
repeated the number of times in the database
changes:
added database select
changed some names ^_^
updated the SQL to enclose the WHERE statment value in '
finished teh code
the code you gave me is ok, it doesn' appears to me any error but it doesn't apears the photo, which is the thing that i want for this code to do. Please help me with this code to appears me the photo. Thanks
zeromadpeter
02-09-2009, 07:10 PM
if you want it to output the html for the image then why are u using a database and not just
<img src="./images/advert.jpg" alt="image woot"/>
please can you tell me what you want to do with the database.
alexdog1805
02-09-2009, 08:40 PM
if you want it to output the html for the image then why are u using a database and not just
<img src="./images/advert.jpg" alt="image woot"/>
please can you tell me what you want to do with the database.
because I am a beginner in php and I want to learn to do in php things that I can make in html, so can you tell me in php how I do that the image appears?
boogyman
02-10-2009, 05:12 PM
while($I = mysql_fetch_array($result))
{
$img = sprintf("<img src=\"%s\" width=\"\" height=\"\" alt=\"\">", $I['image']);
echo $img;
}
alexdog1805
02-14-2009, 02:31 PM
now I have this code:
<?php
$host = "host";
$user = "user";
$pass = "password";
$link = mysql_connect($host , $user , $pass);
if($link)
{
$db_selected = mysql_select_db("image",$link);
if ($db_selected)
{
$image = "images/advert.jpg";
$result = mysql_query("SELECT * FROM table WHERE image='".$image."'");
while($I = mysql_fetch_array($result))
{
echo "- entry: ".$I['image']."<br/>";
}
}
}
while($I = mysql_fetch_array($result))
{
$image = sprintf("<img src="images/advert.jpg" width="20" height="100" alt="20">", $I['image']);
echo $img;
}
?>
and this don't works too, It appears to me this message:
Parse error: syntax error, unexpected T_STRING in /home/hosting/masterfifa/index.php on line 21
punstc
02-14-2009, 05:43 PM
here try this.
<?php
$host = "host";
$user = "user";
$pass = "password";
$link = mysql_connect($host , $user , $pass);
if($link) {
$db_selected = mysql_select_db("image",$link);
if ($db_selected) {
$image = "images/advert.jpg";
$result = mysql_query("SELECT * FROM table WHERE image='$image' ");
while($I = mysql_fetch_array($result)) {
echo "- entry: ".$I['image']."<br/>";
}
}
}
while($I = mysql_fetch_array($result)) {
$img = sprintf("<img src=\"images/advert.jpg\" width=\"20\" height=\"100\" alt=\"20\">", $I['image']);
echo $img;
}
?>
If you look at this specific line
$img = sprintf("<img src=\"images/advert.jpg\" width=\"20\" height=\"100\" alt=\"20\">", $I['image']);
The backslashes in font of the quotes are needed to tell php to ignore this quote as the end of the string I'm entering. I believe the proper name for it is escaping.
Just remember that any time you need to use a quote for a normal html like src="", alt="", etc. inside your php echo string or whatever else your entering you need to add the backslash in front of it so php will ignore the quote.
alexdog1805
02-15-2009, 08:08 AM
here try this.
<?php
$host = "host";
$user = "user";
$pass = "password";
$link = mysql_connect($host , $user , $pass);
if($link) {
$db_selected = mysql_select_db("image",$link);
if ($db_selected) {
$image = "images/advert.jpg";
$result = mysql_query("SELECT * FROM table WHERE image='$image' ");
while($I = mysql_fetch_array($result)) {
echo "- entry: ".$I['image']."<br/>";
}
}
}
while($I = mysql_fetch_array($result)) {
$img = sprintf("<img src=\"images/advert.jpg\" width=\"20\" height=\"100\" alt=\"20\">", $I['image']);
echo $img;
}
?>
If you look at this specific line
$img = sprintf("<img src=\"images/advert.jpg\" width=\"20\" height=\"100\" alt=\"20\">", $I['image']);
The backslashes in font of the quotes are needed to tell php to ignore this quote as the end of the string I'm entering. I believe the proper name for it is escaping.
Just remember that any time you need to use a quote for a normal html like src="", alt="", etc. inside your php echo string or whatever else your entering you need to add the backslash in front of it so php will ignore the quote.
I tried this code and it doesn't appears me any message error, but it doesn't apeears image too. Look here http://masterfifa.3x.ro, here should appears the advert.jpg photo.
alexdog1805
02-20-2009, 08:58 PM
I still can't see the photo.:(
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.