Jump to content


Photo

Variable and images


  • Please log in to reply
8 replies to this topic

#1 HoTDaWg

HoTDaWg
  • Members
  • PipPipPip
  • Advanced Member
  • 275 posts
  • LocationToronto

Posted 15 March 2006 - 08:59 PM

hi,


I have a script, which has an error. Php gives me the following error:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/cortez/public_html/testscripts/photoalbums/gallery.php on line 23

I am trying to create a gallery of all the images which have been uploaded. Here is the script:

<html>
<head>
<title>Image Gallery</title>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
</head>
<body>
<?php
$conn = mysql_connect("localhost","phpfreaks","rocks");

//now choose the database to use
mysql_select_db("cortez_photoalbums");

$id = $_GET['id']; // retrieve id passed via URL
if (isset($id)) {
    $query = "DELETE FROM images WHERE id = '$id' ";
    $result = mysql_query($query);
}
$getimages = mysql_query("SELECT * FROM images ORDER BY id DESC");
while($r=mysql_fetch_array($getimages)) {

extract($r); //remove the $r so its just $variable
    echo("<hr>
    Image: <image src='". $_POST['imageurl']"' height="50" width="50"><br>
    Id: $id <br>

    Date: $date<br>
    <a href='". $_SERVER['PHP_SELF']. "?id=". $id. "'>delete</a>"); 
}
?>

</body>
</html>

thanks,

HotDawg

Handy links:
Google
PHP Manual


#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 15 March 2006 - 09:07 PM

well, it looks pretty good, except, it looks like you forgot to go back INTO the quotes. you also need to escape your double quotes within your string... try this on:
echo("<hr>
    Image: <image src='". $_POST['imageurl'] . "' height=\"50\" width=\"50\"><br>
    Id: $id <br>
    Date: $date<br>
    <a href='". $_SERVER['PHP_SELF']. "?id=$id'>delete</a>"); 


you simply forgot your second "."

the other thought is to do this:
echo("<hr>
    Image: <image src='$_POST[imageurl]' height=\"50\" width=\"50\"><br>
    Id: $id <br>
    Date: $date<br>
    <a href='$_SERVER['PHP_SELF']?id=$id'>delete</a>"); 

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 HoTDaWg

HoTDaWg
  • Members
  • PipPipPip
  • Advanced Member
  • 275 posts
  • LocationToronto

Posted 15 March 2006 - 09:19 PM

the script seems a lot better now,

we so far got:

<html>
<head>
<title>Homework Administration- Delete Homework</title>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
</head>
<body>
<?php
$conn = mysql_connect("localhost","cortez","165745");

//now choose the database to use
mysql_select_db("cortez_photoalbums");

$id = $_GET['id']; // retrieve id passed via URL
if (isset($id)) {
    $query = "DELETE FROM images WHERE id = '$id' ";
    $result = mysql_query($query);
}
$getimages = mysql_query("SELECT * FROM images ORDER BY id DESC");
while($r=mysql_fetch_array($getimages)) {

extract($r); //remove the $r so its just $variable
    echo("<hr>
  Image: <image src='$_POST[imageurl]' height=\"50\" width=\"50\"><br>
    Id: $id <br>
    Date: $date<br>
    <a href='". $_SERVER['PHP_SELF']. "?id=$id'>delete</a>"); 

</body>
</html>

the only problem is, as much, as i hate to say this i am getting the following error:

Parse error: syntax error, unexpected '<' in /home/cortez/public_html/testscripts/photoalbums/gallery.php on line 28

strange.

HotDawg

Handy links:
Google
PHP Manual


#4 XenoPhage

XenoPhage
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 15 March 2006 - 09:27 PM

[!--quoteo(post=355481:date=Mar 15 2006, 04:19 PM:name=HoTDaWg)--][div class=\'quotetop\']QUOTE(HoTDaWg @ Mar 15 2006, 04:19 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
<?php
$conn = mysql_connect("localhost","cortez","165745");

//now choose the database to use
mysql_select_db("cortez_photoalbums");

$id = $_GET['id']; // retrieve id passed via URL
if (isset($id)) {
    $query = "DELETE FROM images WHERE id = '$id' ";
    $result = mysql_query($query);
}
$getimages = mysql_query("SELECT * FROM images ORDER BY id DESC");
while($r=mysql_fetch_array($getimages)) {

extract($r); //remove the $r so its just $variable
    echo("<hr>
  Image: <image src='$_POST[imageurl]' height=\"50\" width=\"50\"><br>
    Id: $id <br>
    Date: $date<br>
    <a href='". $_SERVER['PHP_SELF']. "?id=$id'>delete</a>"); 

</body>
</html>
[/quote]

You didn't close out the php code.. You need to add ?> just before the </body> statement..
--
[a href=\"http://blog.godshell.com\" target=\"_blank\"]XenoPhage[/a]
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Something mysterious is formed, born in the silent void. Waiting alone and unmoving, it is at once still and yet in constant motion. It is the source of all programs. I do not know its name, so I will call it the Tao of Programming.[/quote]

#5 HoTDaWg

HoTDaWg
  • Members
  • PipPipPip
  • Advanced Member
  • 275 posts
  • LocationToronto

Posted 15 March 2006 - 09:36 PM

ooh whoops. Sorry guys. GOD GOD! HARD TO BELIEVE HOW MANY SYNTAX ERRORS I GOT! READ THIS:

Parse error: syntax error, unexpected $end in /home/cortez/public_html/testscripts/photoalbums/gallery.php on line 31

here is the script we got so far:

<html>
<head>
<title>Homework Administration- Delete Homework</title>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
</head>
<body>
<?php
$conn = mysql_connect("localhost","cortez","165745");

//now choose the database to use
mysql_select_db("cortez_photoalbums");

$id = $_GET['id']; // retrieve id passed via URL
if (isset($id)) {
    $query = "DELETE FROM images WHERE id = '$id' ";
    $result = mysql_query($query);
}
$getimages = mysql_query("SELECT * FROM images ORDER BY id DESC");
while($r=mysql_fetch_array($getimages)) {

extract($r); //remove the $r so its just $variable
    echo("<hr>
  Image: <image src='$_POST[imageurl]' height=\"50\" width=\"50\"><br>
    Id: $id <br>
    Date: $date<br>
    <a href='". $_SERVER['PHP_SELF']. "?id=$id'>delete</a>"); 

?>
</body>
</html>

this is really getting me angry (the script),

HotDawg

Handy links:
Google
PHP Manual


#6 XenoPhage

XenoPhage
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 15 March 2006 - 09:49 PM

<html>
<head>
<title>Homework Administration- Delete Homework</title>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
</head>
<body>
<?php
$conn = mysql_connect("localhost","cortez","165745");

//now choose the database to use
mysql_select_db("cortez_photoalbums");

$id = $_GET['id']; // retrieve id passed via URL
if (isset($id)) {
    $query = "DELETE FROM images WHERE id = '$id' ";
    $result = mysql_query($query);
}
$getimages = mysql_query("SELECT * FROM images ORDER BY id DESC");
while($r=mysql_fetch_array($getimages)) {

extract($r); //remove the $r so its just $variable
    echo("<hr>
  Image: <image src='$_POST[imageurl]' height=\"50\" width=\"50\"><br>
    Id: $id <br>
    Date: $date<br>
    <a href='". $_SERVER['PHP_SELF']. "?id=$id'>delete</a>");

}
?>
</body>
</html>

You missed closing the while() loop.. Above passes a php lint test.
--
[a href=\"http://blog.godshell.com\" target=\"_blank\"]XenoPhage[/a]
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Something mysterious is formed, born in the silent void. Waiting alone and unmoving, it is at once still and yet in constant motion. It is the source of all programs. I do not know its name, so I will call it the Tao of Programming.[/quote]

#7 HoTDaWg

HoTDaWg
  • Members
  • PipPipPip
  • Advanced Member
  • 275 posts
  • LocationToronto

Posted 15 March 2006 - 09:54 PM

i hate to be a pain guys, but the script is working! YAY! The only problem is that the images are not showing :(. I view sourced the page and here is what it showed:

<html>
<head>
<title>Homework Administration- Delete Homework</title>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
</head>
<body>
<hr>
  Image: <image src='' height="50" width="50"><br>
    Id: 14 <br>
    Date: 03.15.06<br>

    <a href='/testscripts/photoalbums/gallery.php?id=14'>delete</a><hr>
  Image: <image src='' height="50" width="50"><br>
    Id: 13 <br>
    Date: 03.15.06<br>
    <a href='/testscripts/photoalbums/gallery.php?id=13'>delete</a><hr>
  Image: <image src='' height="50" width="50"><br>

    Id: 12 <br>
    Date: 03.14.06<br>
    <a href='/testscripts/photoalbums/gallery.php?id=12'>delete</a><hr>
  Image: <image src='' height="50" width="50"><br>
    Id: 11 <br>
    Date: 03.14.06<br>

    <a href='/testscripts/photoalbums/gallery.php?id=11'>delete</a><hr>
  Image: <image src='' height="50" width="50"><br>
    Id: 10 <br>
    Date: 03.14.06<br>
    <a href='/testscripts/photoalbums/gallery.php?id=10'>delete</a><hr>
  Image: <image src='' height="50" width="50"><br>

    Id: 9 <br>
    Date: 03.14.06<br>
    <a href='/testscripts/photoalbums/gallery.php?id=9'>delete</a><hr>
  Image: <image src='' height="50" width="50"><br>
    Id: 8 <br>
    Date: 03.14.06<br>

    <a href='/testscripts/photoalbums/gallery.php?id=8'>delete</a><hr>
  Image: <image src='' height="50" width="50"><br>
    Id: 7 <br>
    Date: 03.13.06<br>
    <a href='/testscripts/photoalbums/gallery.php?id=7'>delete</a><hr>
  Image: <image src='' height="50" width="50"><br>

    Id: 6 <br>
    Date: 03.13.06<br>
    <a href='/testscripts/photoalbums/gallery.php?id=6'>delete</a></body>
</html>


as you all may have noticed the image location does not come up for some reason.

very weird,

my appologies and thanks


Handy links:
Google
PHP Manual


#8 HoTDaWg

HoTDaWg
  • Members
  • PipPipPip
  • Advanced Member
  • 275 posts
  • LocationToronto

Posted 16 March 2006 - 02:01 AM

anyone?

Handy links:
Google
PHP Manual


#9 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 16 March 2006 - 02:19 AM

Why are you using $_POST['imageurl'] for the img src tag? Shouldn't that be some value from the database?

while($r=mysql_fetch_array($getimages)) {

extract($r); //remove the $r so its just $variable
    echo("<hr>
  Image: <image src='$pathtofile' height=\"50\" width=\"50\"><br>
    Id: $id <br>
    Date: $date<br>
    <a href='". $_SERVER['PHP_SELF']. "?id=$id'>delete</a>");

}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users