Jump to content

Archived

This topic is now archived and is closed to further replies.

Zbrahead91

Function help

Recommended Posts

i have a home-made function this is thje syntax:

[code]
<?php
#define functions:
function SELCONT($PGAREA) {


//assign values to mysql vars
echo"1";
$host = "localhost";
$dbuser = "PageData";
$dbpass = "pagedata";
$dbname = "PageData";
$dbtable = $page;
echo"1";
//Establish connections
mysql_connect("$host","$dbuser","$dbpass") or die("sorryno conn" . mysql_error());
echo"1";
mysql_select_db("$dbname") or die("sorryno conn" . mysql_error());
echo"1";
//Build query (BETA)

$query = "
SELECT
*
FROM
  `$dbtable`
  WHERE
  `zone`
  =
  $PGAREA
  " ;

//Execute and assign

$find = mysql_query("$query") or die (mysql_error());

$f = mysql_fetch_assoc($find) or mysql_error();

$cont = $f["cont"];
//Print result
echo("$cont");
}
?>
[/code]

on my index.php page which inlcudes this,
i want it to run this function: SELCONT(1) but it stops the page alltogether! and my html later on doesnt appear  (im debugging so this is what is contained in my index.php file:
[code]<?php
echo "Functioning...";

include("Core.php");
echo "included core";
echo "page is $page"; #Stops parsing here by the way
SELCONT("1");
echo "selcont ran"
?>



<html>

<head>

<title><?php SELCONT(1); ?></title>

<link rel=stylesheet type="text/css" href="style.css" />

</head>
<body>
<?php SELCONT(2); ?>
</body>
</html>
[/code])


in my database pagedata is a table HOME this is that home

[table]
[tr][td]cont[/td][td]zone[/td][/tr]
[tr][td]home[/td][td]1[/td][/tr]
[tr][td]Welcome Home debug successful :D[/td][td]2[/td][/tr]


[/table]       

Share this post


Link to post
Share on other sites
not sure if this will totaly solve it but you have not set $page as global in your function

try this

[code]<?php
#define functions:
function SELCONT($PGAREA) {
global $page;

//assign values to mysql vars
echo"1";
$host = "localhost";
$dbuser = "PageData";
$dbpass = "pagedata";
$dbname = "PageData";
$dbtable = $page;
echo"1";
//Establish connections
mysql_connect("$host","$dbuser","$dbpass") or die("sorryno conn" . mysql_error());
echo"1";
mysql_select_db("$dbname") or die("sorryno conn" . mysql_error());
echo"1";
//Build query (BETA)

$query = "
SELECT
*
FROM
  `$dbtable`
  WHERE
  `zone`
  =
  $PGAREA
  " ;

//Execute and assign

$find = mysql_query("$query") or die (mysql_error());

$f = mysql_fetch_assoc($find) or mysql_error();

$cont = $f["cont"];
//Print result
echo("$cont");
}
?>
[/code]

Regards
Liam

Share this post


Link to post
Share on other sites
no, this doesn't seem to work, i stripped the functiuon tags form core and ran it individually with a $pgarea var defiuned and the $page was in the url and it worked fine, this is what is really stumping me, thanjkss for tryin tho :D

Share this post


Link to post
Share on other sites
I think it's a SQL problem.


Try changing this:
$query = "SELECT * FROM `$dbtable` WHERE `zone`=$PGAREA";

To:
$query = "SELECT * FROM `$dbtable` WHERE zone='$PGAREA'";
(notice the after $PGAREA there's both a single quote and a double quote).

Orio.

Share this post


Link to post
Share on other sites
[quote]$f = mysql_fetch_assoc($find) or mysql_error();[/quote]

If there are no records found, mysql_fetch_assoc() returns false. But it is not an error therefore you won't get an error message. So if a function can legimately return false, do not use "or die()", or in this case "or mysql_error()"

[code]if ($f) {
    // echo value
}
else {
    echo "No recs found";
}[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.