473,467 Members | 1,472 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Functions not working/breaking PHP script

18 New Member
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.
Sep 9 '09 #1
5 2136
Markus
6,050 Recognized Expert Expert
What do you mean 'it breaks'? Any errors?
Sep 9 '09 #2
koager
18 New Member
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
Sep 9 '09 #3
koager
18 New Member
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.  
Sep 9 '09 #4
Markus
6,050 Recognized Expert Expert
@koager
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.
Sep 9 '09 #5
koager
18 New Member
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
Sep 9 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: David Walker | last post by:
Hi again As I'm developing my site, i've come across a problem with the database use. While developing it I only have mySQL, but the final server has msSQL. I was thinking about using all my own...
99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
6
by: Unregistered | last post by:
I am very new to javascript, but I am trying to write a script that wil that will be in a pop-up window with a form after the user hits submit button at the bottom I want that current pop-up to...
5
by: knocte | last post by:
Hello. I am a web developer very worried about "bloat code" and "languages mixture". So, since some time, I always try to avoid completely the use of javascript in XHTML/HTML files. This leads...
1
by: PTS | last post by:
I am working on a program that will calculate some numbers. As an example, I will say student average test score and print out the grade but my question is how do I put AVERAGE and test score and...
0
by: Jay Balapa | last post by:
Hello, I posted this under security and there were no replies. We have a website running ASP.Net 1.1 using forms authentication and even protects .htm/.doc files. We have associated such files...
2
by: Jay Balapa | last post by:
Hello, I posted this under general group and no replies. We have a website running ASP.Net 1.1 using forms authentication and even protects .htm/.doc files. We have associated such files to...
2
by: kwenterprise | last post by:
Hello All, I am normally great at figuring out ways around iframe issues that frustrate us all. I am using javasript to try and break an iframe that I have a banner rotator embedded in but it...
4
by: Mike | last post by:
Hi, I took an interest a few months ago in an anti framebreaker javascript. All my research told me that it was impossible. If a website is loaded into a frame/iframe then if it has frame...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.