Jump to content

Blank screens after adding hook


ZeroGravity

Recommended Posts

I am new to WHMCS and PHP (but not to programming). I am trying to add a hook to create a custom inovice number. Just starting with the system I'm not wanting my invoice numbers to be 1,2,3... I picked up the code from another thread.

 

When I put the php file in the includes/hooks directory I get blank pages when saving settings. If I delete the file everything works fine. I have added the following to configration.php but nothing appears on the screen at all.

 

error_reporting(E_ALL); 
$display_errors = true;
$mysql_errors = true;

 

eg. I put the PHP file in the hook folder. Go to the Setup->General Settings page Invoices tab. Change one of the settings and click "Save Changes." I get a blank screen. Click the browser back button and the General Setting->General Tab is displayed. Go to the Invoices Tab and the changes have been saved. If I remove the file from the hooks directory the changes save and the screen refreshes with the confirmation message displayed at the top.

 

I have commented the add_hook line and even commented every line of code inside the function but the error stills happens.

 

Error aside I am not sure if I am going about this the correct way so any advice and assisstance is appreciated.

 

Here is the code in custom_invoice_number.php

<?php
add_hook("InvoiceCreationPreEmail",1,"custom_invoice_number");

function custom_invoice_number($invoiceid) { 

   // generate invoice number and save 
   $customnumber = date("Ym") . $invoiceid; // = 201004312 
   mysql_query ("UPDATE tblinvoices SET invoicenum='$customnumber' WHERE id='$invoiceid' LIMIT 1"); 

   // check 
   $d = array(); 
   $q = mysql_query("SELECT id, invoicenum FROM tblinvoices WHERE id='$invoiceid' LIMIT 1"); 
   while ($row = mysql_fetch_array($q)) { 
       if ($row['invoicenum'] == '') { 
           $d['message'] = 'no invoicenumber stored'; 
      } else { 
           $d['id'] = $row['id']; 
           $d['invoicenum'] = $row['invoicenum']; 
       } 
   } 

   // make response 
   // standard response construction 
   #echo "a=fuffig;b=faffig;c=lalala"; 
   echo 'id=' . $d['id'] . ';invoicenum=' . $d['invoicenum']; 
} 
?>

 

Many Thanks

Link to comment
Share on other sites

Make sure that the files in the hooks folder only contain code for your hook functions. Any other files in this directory (like an error log) will screw things up.

 

But also your syntax is wrong for your hook function. All variables come into the function within an array even if the hook function has only a single var.

You need something like:

 


<?php
add_hook("InvoiceCreationPreEmail",1,"custom_invoice_number");

function custom_invoice_number($vars) {
  $invoiceid = $vars['invoiceid'];

 

at the beginning of your code.

Edited by tomdchi
Link to comment
Share on other sites

Thanks for the heads up on the variables @tomdchi. I made the change you suggested but it didn't change what was happening.

 

I created the hook using example.php as the base. In desperation I recreated the hook using the other sample in the hook directory (vatnumbervalidation.php) as the base. The blank screen problem is no longer happening. I haven't got the time to work out why I was getting blank screens particularly as it isn't happening anymore.

 

But... the hook isn't working, invoicenum is not being updated. I copied the SQL and used it in phpMyAdmin and it worked there. Is there something else that I haven't done?

 

add_hook("InvoiceCreationPreEmail",1,"custom_invoice_number");

function custom_invoice_number($vars) { 
    $invoiceid = $vars['invoiceid'];

   // generate invoice number and save 
   $customnumber = date("Ym") . $invoiceid; // = 201004312 
   mysql_query ("UPDATE tblinvoices SET invoicenum='$customnumber' WHERE id='$invoiceid'"); 

   // check 
   $d = array(); 
   $q = mysql_query("SELECT id, invoicenum FROM tblinvoices WHERE id='$invoiceid' LIMIT 1"); 
   while ($row = mysql_fetch_array($q)) { 
       if ($row['invoicenum'] == '') { 
           $d['message'] = 'no invoicenumber stored'; 
       } else { 
           $d['id'] = $row['id']; 
           $d['invoicenum'] = $row['invoicenum']; 
       } 
   } 

   // make response 
   // standard response construction 
   #echo "a=fuffig;b=faffig;c=lalala"; 
   echo 'id=' . $d['id'] . ';invoicenum=' . $d['invoicenum']; 
}

 

 

When exactly in the process does this action occur?

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated