Zbrahead91 Posted August 6, 2006 Share Posted August 6, 2006 i have a home-made function this is thje syntax:[code]<?php#define functions:function SELCONT($PGAREA) {//assign values to mysql varsecho"1";$host = "localhost";$dbuser = "PageData";$dbpass = "pagedata";$dbname = "PageData";$dbtable = $page;echo"1";//Establish connectionsmysql_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 resultecho("$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]<?phpecho "Functioning...";include("Core.php");echo "included core";echo "page is $page"; #Stops parsing here by the waySELCONT("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] Link to comment https://forums.phpfreaks.com/topic/16705-function-help/ Share on other sites More sharing options...
shocker-z Posted August 6, 2006 Share Posted August 6, 2006 not sure if this will totaly solve it but you have not set $page as global in your functiontry this[code]<?php#define functions:function SELCONT($PGAREA) {global $page;//assign values to mysql varsecho"1";$host = "localhost";$dbuser = "PageData";$dbpass = "pagedata";$dbname = "PageData";$dbtable = $page;echo"1";//Establish connectionsmysql_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 resultecho("$cont");}?>[/code]RegardsLiam Link to comment https://forums.phpfreaks.com/topic/16705-function-help/#findComment-70199 Share on other sites More sharing options...
Zbrahead91 Posted August 6, 2006 Author Share Posted August 6, 2006 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 Link to comment https://forums.phpfreaks.com/topic/16705-function-help/#findComment-70202 Share on other sites More sharing options...
Orio Posted August 6, 2006 Share Posted August 6, 2006 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. Link to comment https://forums.phpfreaks.com/topic/16705-function-help/#findComment-70209 Share on other sites More sharing options...
Barand Posted August 6, 2006 Share Posted August 6, 2006 [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] Link to comment https://forums.phpfreaks.com/topic/16705-function-help/#findComment-70211 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.