Connecting Tech Pros Worldwide Forums | Help | Site Map

Functions not working/breaking PHP script

Newbie
 
Join Date: Sep 2009
Posts: 16
#1: Sep 9 '09
I have various functions such as this throughout my script
Expand|Select|Wrap|Line Numbers
  1. function db1_select_query($sql) {
  2.     // Always query db1
  3.     db1_connection();
  4.     $res = mysql_query($sql);
  5.     if (!$res) {
  6.          echo("<P>Error performing query select: " . mysql_error() . "</P>");
  7.            exit();
  8.     }
  9.     db_close_connection1();
  10.       return $res;
  11. }
  12.  
and
Expand|Select|Wrap|Line Numbers
  1. function get_complete_record($id) {
  2.     // Declare Varibles Global or outside the function
  3.     global $product_id, $title, $ac_type, $brief_desc,
  4.          $description,$expiry_date, $tech_specs;
  5.  
  6.   if ($id == '') {
  7.          $sql = "select * from product where product_id = '" . $_GET['product_id'] . "'";  
  8.   } else {
  9.          $sql = "select * from product where product_id = '" . $id . "'";
  10.   }
  11.  
  12.   if ($debug) echo ($sql);
  13.  
  14.  
  15.     $result = db1_select_query($sql);
  16.  
  17.     // $result equals the number of rows effected
  18.     // It should always equal 1
  19.     if (mysql_numrows($result) == 0) {
  20.         // Session not established
  21.         return false;
  22.         exit();
  23.     }
  24.  
  25.     // Populate Variables
  26.     $product_id=mysql_result($result,0,"product_id");
  27.     $title=mysql_result($result,0,"title");
  28.     $ac_type=mysql_result($result,0,"ac_type");
  29.     $brief_desc=mysql_result($result,0,"brief_desc");
  30.     $description=mysql_result($result,0,"description");
  31.     $tech_specs=mysql_result($result,0,"tech_specs");   
  32.  
  33.     // Close up result set
  34.     mysql_free_result($result);
  35.     return true;
  36. }
  37.  
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.

Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#2: Sep 9 '09

re: Functions not working/breaking PHP script


What do you mean 'it breaks'? Any errors?
Newbie
 
Join Date: Sep 2009
Posts: 16
#3: Sep 9 '09

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.
Expand|Select|Wrap|Line Numbers
  1. ini_set('error_reporting', E_ALL);
  2. ini_set('display_errors', 'On');
  3. ini_set('display_startup_errors', 'On');
  4.  

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
#4: Sep 9 '09

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
Expand|Select|Wrap|Line Numbers
  1.     $title=$_POST["title"];
  2.     $ac_type=$_POST["ac_type"];
  3.     $brief_desc=$_POST["brief_desc"];
  4.     $description=$_POST["description"];
  5.     $tech_specs=$_POST["tech_specs"];
  6.  
as nothing is showing when I echo
Expand|Select|Wrap|Line Numbers
  1. <? echo($ac_type) ?> <? echo($title)?> <? if ($brief_desc != '') { ?>(<? echo($brief_desc)?>) <? } ?>
  2.  
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#5: Sep 9 '09

re: Functions not working/breaking PHP script


Quote:

Originally Posted by koager View Post

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.

Expand|Select|Wrap|Line Numbers
  1. ini_set('error_reporting', E_ALL);
  2. ini_set('display_errors', 'On');
  3. ini_set('display_startup_errors', 'On');
  4.  

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
#6: Sep 9 '09

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
Expand|Select|Wrap|Line Numbers
  1. function dbl_connection() {
  2.   // Define variables to use from global context
  3.   global $db1_name, $db1_host, $db1_user_name, $db1_password, $connection1, $connection2;
  4.  
  5.     $connection1 =  @mysql_connect("mysql.example.com", "helipodmysql", "passwd");
  6.     if (!$connection1) {  
  7.        die( "<P>Unable to connect to the database server at this time...<br>" . mysql_error() . "</P>" );  
  8.        exit();
  9.     }
  10.  
  11.     // Select the database
  12.     if (! @mysql_select_db("helipodmysql") ) {
  13.           echo( "<P>Unable to locate the database at this time.</P>" );
  14.           exit();
  15.     }
  16.     return $connection1;
  17. }
  18.  
  19. function db1_select_query($sql) {
  20.     // Always query db1
  21.     db1_connection();
  22.     $res = mysql_query($sql);
  23.     if (!$res) {
  24.          echo("<P>Error performing query select: " . mysql_error() . "</P>");
  25.            exit();
  26.     }
  27.     db_close_connection1();
  28.       return $res;
  29. }
  30.  
  31. function get_complete_record($id) {
  32.     // Declare Varibles Global or outside the function
  33.     global $product_id, $title, $ac_type, $brief_desc,
  34.          $description,$expiry_date, $tech_specs;
  35.  
  36.   if ($id == '') {
  37.          $sql = "select * from product where product_id = '" . $_GET['product_id'] . "'";  
  38.   } else {
  39.          $sql = "select * from product where product_id = '" . $id . "'";
  40.   }
  41.  
  42.   if ($debug) echo ($sql);
  43.  
  44.  
  45.     $result = db1_select_query($sql);
  46.  
  47.     // $result equals the number of rows effected
  48.     // It should always equal 1
  49.     if (mysql_numrows($result) == 0) {
  50.         // Session not established
  51.         return false;
  52.         exit();
  53.     }
  54.  
  55.     // Populate Variables
  56.     $product_id=mysql_result($result,0,"product_id");
  57.     $title=mysql_result($result,0,"title");
  58.     $ac_type=mysql_result($result,0,"ac_type");
  59.     $brief_desc=mysql_result($result,0,"brief_desc");
  60.     $description=mysql_result($result,0,"description");
  61.     $tech_specs=mysql_result($result,0,"tech_specs");   
  62.  
  63.     // Close up result set
  64.     mysql_free_result($result);
  65.     return true;
  66. }
  67.  
ect...with more functions
and then on the actual page such as my details.php I have
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include("inc/header_functions.php");
  3.  
  4. $record_exists = get_complete_record($_GET['id']);
  5.  
  6. ?>
  7. <? include 'header.php'; ?>
  8.  
  9.  
  10.   <table  cellspacing="15" class="Table" align="center">
  11.      <tr>
  12.       <td class="FieldsHeading" colspan="2">
  13.         <? echo($ac_type) ?> <? echo($title)?> <? if ($brief_desc != '') { ?>(<? echo($brief_desc)?>) <? } ?>
  14.       </td>
  15.     </tr>
  16.     <tr>
  17.       <td class="FieldText" align="left" valign="top" width="50%">
  18.         <? echo($description)?>
  19.       </td>
  20.       <td class="FieldText" align="center" valign="middle" >
  21.         <? if (file_exists($pic_uploaddir . "prod_" . $product_id . "_pic_0.JPG")) { ?>
  22.         <img src="/img/product/prod_<? echo $product_id; ?>_pic_0.JPG" />
  23.         <? } else { echo "&nbsp"; } ?>
  24.       </td>
  25.     </tr>
  26.     <tr>
  27.       <td class="FieldLabel" align="right" valign="top" width="50%">
  28.         <? if (file_exists($pic_uploaddir . "prod_" . $product_id . "_pic_1.JPG")) { ?>
  29.         <img src="/img/product/prod_<? echo $product_id; ?>_pic_1.JPG" />
  30.         <? } else { echo "&nbsp"; } ?>
  31.       </td>
  32.       <td align="center" valign="middle">
  33.       <? if ($tech_specs != '') { ?>
  34.         <table width="100%">
  35.           <tr><td colspan="2" class="TechSpecs">Technical Specifications</td></tr>
  36.           <tr><td width=150>&nbsp;</td><td>&nbsp;</td></tr>
  37.           <? echo($tech_specs)?>
  38.           </table>
  39.        <? } else { echo("&nbsp;"); }?>
  40.        <table><tr><td align="center"><a class="DealersLink" href="/dist_results.php" >Locate a Dealer</a></td></tr></table>
  41.        </td>
  42.     </tr>
  43.     <? if (file_exists($pic_uploaddir . "prod_" . $product_id . "_pic_2.JPG")) { ?>
  44.     <tr>
  45.       <td>&nbsp;</td>
  46.       <td class="FieldLabel" align="center" valign="top" width="50%">
  47.             <a class="" href="/certs.php?product_id=<? echo($product_id); ?>" >Click here for<br>Certifications and Approvals</a>
  48.       </td>
  49.     </tr>
  50.     <? } ?>
  51.   </table>
  52. <br>
  53.  
  54.   <? include("footer.php"); ?>
  55.  
where header.php has include function.php which consists of more functions and also include sql_functions.php and config.php
(from functions.php)
Expand|Select|Wrap|Line Numbers
  1. function populate_var_from_post() {
  2.   global $product_id, $title, $ac_type, $brief_desc, $description, $tech_specs;
  3.  
  4.     //$product_id=$_POST["product_id"];
  5.     $title=$_POST["title"];
  6.     $ac_type=$_POST["ac_type"];
  7.     $brief_desc=$_POST["brief_desc"];
  8.     $description=$_POST["description"];
  9.     $tech_specs=$_POST["tech_specs"];
  10. }
  11.  
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
Reply