Jump to content


Photo

Function help


  • Please log in to reply
4 replies to this topic

#1 Zbrahead91

Zbrahead91
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 06 August 2006 - 01:37 PM

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

<?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");
}
?>

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:
<?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>
)


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







contzone
home1
Welcome Home debug successful :D2
       



#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 06 August 2006 - 01:54 PM

not sure if this will totaly solve it but you have not set $page as global in your function

try this

<?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");
}
?>

Regards
Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 Zbrahead91

Zbrahead91
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 06 August 2006 - 02:00 PM

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

#4 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 06 August 2006 - 02:16 PM

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.
Think you're smarty?

(Gone until 20 to November)

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 06 August 2006 - 02:26 PM

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


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()"

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

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users