Functions not working/breaking PHP script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • koager
    New Member
    • Sep 2009
    • 18

    Functions not working/breaking PHP script

    I have various functions such as this throughout my script
    Code:
    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
    Code:
    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.
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    What do you mean 'it breaks'? Any errors?

    Comment

    • koager
      New Member
      • Sep 2009
      • 18

      #3
      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.
      Code:
      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

      Comment

      • koager
        New Member
        • Sep 2009
        • 18

        #4
        The alternate method of pasting sections in doesn't work well at all since other than that sql_functions.p hp 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
        Code:
        	$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
        Code:
        <? echo($ac_type) ?> <? echo($title)?> <? if ($brief_desc != '') { ?>(<? echo($brief_desc)?>) <? } ?>

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          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.
          Code:
          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.

          Comment

          • koager
            New Member
            • Sep 2009
            • 18

            #6
            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.ph p I have
            Code:
            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
            Code:
            <?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 "&nbsp"; } ?>
                  </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 "&nbsp"; } ?>
                  </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>&nbsp;</td><td>&nbsp;</td></tr>
                      <? echo($tech_specs)?>
                      </table>
                   <? } else { echo("&nbsp;"); }?>
                   <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>&nbsp;</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.p hp and config.php
            (from functions.php)
            Code:
            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
            Last edited by Atli; Sep 10 '09, 02:12 PM. Reason: Removed DB connection info. Please don't post real URIs and login info!

            Comment

            Working...