Jump to content


Photo

Unexpected T VARIABLE?


  • Please log in to reply
12 replies to this topic

#1 Unholy Prayer

Unholy Prayer
  • Members
  • PipPipPip
  • Advanced Member
  • 166 posts

Posted 17 August 2006 - 06:16 AM

Ok, I am trying to make an affiliates management program, but I keep getting this error on the index display page... here it is:
Parse error: syntax error, unexpected T_VARIABLE in /home/mutantde/public_html/programs/index.php on line 4

This is line 4:
$result = mysql_query("SELECT * from affiliates");

This is probably a noob question, but this is my first PHP program so I guess I am a PHP Noob.

Thanks in advance for the help.

#2 Jeremysr

Jeremysr
  • Members
  • PipPipPip
  • Advanced Member
  • 199 posts
  • LocationSaskatchewan, Canada

Posted 17 August 2006 - 06:18 AM

I don't see anything wrong with it, but it might be the line above or below line 4...I think if you missed a semi-colon on line 3 it'd say that it is an error on line 4.

#3 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 17 August 2006 - 06:18 AM

Going to need a few lines around line 4. Php syntax errors are not line accurate.

#4 Unholy Prayer

Unholy Prayer
  • Members
  • PipPipPip
  • Advanced Member
  • 166 posts

Posted 17 August 2006 - 06:19 AM

This is the whole page:
<?php
require_once('database.php')

$result = mysql_query("SELECT * from affiliates");

while($r=mysql_fetch_array($result))
{	  
   $site_name=$r["site_name"];
   $site_url=$r["site_url"];
   $banner_url=$r["banner_url"];
   echo "<a href='$site_url' target='new'><img src='$banner_url' width='88' height='31'></a>"
}
?>

I know... not that much coding, right?  But hey, with a PHP noob like me, this kind of stuff is expected.

#5 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 17 August 2006 - 06:20 AM

Your missing the colon from the end of your only echo() line.

#6 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 17 August 2006 - 06:21 AM

And also from the require_once() line.

#7 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 17 August 2006 - 06:22 AM

Jeremysr, a simple yes / no. Do you understand the meaning of your (our) avitar?

#8 Unholy Prayer

Unholy Prayer
  • Members
  • PipPipPip
  • Advanced Member
  • 166 posts

Posted 17 August 2006 - 06:24 AM

Ok, that's wierd because semicolons have never been a problem in my other scripts in both the require_once() and echo lines.  Where exactly do I put them?  Just at the end?

#9 Jeremysr

Jeremysr
  • Members
  • PipPipPip
  • Advanced Member
  • 199 posts
  • LocationSaskatchewan, Canada

Posted 17 August 2006 - 06:26 AM

Jeremysr, a simple yes / no. Do you understand the meaning of your (our) avitar?


Yes. I read the "How to be a Hacker" article and the emblem faqs.

And Unholy Prayer, semi-colons signify the end of a line.

#10 Unholy Prayer

Unholy Prayer
  • Members
  • PipPipPip
  • Advanced Member
  • 166 posts

Posted 17 August 2006 - 06:27 AM

Oh, silly me.  I was thinking of : instead of ;  Lol.  I am officially embarressed.

#11 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 17 August 2006 - 06:29 AM

Jeremysr, cool. I have the book.

that's wierd because semicolons have never been a problem in my other scripts


You should have... there are a required part of php synatx.

Yes, you'll need them at the end.
<?php
require_once('database.php');

$result = mysql_query("SELECT * from affiliates");

while($r=mysql_fetch_array($result))
{	  
   $site_name=$r["site_name"];
   $site_url=$r["site_url"];
   $banner_url=$r["banner_url"];
   echo "<a href='$site_url' target='new'><img src='$banner_url' width='88' height='31'></a>";
}
?>


#12 Unholy Prayer

Unholy Prayer
  • Members
  • PipPipPip
  • Advanced Member
  • 166 posts

Posted 17 August 2006 - 06:31 AM

Ok, there's no error now, but it's not displaying anything...  Here it is:
http://www.mutant-de...grams/index.php

Note:  That is the correct URL, I just forgot to add the "affiliates" directory and put all the files in it.  I'll get to it when I'm done with the program.

#13 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 17 August 2006 - 06:48 AM

You never check to see if your query actually works before using it. Get in the habbit.

<?php
require_once('database.php');

if ($result = mysql_query("SELECT * from affiliates")) {
  while($r=mysql_fetch_array($result))
    $site_name=$r["site_name"];
    $site_url=$r["site_url"];
    $banner_url=$r["banner_url"];
    echo "<a href='$site_url' target='new'><img src='$banner_url' width='88' height='31'></a>";
  }
} else {
  echo "query failed ".mysql_error();
}
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users