Jump to content

Function help


Zbrahead91

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]       

Link to comment
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
Link to comment
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.
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.