/    Sign up×
Community /Pin to ProfileBookmark

Functions? Correct Syntax? site is down please help!!!

Having major problems trying to use a function library. it will be more complex then the code I provide but I am confident that when we figure out what is going on here the other functions I write in the library will work out too.

first of alll couple of questions
a)Can I store multiple functions inside of on php file?
b)is this html right for calling the functions?
c)is the syntax correct for the function file.

B:

[code=html]
<?
include (“listingsfunc.php”);
dbconnect();
eventreg();
?>
<html>
<head></head><body><table><tr>
<td id=”rh-col”>
<h2 align=”center”><a name=”top”>The Official Erie Bar, Erie Club, <br />
and Erie Event Head Quarters</a></h2>
<hr align=”center” width=”75%” />
<br/>
<hr align=”center” width=”75%” />
<h3 align=”center”><a name=”level2″>Event Announcements</a></h3>
<hr align=”center” width=”75%” />
<? echo “$display_block”; ?>
<br />
<br />
</td>
</tr>
</table>
</body>
</html>

[/code]

C:

[code=php]<?php
//connects to my database for future querys
function dbconnect() {
$db_name = “markbad_markbadsql”;
$connection = @mysql_connect (“localhost”, “markbad_drpl1”, “pwremoved”)
or die (‘I cannot connect to the database because: ‘ . mysql_error());
$db = mysql_select_db ($db_name, $connection)
or die (‘I cannot connect to the database because: ‘ . mysql_error());
}
// Shows a regular listing of events from the past week.
function eventreg() {
$table_name = “events”;
$sql = “SELECT * FROM $table_name WHERE `date` BETWEEN DATE_SUB(CURDATE(), INTERVAL 6 DAY) and DATE_ADD(CURDATE(), INTERVAL 1 DAY)”;
$result = mysql_query($sql,$connection)
or die (mysql_error());
//While loop will create an array called $row
while ($row = mysql_fetch_array($result)) {
// get individual elements from events
$date = ($row[‘date’]);
$bar = ($row[‘bar’]);
$updated = ($row[‘updated’]);
$details = ($row[‘details’]);
$map_url = ($row[‘map_url’]);
$display_block .= ”
<h4>$bar <span class=”date”> $updated</span></h4>
<p>$details</p>
<div align=”right”><span class=”map”><a href=”$map_url” target=”_blank” title=”Erie Bar :: $bar”>Get Directions</a></span></div>
“;
}
}
?>[/code]

Please Help Me My whole site is down until I get this resolved!!
Thank you.

to post a comment
PHP

18 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 15.2006 — What error (or other problem) are you getting?
Copy linkTweet thisAlerts:
@Markbad311authorJan 15.2006 — What error (or other problem) are you getting?[/QUOTE]

funny part is all I am getting is a blank page with no HTML at all. I don't know if it is a permissions problem or I am just plain wrong.
Copy linkTweet thisAlerts:
@NogDogJan 15.2006 — Try adding some lines at the start of the main page to make sure error-reporting is happening, and use require instead of include to force a fatal error if the include file is not able to be read.
[code=php]
<?php
ini_set("display_errors", "1");
error_reporting(E_ALL);
require("listingsfunc.php");
dbconnect();
eventreg();
?>
[/code]

This is all intended to try our best to get PHP to tell us what's wrong.
Copy linkTweet thisAlerts:
@Markbad311authorJan 15.2006 — do you think it is a permissions problem?? I added
[code=php]
return $display_block;
[/code]

still the same results absolutely nothing! not even HTML!
Copy linkTweet thisAlerts:
@Markbad311authorJan 15.2006 — ok done did that and I have added a few things to the function library

here is the error I get

Notice: Undefined variable: connection in /home/markbad/public_html/listingsfunc.php on line 15

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/markbad/public_html/listingsfunc.php on line 15

and new PHP
[code=php]

<?php
//connects to my database for future querys
function dbconnect() {
$db_name = "markbad_markbadsql";
$connection = @mysql_connect ("localhost", "markbad_drpl1", "yup")
or die ('I cannot connect to the database because: ' . mysql_error());
$db = mysql_select_db ($db_name, $connection)
or die ('I cannot connect to the database because: ' . mysql_error());
return $connection;
}
// Shows a regular listing of events from the past week.
function eventreg() {
$table_name = "events";
$sql = "SELECT * FROM $table_name WHERE date BETWEEN DATE_SUB(CURDATE(), INTERVAL 6 DAY) and DATE_ADD(CURDATE(), INTERVAL 1 DAY)";
$result = mysql_query($sql,$connection)
or die (mysql_error());
//While loop will create an array called $row
while ($row = mysql_fetch_array($result)) {
// get individual elements from events
$date = ($row['date']);
$bar = ($row['bar']);
$updated = ($row['updated']);
$details = ($row['details']);
$map_url = ($row['map_url']);
$display_block .= "
<h4>$bar <span class="date"> $updated</span></h4>
<p>$details</p>
<div align="right"><span class="map"><a href="$map_url" target="_blank" title="Erie Bar :: $bar">Get Directions</a></span></div>
";
}
return $display_block;
}
?>[/code]
Copy linkTweet thisAlerts:
@chazzyJan 15.2006 — first problem i see is this line:
[code=php]
$sql = "SELECT * FROM $table_name WHERE date BETWEEN DATE_SUB(CURDATE(), INTERVAL 6 DAY) and DATE_ADD(CURDATE(), INTERVAL 1 DAY)";
[/code]

where are you defining $table_name?
Copy linkTweet thisAlerts:
@Markbad311authorJan 15.2006 — first problem i see is this line:
[code=php]
$sql = "SELECT * FROM $table_name WHERE date BETWEEN DATE_SUB(CURDATE(), INTERVAL 6 DAY) and DATE_ADD(CURDATE(), INTERVAL 1 DAY)";
[/code]

where are you defining $table_name?[/QUOTE]



right above the query

[code=php]
$table_name = "events";
$sql = "SELECT * FROM $table_name WHERE date BETWEEN DATE_SUB(CURDATE(), INTERVAL 6 DAY) and DATE_ADD(CURDATE(), INTERVAL 1 DAY)";
[/code]
Copy linkTweet thisAlerts:
@NogDogJan 15.2006 — $connection is local to the dbconnect() function, so is unknown to the eventreg() function. It should be OK to just delete the 2nd parameter of your mysql_query() call in the latter function, since you only have one active db connection anyway. (Otherwise, you'll either need to make it a global variable, or make it a parameter to the eventreg() function, catch the return value from the dbconnect() function, then use it as a parameter to the eventreg() function. But all that really should not be necessary in this case, so I'd just omit the 2nd mysql_query() parameter.)
Copy linkTweet thisAlerts:
@Markbad311authorJan 15.2006 — Ok well this is what I got. I am a newbie to this so I get confused real easy this is a little update of what I have done so far


I get this error:
[CODE]
Notice: Undefined variable: connection in /home/markbad/public_html/Untitled-4.php on line 6

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/markbad/public_html/listingsfunc.php on line 15
[/CODE]



here is the new function library

[code=php]
<?php
//connects to my database for future querys
function dbconnect() {
$db_name = "markbad_markbadsql";
$connection = @mysql_connect ("localhost", "markbad_drpl1", "no")
or die ('I cannot connect to the database because: ' . mysql_error());
$db = mysql_select_db ($db_name, $connection)
or die ('I cannot connect to the database because: ' . mysql_error());
return $connection;
}
// Shows a regular listing of events from the past week.
function eventreg($connection) {
$table_name = "events";
$sql = "SELECT * FROM $table_name WHERE date BETWEEN DATE_SUB(CURDATE(), INTERVAL 6 DAY) and DATE_ADD(CURDATE(), INTERVAL 1 DAY)";
$result = mysql_query($sql,$connection)
or die (mysql_error());
//While loop will create an array called $row
while ($row = mysql_fetch_array($result)) {
// get individual elements from events
$date = ($row['date']);
$bar = ($row['bar']);
$updated = ($row['updated']);
$details = ($row['details']);
$map_url = ($row['map_url']);
$display_block .= "
<h4>$bar <span class="date"> $updated</span></h4>
<p>$details</p>
<div align="right"><span class="map"><a href="$map_url" target="_blank" title="Erie Bar :: $bar">Get Directions</a></span></div>
";
}
return $display_block;
}
?>
[/code]


and the html using the two functions

[code=html]<?php
ini_set("display_errors", "1");
error_reporting(E_ALL);
require("listingsfunc.php");
dbconnect();
eventreg($connection);
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
<? echo "$display_block"; ?>
</body>
</html>
[/code]



Like I said I am having a real big problem still. Should I just make the functions complete and call them all together.
Copy linkTweet thisAlerts:
@NogDogJan 15.2006 — Just change this:
[code=php]
$result = mysql_query($sql,$connection)
[/code]

...to this:
[code=php]
$result = mysql_query($sql)
[/code]
Copy linkTweet thisAlerts:
@Markbad311authorJan 15.2006 — did that now I get this error


Notice: Undefined variable: connection in /home/markbad/public_html/Untitled-4.php on line 6

Notice: Undefined variable: display_block in /home/markbad/public_html/listingsfunc.php on line 29

Notice: Undefined variable: display_block in /home/markbad/public_html/Untitled-4.php on line 18
Copy linkTweet thisAlerts:
@chazzyJan 15.2006 — ::slaps head::

before your while loop, in the first code before i responded, add:
[code=php]
$display_block ="";
[/code]


you can't add to a value if it's not defined.
Copy linkTweet thisAlerts:
@Markbad311authorJan 15.2006 — The Problem is that the values aren't being returned to the script including it. thats a big problem lol!
Copy linkTweet thisAlerts:
@Markbad311authorJan 15.2006 — That kills one error

Notice: Undefined variable: connection in /home/markbad/public_html/Untitled-4.php on line 6

Notice: Undefined variable: display_block in /home/markbad/public_html/Untitled-4.php on line 18

so what is happening is The Functions are not returning the Variables. Even though I am using "return $connection; and return $display_block

I am running PHP version 4.4.1

is that a problem?? this is the first variable I have came across that wasn't doing its job. should I just make it global instead of returning it?
Copy linkTweet thisAlerts:
@bokehJan 15.2006 — you can't add to a value if it's not defined.[/QUOTE]You can... it's just that with error reporting set to E_ALL it raises a [I]notice[/I].
Copy linkTweet thisAlerts:
@NogDogJan 15.2006 — [code=php]
$connection = dbconnect();
eventreg($connection);
[/code]

($connection does not have a value in the main script unless you set it to something)
Copy linkTweet thisAlerts:
@chazzyJan 15.2006 — You can... it's just that with error reporting set to E_ALL it raises a [I]notice[/I].[/QUOTE]

My experience has been that it fails, and that's w/ 3 different installs (including a local) maybe it's a setting in php.ini

and I think NogDog just mentioned this but..
[code=php]
require("listingsfunc.php");
$connection = dbconnect();
eventreg($connection);
?>
[/code]


I'm a little surprised that PHP isn't throwing an error/warning along the lines of "Function returning value not returned into variable."
Copy linkTweet thisAlerts:
@Markbad311authorJan 15.2006 — JUST MADE IT GLOBAL and it WORKS!

here is the syntax !

[code=php]
<?php
//connects to my database for future querys

function dbconnect() {
global $connection;
$db_name = "markbad_markbadsql";
$connection = @mysql_connect ("localhost", "markbad_drpl1", "n4x4q37IhCez")
or die ('I cannot connect to the database because: ' . mysql_error());
$db = mysql_select_db ($db_name, $connection)
or die ('I cannot connect to the database because: ' . mysql_error());

}
// Shows a regular listing of events from the past week.
function eventreg($connection) {
global $display_block;
$table_name = "events";
$sql = "SELECT * FROM $table_name WHERE date BETWEEN DATE_SUB(CURDATE(), INTERVAL 6 DAY) and DATE_ADD(CURDATE(), INTERVAL 1 DAY)";
$result = mysql_query($sql)
or die (mysql_error());
$display_block ="";
//While loop will create an array called $row
while ($row = mysql_fetch_array($result)) {
// get individual elements from events
$date = ($row['date']);
$bar = ($row['bar']);
$updated = ($row['updated']);
$details = ($row['details']);
$map_url = ($row['map_url']);
$display_block .= "
<h4>$bar <span class="date"> $updated</span></h4>
<p>$details</p>
<div align="right"><span class="map"><a href="$map_url" target="_blank" title="Erie Bar :: $bar">Get Directions</a></span></div>
";
}

}
?>
[/code]
×

Success!

Help @Markbad311 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...