0

I I am trying to make a site checker for my traffic exchange Now i was able to get this to work

SELECT*FROM vtp_urls where ID=326

and it puled up the right file and everything so I search the web for a way to display the url so I can see if it is good or bad and found this:

<?php
include("mysql_config.php");

if ($dbc = mysql_connect ($host, $user, $passwrd)) // make connection
{
	if (!mysql_select_db ($db)) 
	{ // If it can not select the database.
		echo 'failed to select db';
		exit();
	}
{
$geturl= mysql_query ("SELECT*FROM "vtp_urls" WHERE id='362'") or die(mysql_error());
$count = mysql_num_rows($geturl);
     if($count == 1)
     {
     $row = mysql_fetch_assoc($geturl);
     {
     $url= $row['url'];
{
 echo  "<iframe src=$url style="background: #fff;" frameborder="0" height="450" scrolling="auto" width="100%"></iframe>";
            </div>
} 
?>

now that should have displayed the same site but no luck get a Parse error:

syntax error, unexpected T_STRING in /home/royalfam/public_html/sitetester.php on line 12

this is just the start of the site checker just to see if I can get the same result as I did before.

This is my first bit of code I am writing on my own so please be gentle and remember in this I am dumber than a fifth grader. LOL
so any help in fixing the parse error or ideas on how to do this better would be great:)

Dave

2
Contributors
22
Replies
23
Views
7 Years
Discussion Span
Last Post by scaiferw
Featured Replies
  • On line 12 [iCODE]FROM "vtp_urls" WHERE[/iCODE] needs to be single quotes. That should do it. Whenever you get that "unexpected T_STRING..." error, look for a problem with quotes. Your whole SQL query is surrounded by double quotes, so any quotes within that query must be single quotes or escaped , … Read More

1

On line 12 FROM "vtp_urls" WHERE needs to be single quotes.

That should do it.

Whenever you get that "unexpected T_STRING..." error, look for a problem with quotes.

Your whole SQL query is surrounded by double quotes, so any quotes within that query must be single quotes or escaped , meaning preceded by a back slash as in "SELECT * FROM 'vtp_urls' WHERE id='362'" or "SELECT * FROM \"vtp_urls\" WHERE id=\"362\"" .

I don't bother escaping, it's annoying to do and hard to read.

Since you're new, like we all once were, I'll give you a couple of other tips.

1. Whenever your code throws an error you don't understand, look first for a quoting error or a missing ; on the referenced line or the previous line(s).

2. Whenever you have or die(mysql_error()) , in your code, do this instead: or die(__LINE__.": ".mysql_error()) . Now your error message will reveal the line where the error occurred so you know where in the forest to start hunting.

3. Lines 8-9 can be reduced to: exit("failed to select db"); . In fact, while I can't test it right now, I suspect lines 6-10 could be reduced to mysql_select_db($db) or die(__LINE__.": Failed to select database."); .

Hope that helps!

Cheers,

Rob

Edited by scaiferw: n/a

0

cool that got me down to line 22 there is only 23 LOL

<?php
include("mysql_config.php");

if ($dbc = mysql_connect ($host, $user, $passwrd)) // make connection
{
	if (!mysql_select_db ($db)) 
	{ // If it can not select the database.
		echo 'failed to select db';
		exit();
	}
{
$geturl= mysql_query ("SELECT * FROM 'vtp_urls' WHERE id='362'")or die(mysql_error());  
     {
     $row = mysql_fetch_row($geturl);
     {
     $url= $row['url'];}
{
 echo  '<iframe src="'.$url.'" style="background: #fff;" frameborder="0" height="450" scrolling="auto" width="100%"></iframe>';  
            
} 
?>

it is the line with the Iframe error is as follows
Parse error: syntax error, unexpected $end in /home/royalfam/public_html/sitetester.php on line 22

We are so close. LOL to finishing part one.

part two looping it is easy then I just have to figutre out how to get it to move from row to row. LOL

Edited by Ezzaral: Fixed broken code tags.

0

Your braces were all squirrely so I stripped them all out and put it together the way I think it should be, but since I don't have all your code I can't be positive this is right. Try it, anyway.

<?php
include("mysql_config.php");

if ($dbc = mysql_connect ($host, $user, $passwrd)) {
	if (!mysql_select_db ($db)) { 
		// If it can not select the database.
		echo 'failed to select db';
		exit();
	}
}

$geturl = mysql_query ("SELECT * FROM 'vtp_urls' WHERE id='362'") or die(mysql_error());
$count = mysql_num_rows($geturl);

if ($count == 1) {
	$row = mysql_fetch_assoc($geturl);
	$url= $row['url'];
	echo  '<iframe src="$url" style="background: #fff;" frameborder="0" height="450" scrolling="auto" width="100%"></iframe>';
} 
?>

Or, how I'd do it for comparison;

<?php
include("mysql_config.php");

if ($dbc = mysql_connect ($host, $user, $passwrd)) {
	mysql_select_db($db) or die(__LINE__.": Failed to select DB");
}

$geturl = mysql_query ("SELECT * FROM 'vtp_urls' WHERE id='362'") or die(__LINE__.": Query failed: ".mysql_error());
$count = mysql_num_rows($geturl);

if ($count == 1) {
	$row = mysql_fetch_assoc($geturl);
	$url= $row['url'];
	echo  '<iframe src="$url" style="background: #fff;" frameborder="0" height="450" scrolling="auto" width="100%"></iframe>';
} 
?>

To go from row to row, if I understand you correctly, this is an example of what to do;

// get data from table 
$result = mysql_query("SELECT firstname,lastname FROM members") 
  or die(__LINE__.": SELECT error getting member data ".mysql_error());

// open table
echo "<table>";

// now loop through the recordset
while($row=mysql_fetch_array($result)) { 

  // create a variable for each attribute
  foreach($row as $var => $temp){
    $$var = $temp;
  }

  // create a table row for this record
  echo "<tr><td>$firstname $lastname</td></tr>";

} // end while loop

// close table
echo "</table>";

I hope this works out for you!

Do yourself a big favour and download Notepad++ free from http://notepad-plus.sourceforge.net/. This is a syntax colouring code editor and will save you from madness.

Edited by scaiferw: n/a

0

nope no joy that is all the code for now trying to get it to show the URL then I know the heart of the system is good and can continue to build around it.

the error was

8: Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''vtp_urls' WHERE id='362'' at line 1

Might I ask what the count does?

0

Maybe I am over thinking this all I need it to do is display that url so I know the core works. LOL

0

$count is the number of rows returned by the query. (See line 13)

In your query, you're only going to get one row, becaue of WHERE id='362' (I assume id is the primary key and is therefore unique. Given that, the if ($count == 1) { bit would be a way of saying "Only do this if a record matching that condition was found".

Edited by scaiferw: n/a

0

ok I am just looking for one to confirm when this is done it will display a site for so many seconds and give me the option to delete it I have the delete code down. LOL

and this is the heart of it. because looping isn't going to be a problem have done that before and seen it used a million times on my TE

so we are looking to return 1 site at a time the next one in the row but wanted to test the core first you see. is that micro managing?

Sorry to be a pain. I have been looking for an answer and it just isn't to be found.
LOL

0

yea me too. may boss is right this is going to take toime. lol
Thanks so much you did get me further one last question if I am just looking for one url at a time do I take the * and the count out?

0

The count seems to be used to see if you're getting one record returned.

The ID attribute is normally the Primary Key in the database table, which means there won't ever be two records with the same value. So you'll either get one or zero results, never more than one.

The whole count thing seems unnecessary to me.

A good way to limit the results to one if you're not absolutely positive you're searching on a unique value is to use the LIMIT clause: SELECT * FROM members WHERE lastname = 'smith' LIMIT 1 That guarantees there will be only one record returned, even if there are many smiths.

The * means you're asking for every attribute (field) to be returned for each record. Alternatively you could just say firstname,lastname , but you must have something there between SELECT and FROM.

Putting the * is OK if there aren't thousands of records with many attributes being returned, but it is a little wasteful if you don't need all the attributes returned.

Edited by scaiferw: n/a

0

Your braces were all squirrely so I stripped them all out and put it together the way I think it should be, but since I don't have all your code I can't be positive this is right. Try it, anyway.

<?php
include("mysql_config.php");

if ($dbc = mysql_connect ($host, $user, $passwrd)) {
	if (!mysql_select_db ($db)) { 
		// If it can not select the database.
		echo 'failed to select db';
		exit();
	}
}

$geturl = mysql_query ("SELECT * FROM 'vtp_urls' WHERE id='362'") or die(mysql_error());
$count = mysql_num_rows($geturl);

if ($count == 1) {
	$row = mysql_fetch_assoc($geturl);
	$url= $row['url'];
	echo  '<iframe src="$url" style="background: #fff;" frameborder="0" height="450" scrolling="auto" width="100%"></iframe>';
} 
?>

Or, how I'd do it for comparison;

<?php
include("mysql_config.php");

if ($dbc = mysql_connect ($host, $user, $passwrd)) {
	mysql_select_db($db) or die(__LINE__.": Failed to select DB");
}

$geturl = mysql_query ("SELECT * FROM 'vtp_urls' WHERE id='362'") or die(__LINE__.": Query failed: ".mysql_error());
$count = mysql_num_rows($geturl);

if ($count == 1) {
	$row = mysql_fetch_assoc($geturl);
	$url= $row['url'];
	echo  '<iframe src="$url" style="background: #fff;" frameborder="0" height="450" scrolling="auto" width="100%"></iframe>';
} 
?>

To go from row to row, if I understand you correctly, this is an example of what to do;

// get data from table 
$result = mysql_query("SELECT firstname,lastname FROM members") 
  or die(__LINE__.": SELECT error getting member data ".mysql_error());

// open table
echo "<table>";

// now loop through the recordset
while($row=mysql_fetch_array($result)) { 

  // create a variable for each attribute
  foreach($row as $var => $temp){
    $$var = $temp;
  }

  // create a table row for this record
  echo "<tr><td>$firstname $lastname</td></tr>";

} // end while loop

// close table
echo "</table>";

I hope this works out for you!

Do yourself a big favour and download Notepad++ free from http://notepad-plus.sourceforge.net/. This is a syntax colouring code editor and will save you from madness.

worked like gang busters took me a while but this is what I ended up with. it works when I put all my data base stuff in there but not right now so here is the near working code :)

<?php
include("mysql_config.php");

if ($dbc = mysql_connect ($host, $user, $passwrd)) {
	mysql_select_db($db) or die(__LINE__.": Failed to select DB");


  $result = mysql_query("SELECT url FROM vtp_urls");
echo "<table>";

// now loop through the recordset
while($row=mysql_fetch_array($result)) { 

  // create a variable for each attribute
  foreach($row as $var => $temp){
    $$var = $temp;
  }

  // create a table row for this record
  echo  "<tr><td>$url<tr><td>";

} // end while loop

// close table
echo  "</table>";

only one problem it finishes in about a second and I looked up PHP loop for about an hour now and gave up so how do I slow this down to about a 20 second loop. IE it picks the first one up out of the data base waits 20 seconds then gets the next one. LOL.

When i put the echo to src the link it looped my computer and I had to shut it down but it was pulling everything off the site. funniest thing you ever saw. LOL

Dave

Thank you all so much I have learned alot and I am not done yet:)

Dave

Edited by Ezzaral: Fixed end code tag. Forward slash was missing.

0

Hey Dave;

There's a function for precisely that;

// sleep for 20 seconds
sleep(20);

Glad it worked out!

(BTW, echo "<tr><td>$url<tr><td>"; should be echo "<tr><td>$url</td></tr>"; Cheers,

Rob

Edited by scaiferw: n/a

0

and that would go after this?
// create a table row for this record
echo "<tr><td>$url<td><tr>";

0

Yes, that's probably where you want the pause, but it's up to you. The spot you suggest would make sense because it's the last thing that happens in the loop iteration.

By the way, <tr><td>$url<td><tr> won't work at all. <tr> opens a row, and <td> opens a cell in the row. </td> and </tr> close them.

There are two problems with the way you have that line. First, your <tr> and <td> elements aren't closed. The <td> and <tr> after '$url' should be the closing tags with the slash, but instead they're opening new tags.

The other thing is that your TR and TD tags overlap. <tr><td>content</td></tr> works, <tr><td>content<tr><td> does not work. TD is a 'child' of TR, and so the TD must be closed before the TR is closed.

It makes more sense visually when indented on multiple lines;

<tr>
  <td>
    Content goes here.
  </td>
</tr>

To have compliant XHTML code, which is critical to have your page display properly in various browsers, you have to open an close your tags the right way.

When developing I usually put a hidden link to http://validator.w3.org/check/referer in the page footer so I can check easily. Click the link and the whole page will be checked for validation. Don't be freaked out if it shows dozens of errors, sometimes one fix will reduce the error count substantially.

Cheers,

Rob

Edited by scaiferw: n/a

0

tried the sleep thing and all it did was loop the system then dump all the urls at once.

I tried putting it in many places and some caused an endless loop again. any chance some one could show where it would go pretty please. lol

also fixed the data base not closing with a }

Dave

0

lol seems boss was kind enought to tell me NOW that there doesn't need to be a timer in it as a javascript will be handling the timer. LOL

Thanks for all your help and I learned alot

Dave

0

My pleasure. I've had a lot of help on boards like this, so a little pay-it-forward is always in order.

And I learned a little bit about flush()/sleep() too!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.