Functions not working/breaking PHP script | Newbie | | Join Date: Sep 2009
Posts: 16
| |
I have various functions such as this throughout my script -
function db1_select_query($sql) {
-
// Always query db1
-
db1_connection();
-
$res = mysql_query($sql);
-
if (!$res) {
-
echo("<P>Error performing query select: " . mysql_error() . "</P>");
-
exit();
-
}
-
db_close_connection1();
-
return $res;
-
}
-
and -
function get_complete_record($id) {
-
// Declare Varibles Global or outside the function
-
global $product_id, $title, $ac_type, $brief_desc,
-
$description,$expiry_date, $tech_specs;
-
-
if ($id == '') {
-
$sql = "select * from product where product_id = '" . $_GET['product_id'] . "'";
-
} else {
-
$sql = "select * from product where product_id = '" . $id . "'";
-
}
-
-
if ($debug) echo ($sql);
-
-
-
$result = db1_select_query($sql);
-
-
// $result equals the number of rows effected
-
// It should always equal 1
-
if (mysql_numrows($result) == 0) {
-
// Session not established
-
return false;
-
exit();
-
}
-
-
// Populate Variables
-
$product_id=mysql_result($result,0,"product_id");
-
$title=mysql_result($result,0,"title");
-
$ac_type=mysql_result($result,0,"ac_type");
-
$brief_desc=mysql_result($result,0,"brief_desc");
-
$description=mysql_result($result,0,"description");
-
$tech_specs=mysql_result($result,0,"tech_specs");
-
-
// Close up result set
-
mysql_free_result($result);
-
return true;
-
}
-
but it seems to break the script right at the function *() { line
however I don't see anything wrong with it and I know that it's suppose to work since the website has worked before and I was just given all the files to push up on the server I am working on now.
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,949
| | | re: Functions not working/breaking PHP script
What do you mean 'it breaks'? Any errors?
| | Newbie | | Join Date: Sep 2009
Posts: 16
| | | re: Functions not working/breaking PHP script
Weird, the website timed out on me when I tried editing my post to include that part.
For some reason when I add the three lines below to the top of the script still nothing happens, even though it is suppose to display something when I test it with echo "no it doesnt work". I don't get any errors; just a blank page. -
ini_set('error_reporting', E_ALL);
-
ini_set('display_errors', 'On');
-
ini_set('display_startup_errors', 'On');
-
I went through the script with echo "yes it works"; to figure out where the script was stopping and giving me a blank page
I had a function around my connection to the database, too, but I removed that as I went through the script and saw not a real need for it as nothing is calling the variable that it returns. I was able to connect to the database afterward, but I don't think I can do that with the rest as they return things and calls them. The other choice I suppose I have is to separate them out from that page and the paste them into each individual .php page where the variables are required in that instance.
There shouldn't be any errors at all since this was someone else's website that was working and up. I was given all the files to push up onto the server that I am on now.
_____________________
side question:
In the url if I put subdomain/domain I get an endless refreshing of a blank page so I have to do subdomain/domain/index.php to actually load the home page.
Is there a way around that as in it should directly show index.php
| | Newbie | | Join Date: Sep 2009
Posts: 16
| | | re: Functions not working/breaking PHP script
The alternate method of pasting sections in doesn't work well at all since other than that sql_functions.php I also have functions.php and config.php which also seems to have the issue with the script breaking when there is a function
and none of variables such as these seem to work -
$title=$_POST["title"];
-
$ac_type=$_POST["ac_type"];
-
$brief_desc=$_POST["brief_desc"];
-
$description=$_POST["description"];
-
$tech_specs=$_POST["tech_specs"];
-
as nothing is showing when I echo -
<? echo($ac_type) ?> <? echo($title)?> <? if ($brief_desc != '') { ?>(<? echo($brief_desc)?>) <? } ?>
-
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,949
| | | re: Functions not working/breaking PHP script Quote:
Originally Posted by koager Weird, the website timed out on me when I tried editing my post to include that part.
For some reason when I add the three lines below to the top of the script still nothing happens, even though it is suppose to display something when I test it with echo "no it doesnt work". I don't get any errors; just a blank page. -
ini_set('error_reporting', E_ALL);
-
ini_set('display_errors', 'On');
-
ini_set('display_startup_errors', 'On');
-
I went through the script with echo "yes it works"; to figure out where the script was stopping and giving me a blank page
I had a function around my connection to the database, too, but I removed that as I went through the script and saw not a real need for it as nothing is calling the variable that it returns. I was able to connect to the database afterward, but I don't think I can do that with the rest as they return things and calls them. The other choice I suppose I have is to separate them out from that page and the paste them into each individual .php page where the variables are required in that instance.
There shouldn't be any errors at all since this was someone else's website that was working and up. I was given all the files to push up onto the server that I am on now.
_____________________
side question:
In the url if I put subdomain/domain I get an endless refreshing of a blank page so I have to do subdomain/domain/index.php to actually load the home page.
Is there a way around that as in it should directly show index.php Can I see your fully revised copy of the source code now please?
To your second question, depending on your server, you can set the default landing page(s) if one isn't provided. However, you'll have to ask in the relevant server forum.
| | Newbie | | Join Date: Sep 2009
Posts: 16
| | | re: Functions not working/breaking PHP script
Nothing was really revised as I was just messing around with the code trying to get things to work but then just reverting it back as things were still breaking
on my sql_function.php I have -
function dbl_connection() {
-
// Define variables to use from global context
-
global $db1_name, $db1_host, $db1_user_name, $db1_password, $connection1, $connection2;
-
-
$connection1 = @mysql_connect("mysql.example.com", "helipodmysql", "passwd");
-
if (!$connection1) {
-
die( "<P>Unable to connect to the database server at this time...<br>" . mysql_error() . "</P>" );
-
exit();
-
}
-
-
// Select the database
-
if (! @mysql_select_db("helipodmysql") ) {
-
echo( "<P>Unable to locate the database at this time.</P>" );
-
exit();
-
}
-
return $connection1;
-
}
-
-
function db1_select_query($sql) {
-
// Always query db1
-
db1_connection();
-
$res = mysql_query($sql);
-
if (!$res) {
-
echo("<P>Error performing query select: " . mysql_error() . "</P>");
-
exit();
-
}
-
db_close_connection1();
-
return $res;
-
}
-
-
function get_complete_record($id) {
-
// Declare Varibles Global or outside the function
-
global $product_id, $title, $ac_type, $brief_desc,
-
$description,$expiry_date, $tech_specs;
-
-
if ($id == '') {
-
$sql = "select * from product where product_id = '" . $_GET['product_id'] . "'";
-
} else {
-
$sql = "select * from product where product_id = '" . $id . "'";
-
}
-
-
if ($debug) echo ($sql);
-
-
-
$result = db1_select_query($sql);
-
-
// $result equals the number of rows effected
-
// It should always equal 1
-
if (mysql_numrows($result) == 0) {
-
// Session not established
-
return false;
-
exit();
-
}
-
-
// Populate Variables
-
$product_id=mysql_result($result,0,"product_id");
-
$title=mysql_result($result,0,"title");
-
$ac_type=mysql_result($result,0,"ac_type");
-
$brief_desc=mysql_result($result,0,"brief_desc");
-
$description=mysql_result($result,0,"description");
-
$tech_specs=mysql_result($result,0,"tech_specs");
-
-
// Close up result set
-
mysql_free_result($result);
-
return true;
-
}
-
ect...with more functions
and then on the actual page such as my details.php I have -
<?php
-
include("inc/header_functions.php");
-
-
$record_exists = get_complete_record($_GET['id']);
-
-
?>
-
<? include 'header.php'; ?>
-
-
-
<table cellspacing="15" class="Table" align="center">
-
<tr>
-
<td class="FieldsHeading" colspan="2">
-
<? echo($ac_type) ?> <? echo($title)?> <? if ($brief_desc != '') { ?>(<? echo($brief_desc)?>) <? } ?>
-
</td>
-
</tr>
-
<tr>
-
<td class="FieldText" align="left" valign="top" width="50%">
-
<? echo($description)?>
-
</td>
-
<td class="FieldText" align="center" valign="middle" >
-
<? if (file_exists($pic_uploaddir . "prod_" . $product_id . "_pic_0.JPG")) { ?>
-
<img src="/img/product/prod_<? echo $product_id; ?>_pic_0.JPG" />
-
<? } else { echo " "; } ?>
-
</td>
-
</tr>
-
<tr>
-
<td class="FieldLabel" align="right" valign="top" width="50%">
-
<? if (file_exists($pic_uploaddir . "prod_" . $product_id . "_pic_1.JPG")) { ?>
-
<img src="/img/product/prod_<? echo $product_id; ?>_pic_1.JPG" />
-
<? } else { echo " "; } ?>
-
</td>
-
<td align="center" valign="middle">
-
<? if ($tech_specs != '') { ?>
-
<table width="100%">
-
<tr><td colspan="2" class="TechSpecs">Technical Specifications</td></tr>
-
<tr><td width=150> </td><td> </td></tr>
-
<? echo($tech_specs)?>
-
</table>
-
<? } else { echo(" "); }?>
-
<table><tr><td align="center"><a class="DealersLink" href="/dist_results.php" >Locate a Dealer</a></td></tr></table>
-
</td>
-
</tr>
-
<? if (file_exists($pic_uploaddir . "prod_" . $product_id . "_pic_2.JPG")) { ?>
-
<tr>
-
<td> </td>
-
<td class="FieldLabel" align="center" valign="top" width="50%">
-
<a class="" href="/certs.php?product_id=<? echo($product_id); ?>" >Click here for<br>Certifications and Approvals</a>
-
</td>
-
</tr>
-
<? } ?>
-
</table>
-
<br>
-
-
<? include("footer.php"); ?>
-
where header.php has include function.php which consists of more functions and also include sql_functions.php and config.php
(from functions.php) -
function populate_var_from_post() {
-
global $product_id, $title, $ac_type, $brief_desc, $description, $tech_specs;
-
-
//$product_id=$_POST["product_id"];
-
$title=$_POST["title"];
-
$ac_type=$_POST["ac_type"];
-
$brief_desc=$_POST["brief_desc"];
-
$description=$_POST["description"];
-
$tech_specs=$_POST["tech_specs"];
-
}
-
and ect with more functions setting things
What I mainly don't understand is if it all worked perfectly before, the website should work after I uploaded the MySql database exactly as they had it, since I just imported a file, and then changed host, username, and password so that it can connect and pull the information that is needed
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,510 network members.
|