Forum Moderators: coopster

Message Too Old, No Replies

Can anyone tell me why this isn't working?

         

generic

4:30 am on Jan 20, 2006 (gmt 0)

10+ Year Member



Hi.

I'm trying to get this event listing type script to run. It was a conversion of sorts from a flat file type of setup to this mysql version. I'm really not sure where it's going wrong as I have no access to the server to turn error reporting on. I just thought extra eyes may spot the missing quote or whatever is wrong that I'm not catching.

Anyway, I'm sure it's nasty code but it's more an excercise in learning for me at this point. Any takers?

events.php
==========
include("includes/dbconnect.php");

//begin event check and listing
if(isset($_GET["e"]) &&!empty($_GET["e"])) { //if single event is called[/code]
$e = $_GET["e"];

$result = mysql_query("SELECT * FROM snospree_events WHERE eventid='$eventid' ",$connect);
while($myrow = mysql_fetch_assoc($result)) {//begin loop

//auto-parse URLs
$myrow[eventdesc] = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i","<a target=\"_blank\" href=\"$1\">$1</a>", $myrow[eventdesc]);
$myrow[eventurl] = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i","<a target=\"_blank\" href=\"$1\">$1</a>", $myrow[eventurl]);

//convert mysql date/time results from YYYY:MM:DD to Weekday, Month Day Year
$myrow[eventdate] = date('l, F jS',strtotime($myrow[eventdate]));
$myrow[eventtime] = date('g:i a',strtotime($myrow[eventtime]));

if($myrow[eventid]) == $e ) {
echo "<h1>$myrow['eventname']</h1>\n";
echo "<table style='width:100%;' cellspacing='0' cellpadding='0'>\n";
echo "<tr>\n";
echo "<td>\n";

// begin single event data here
echo "<span style='color:#666;line-height: 18px;font-size:0.8em;'>Scheduled start: <strong>$myrow['eventdate'] at $myrow['eventtime']</strong>.<br>\n";

if (!empty($myrow[eventurl])) {//url check
echo "<a href='$myrow['eventurl']' target='_blank'></a>$myrow['eventurl']</a><br>\n";
} else {
echo "";
}//end url check

if (!empty($myrow[eventimage])) {//image check
echo "<img src='images/$myrow['eventimage']\" alt='$myrow['eventname']'><br>\n";
} else {
echo "";
}// end image check

echo "<br>\n";
echo "<div style='text-align:right;font-size:0.9em;border-top:1px solid #ccc;line-height:24px;'>[ <a href='events.php'>To Event Listings</a> ]\n";
echo "</div>\n";
}// end loop
} // end single event check

} else { //otherwise, single event wasn't called so begin full schedule listing

echo "<h1>Festival Event Schedule</h1>\n";
echo "<table width='100%' cellspacing='0' cellpadding='0'>\n";
echo "<tr>\n";
echo "<td>\n";

// begin event schedule here
$result = mysql_query("SELECT * FROM snospree_events ORDER BY eventdate ASC",$connect);

// count results
$entries = mysql_num_rows($result);

echo "<br>\n";
echo "\n";
echo "There are <strong>$entries</strong> events scheduled for this years Snospree. For more information on each event, simply click on the event title.<br><br>\n";
//echo "The event listings are temporarily down. Check back often for the most up to date listings of what's going on for Snospree this year!<br><br>\n";

while($myrow = mysql_fetch_assoc($result)) {//begin loop
//auto-parse URLs
$myrow[eventdesc] = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i","<a target=\"_blank\" href=\"$1\">$1</a>", $myrow[eventdesc]);
$myrow[eventurl] = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i","<a target=\"_blank\" href=\"$1\">$1</a>", $myrow[eventurl]);
//convert mysql date/time results from YYYY:MM:DD to Weekday, Month Day Year
$myrow[eventdate] = date('l, F jS Y',strtotime($myrow[eventdate]));
$myrow[eventtime] = date('g:i a',strtotime($myrow[eventtime]));
if($i % 2 ==0) {
$bgcolor='#efefef'; }
else {
$bgcolor='#ffffff'; }
echo "<tr>
<td valign='middle' style='font-size:0.8em; background-color: $bgcolor; padding: 4px 0 4px 8px;'><a href='?e=$myrow['eventid']'>$myrow['eventname']</a> scheduled start: $myrow['eventtime']</td>
</tr>";

}// end loop
}// end of else
?>

coopster

10:36 pm on Feb 2, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



If you have the ability to push the script over to the server you should have the ability to turn on error_reporting() [php.net]. There you go, your first step in that exercise to learning ;)

Moosetick

10:47 pm on Feb 2, 2006 (gmt 0)

10+ Year Member



At the least, you need to say what it is doing and what you want it to do. Slapping some code up and asking what is wrong doesn't help.

If it is supposed to say "Hello world" then you need to remove all those lines and add...

<?php
echo "Hello world";
?>

generic

10:48 pm on Feb 2, 2006 (gmt 0)

10+ Year Member



Crazy, I think I ended up finding the flaw in my stuff and it was in part the fault of the server people I was working with, as they're php and mysql versions are in the low 3's I think. Anyway, I ended up getting it working no problem. Thanks for responding though!

coopster

10:51 pm on Feb 2, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



PHP3? Whew, that is old. Glad you got it sorted, generic.

generic

10:58 pm on Feb 2, 2006 (gmt 0)

10+ Year Member



Thanks coopster.

Moose, at first I thought, hey, you're right. In retrospect, no - I was asking for a basic "double-check" not a problem with a specific part of the script. I thought it must have been a simple parse error so I was looking more for the problem being missing quotes, no semicolon to end lines, etc...

Having said that, I'll try and be a bit more concise in the future in regards to how I ask my questions and what code I post up.

Thanks guys. The feedback was appreciated!

[edited by: generic at 11:02 pm (utc) on Feb. 2, 2006]

StupidScript

11:00 pm on Feb 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did it have anything to do with

echo "<a href='$myrow['eventurl']' target='_blank'></a>$myrow['eventurl']</a><br>\n";

or

$myrow[eventurl]

?

In the first there is plenty of room for confusion re: your use of array elements in a single-quoted string. Neater if you assign the array element values to a new variable and then use them. ($eventurl=$myrow['eventurl'])

In the second you assume perhaps too much by not using proper syntax in referring to the array elements. They should be delimited with quotes or apostrophes. ($myrow['eventurl'] instead of $myrow[eventurl])

You should try to get your host to update their installation, as that archaic version of PHP has many known security issues that are still being exploited, and you will have trouble executing anything really fancy because the fancy PHP functions are probably not available. Heck, even 4.x releases are frustratingly outdated now.

generic

11:03 pm on Feb 2, 2006 (gmt 0)

10+ Year Member



Again, yea, cruddy code. If it's requested, I guess I can post my working code up for those looking for something similar but at this point, I don't know how useful that would be.

Anyway, thanks for the interest.