Jump to content

scottybwoy

Members
  • Posts

    532
  • Joined

  • Last visited

    Never

Posts posted by scottybwoy

  1. Hi Crew,

     

    I'm trying to present a MSSQL timestamp in php.  If I select the record and put it in a $var and try to echo it like so :

     

    echo date(DMdY, $date);

    echo date(Gi, $date);

     

    It always returns Thu01011970 So how would I get this to display correctly?

     

    Thanks in advance

  2. OK I got around the other two errors.

     

    For the optional arguments within the func spec i added = false.  Like so :

    <?php
    function test($foo, $bar = FALSE) {
        echo $foo . $bar;
    }
    ?>
    

     

    second error, I now use my predefined database functions and store the parameters in a csv string in the database like so :

    <?php
    $msgType = 3;
    $userId = $_SESSION['USER_ID'];
    $msg = "Changed $old data was updated with this $new data";
    $qryParams = "SELECT_ALL,$tbl,$col,$val,";
    
    if (isset($optionalCol)) {
     $qry .= ",$optionalCol,$optionalVal";
    }
    
    $msgcols = "(msgType, userId, msg, qry)";
    $msgvals = "(3, '" . $userId . "', '" . $msg . "', '" . $qry . "')";
    
    $sql = "INSERT INTO msgLog $msgcols VALUES $msgvals";
    mssql_query($sql);
    ?>
    

     

    Then to call it I just use :

    <?php
    if(preg_match("SELECT_ALL", $qryParams) {
        $this->select($tbl, $col, $val);
    }
    ?>
    

     

    Although I still thinks thats a bit messy if some one can see a clearer case still I'd be glad.

     

    Thanks

  3. OK I solved my second problem which I thought would be the hardest by using array_intersect_keys()

     

    So that section now looks like so :

     

    <?php
    
    $keys = array_keys($diff);
    $keys = implode(', ', $keys);
    $keys = substr($keys, 0, -2);
    $old = array_intersect_key($arr1, $diff);
    $old = implode(', ', $old);
    $new = implode(', ', $diff);
    
    $msgType = 3;
    $userId = $_SESSION['USER_ID'];
    $msg = "Changed $keys from : $old to : $new where $col = $val in $tbl";
    echo $msg . "<br>";
    
    ?>
    

     

    Any updates on the other issues?

  4. Hi All,

     

    I'm just updating a function of mine but there are a few problems I'd like to clear.  First the code then I'l point out the issues.

     

    <?php
    // Checks if $arr1 has anything extra than $arr2 then writes those diffrences
    // to $tbl at the given location
    function updateDiff($arr1, $arr2, $tbl, $col, $val, $optionalCol, $optionalVal) {
    
    if (!empty($diff)) {
    	$colvals = "";
    
    	foreach ($diff as $k => $v) {
    		trim($v);
    		$this->cleanSql($v);
    		if (is_int($v)) {
    			$colvals .= $k . " = $v, ";
    		} else {
    			$colvals .= $k . " = '" . $v . "', ";
    		}
    
    	}
    
    	$colvals = substr($colvals, 0, -2);
    	$sql = "UPDATE $tbl SET " . $colvals . " WHERE $col = '" . $val . "'";
    
    	if (isset($optionalCol)) {
    		$sql .= " AND $optionalCol = '" . $optionalVal . "'";
    	}
    
    	mssql_query($sql) or trigger_error("Failed to Update $tbl where $col = $val!", E_USER_ERROR);
    
    	$keys = array_keys($diff);
    \\-- Think I need a foreach() here!
    	$keys = implode(', ', $keys);
    	$old = implode(', ', $arr1);
    	$new = implode(', ', $diff);
    
    	$msgType = 3;
    	$userId = $_SESSION['USER_ID'];
    	$msg = "Changed $old data was updated with this $new data";
    	$qry = "SELECT * FROM $tbl WHERE $col = '" . $val . "'";
    
    	if (isset($optionalCol)) {
    		 $qry .= " AND $optionalCol = '" . $optionalVal . "'";
    	} 
    
    	$msgcols = "(msgType, userId, msg, qry)";
    	$msgvals = "(3, \'" . $userId . "\', \'" . $msg . "\', \'" . $qry . "\')";
    
    	$sql = "INSERT INTO msgLog $msgcols VALUES $msgvals";
    	mssql_query($sql) or trigger_error("Failed to Log Confirmation Message", E_USER_WARNING);
    } else {
    	trigger_error("Nothing to change", E_USER_NOTICE);
    }
    }
    ?>
    

     

    First of all in the supplied arguments for the func, is there a way of specifying the them to be optional for instance like with [] but I tried that already, and I know the func will work anyway so isn't too important.

     

    Second, where I put the comment for a foreach() I'd like to change my $msg to read :

    "Changed $keys in original row from $oldvals to $newvals"

    Now I have $keys and $newvals but to get $oldvals I need to extract just the keys from $arr2 that are in $diff and put the values into a string in the same format,  I'm a bit stuck on how to go about that.

     

    Lastly, I want to store a query in my table, but it doesn't like the syntax, can anyone tell me the correct way to do it,  thanks for your help.

  5. Morning all,

     

    I've come to a point where I can't get my head round how to do what I want to do.  So I wondered if anyone here has done it or can point me in the right direction.

     

    I have a CRM system and I want a messaging and sort of logging system in one.  The screen is broken up into five parts :

    1) A header section with search fields date and time.

    2) A left hand main section with relevant forms and menus.

    3) An upper right hand section where I want my messages and alert sections to appear.

    4) A lower right hand section where random product info appears as an aid to the employee.

    5) And a footer section that displays targets and other constructive data.

     

    In my messaging system I have three types of messages :

    1) Confirmation msg, telling them what they have done. i.e. Customer Removed.

    2) Process msg, advising the user what is to be done i.e. Ring customer.

    3) Error msg i.e. Please check post code.

     

    Now I know how to make the trigger work to display the alerts, but can't think of a what data I need to store and how to.  For instance if the user has just input a new product.  I want it so that If they click on the the msg "Product 'name' has been added" I want it to bring up the page for that product 'name' for them to review what has just been added, and to amend if need be.

     

    Also I wish to make an error log but with more descriptions for me the administrator and polite messages for the user.  Could this be stored in the same table?

     

    My format for data storage I was thinking of would be to have :

     

    msgId          int        for logging purposes

    msgType      smallint  to distinguish msgs

    msg            varchar  what is to be displayed

    sql              varchar  if data needs to be called how to do it (Nulls allowed)

     

    Is this a satisfactory way of going about it?

  6. Yep now we are on the right trail.  As expected LOGON_USER is not available in the $_SERVER array.

     

    What else should I be looking for?  Here are some results that may be useful :

     

    [CONTENT_LENGTH] => 0

    [GATEWAY_INTERFACE] => CGI/1.1

    [HTTPS] => off

    [HTTP_ACCEPT] => */*

    [HTTP_ACCEPT_LANGUAGE] => en-gb

    [HTTP_CONNECTION] => Keep-Alive

    [HTTP_USER_AGENT] => Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727)

    [HTTP_COOKIE] => debug_port=10013; debug_host=192.168.0.22; start_debug=1; debug_stop=1; send_sess_end=1; debug_jit=1;

    [HTTP_ACCEPT_ENCODING] => gzip, deflate

    [iNSTANCE_ID] => 1

    [NUMBER_OF_PROCESSORS] => 2

    [Os2LibPath] => D:\WINNT\system32\os2\dll;

    [OS] => Windows_NT

    [Path] => D:\WINNT\system32;D:\WINNT;D:\WINNT\System32\Wbem;D:\php;D:\Program Files\Microsoft SQL Server\80\Tools\Binn\;D:\Program Files\Microsoft SQL Server\90\Tools\binn\

    [PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH

    [PROCESSOR_ARCHITECTURE] => x86

    [PROCESSOR_IDENTIFIER] => x86 Family 15 Model 4 Stepping 1, GenuineIntel

    [PROCESSOR_LEVEL] => 15

    [PROCESSOR_REVISION] => 0401

    [ProgramFiles] => D:\Program Files

    [REMOTE_ADDR] => 192.168.0.7

    [REMOTE_HOST] => 192.168.0.7

    [REQUEST_METHOD] => GET

    [sCRIPT_NAME] => /name.php

    [sERVER_PORT] => 80

    [sERVER_PORT_SECURE] => 0

    [sERVER_PROTOCOL] => HTTP/1.1

    [sERVER_SOFTWARE] => Microsoft-IIS/5.0

    [ORIG_PATH_INFO] => /name.php

    [ORIG_SCRIPT_NAME] => /name.php

    [php_SELF] => /name.php

    [REQUEST_TIME] => 1176799554

     

    What I found peculiar is that the debug host is 192.168.0.22 which is neither the servers ip nor my pc (192.168.0.7 <- dynamically assigned) and HTTP_USER_AGENT is Mozilla/4.0 although I loaded it via IE6.1?

     

    Also $_ENV array returned empty, could this be part of the cause?

  7. Yes, you are correct.  I was not planning to turn off error reporting and have not.  Maybe I should make this a little clearer as boo_lolly got mixed up with $_SERVER & $_SESSION, I am using windows 2k environment and to my understanding $_SERVER['LOGON_USER'] Should display the current username logged on to Windows environment, however this is returning null.

     

    I thought it may be down to the way it was executed as in the manual it suggests this predefined variable works differently under different environments, (no surprises there).  However I am using the same version of IIS and php with the same phi.ini config file and same scripts as before yet it is not working as before.

     

    Can anyone spot the hole from the info I have given so far.

     

    The IIS Box is also acting as DHCP+DNS server running active directory too if that helps.

     

    Thanks for your time and input.

  8. Hi guru's,

     

    I have a script that was working fine until I had to reinstall everything.  Now my scripts says that :

     

    PHP Notice: Undefined index: LOGON_USER in D:\Inetpub\wwwroot\name.php on line 5

     

    Where I have just made a new file to isolate the issue, but this derives from this script :

     

    <?php
    
    echo $_SERVER['LOGON_USER'];
    
    ?>
    

     

    Which worked fine before.  Is this down to the way php is being run? As it stands it is being run via IIS 5 as cgi executable.  I've looked over the install txt and it seems as though I have done everything correct.

  9. Yep that done the trick, thanks.  However I now get this message :

     

    PHP Warning: mssql_select_db() [function.mssql-select-db]: message: The server principal "MRI\IUSR_MRI-SERVER" is not able to access the database "mri_sql" under the current security context. (severity 14) in D:\Inetpub\wwwroot\testing\classes\config.inc.php on line 121

     

    So I added IUSER_MRI-SERVER to the MSSQL USER group in Active directory, but that didn't do it.  I don't remember doing much else like this before.  Any ideas?

     

    What do u mean about that pikemsu28, it should be using Windows Authentication.

  10. Hi All,

     

    The main server at work which I was working from, Died! Damn Hard drives! Luckily I didn't lose all the work, however a full re-install of the system was required.  So I now have php 5.1.4 same as before, IIS 5 Same as before but have upgraded to MS-SQL 2005.

     

    php and IIS seem to be running in harmony.  I just dumped my original php.ini in also.

    however I can connect to MSSQL via the management console, on Windows Authentication but it doesn't from my script.

     

    My script is correct as that is what I have been working on before and it was all working fine.  Any ideas as to what I have missed out?  I receive this error :

     

    PHP Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: localhost,1433 in D:\Inetpub\wwwroot\testing\classes\config.inc.php on line 119 PHP Warning: mssql_query() [function.mssql-query]: Unable to connect to server: (null) in D:\Inetpub\wwwroot\testing\classes\mri_central.php on line 20 PHP Warning: mssql_query() [function.mssql-query]: A link to the server could not be established in D:\Inetpub\wwwroot\testing\classes\mri_central.php on line 20 PHP Fatal error: SQL in D:\Inetpub\wwwroot\testing\classes\mri_central.php on line 21

     

    From this code : (although I know thats correct, it's not a php prob i know, but this is the best forum)

    <?php
    
    function db_conn () {
    global $APP_CONN;
    if ($APP_CONN = mssql_connect ("localhost,1433", "user", "pass", ""))  <-- Line 119
    {
    	return mssql_select_db("APP_DB");
    } else {
    	return false;
    }
    }
    
    db_conn();
    
    ?>
    

     

    Thanks in advance

  11. Ok The simple question would be, does anyone have a good technique for presenting templates, under a class framework, where one parent class (namely home) uses other daughter scripts to process the information before learning which template is to be presented and using return to pass back $template to the home class.

     

    Thanks for your time.

  12. It depends on how you are generating the page.  If your page comes from the .php file then it is slightly easier as you can just do...

    <?php
    $numbers1 = $_POST['numbers1'];
    $numbers2 = $_POST['numbers2'];
    ?>
    <form method="POST">
    <label for="n1">Numbers #1 :</label><input type="text" id="n1" name="numbers1" value="<?php echo $numbers1; ?>" /></br>
    <label for="n2">Numbers #2 :</label><input type="text" id="n2" name="numbers2" value="<?php echo $numbers2; ?>" /></br>
    </form>
    

     

    Or if you are using templates, you will need to flag up the globals scope, i.e.

    <?php
    globals $numbers1, $numbers2;
    
    $numbers1 = $_POST['numbers1'];
    $numbers2 = $_POST['numbers2'];
    
    include(form.php);
    ?>
    

     

    But without any more info, that's as far as I can help you, what is it exactly you are trying to do?

  13. Think what you need here is :

    <?php
    <tr>
        <td>Item Type</td>
        <td>Description</td>
        <td>Weight</td>
        <td>Price</td>
      </tr>
      <tr><td>
    <? 
    while($row = mysql_fetch_assoc($query)) {
    $item_name = $row['item_name'];
    $description = $row['description'];
    $weight = $row['weight'];
    $price = $row['price'];
    echo "<td>$item_name</td><td>$description</td><td>$weight</td><td>$price</td>";
    }
    ?>
      </td>
      </tr>
    ?>
    

    Then what is meant by

    Change empty data to " "

    is where you have a <td></td> fill it with <td> </td>

    Hope that helps. Good Luck

  14. Hey peeps,

     

    I've been working with my templates and scripts for a while now, and have decided that the way they are being used is very messy.  I have a home class, that checks the login then looks for page requests by the user and then displays whatever is returned.  This is what I had before (that worked) :

    <?php
    $content = $_REQUEST['content'];
    $company = $_REQUEST['company'];
    $modelId = $_REQUEST['modelId'];
    
    if (!empty($content)) {
        	$constant = $content . ".php";
    $template = SCRIPTS . "/$constant";
    } elseif (!empty($company)) {
        	require(COMPANY_SCR);
    } elseif (!empty($modelId)) {
        	require(PRODUCT_SCR);
    } elseif ($content == "") {
        	$template = ADMIN_SCR;
    }
    
    echo "<div id='container'>";
    require_once(HEADER);
    echo "<div id='content'>";		
    require($template);
    echo "</div>";
    include(TEMPLATE_DIR . "/inform.php");
    include(TEMPLATE_DIR . "/prodDisp.php");
    include(TEMPLATE_DIR . '/footer.php');
    echo "</div>";
    
    ?>
    

    Now my Scripts called by $content use include / require to display the relevant template however COMPANY_SCR / PRODUCT_SCR use return $template; at the end of their functions.

     

    Each Class Script is initiated by a call to a loading function for instance :

    <?php
    $thisApp = new custApp();
    
    $thisApp->custCheck();
    ?>
    

    All classes extend Home Class and an initial called function may look like this :

    <?php
    function custCheck() {
    // The if statement this gets the select values
    // Then it checks how this page was called and what data is available
    
    if (isset($_REQUEST['company'])) {
    	$this->custLoad($_REQUEST['company']);
    } else {
    	require(CUST_PAGE);
    }
    
    }
    ?>
    

    The custLoad function returns $template as an object which in turn goes back to the Home Class calling function and loads the required template, this makes sense and is how I want it to work.  However the scripts that are called via $content must use require / include to work and is starting to become a labyrinth of includes due to my lack of understanding, from what I have worked out it is probably down to the way variable functions behave, but I have not been able to work out an alternative.

     

    I tried using a switch case, but this created unexpected results.

    <?php
    switch ($content) {
        	case 'customer':
        		require(COMPANY_SCR);
        		break;
        	case 'client':
        		require(CLIENT_SCR);
        		break;
        	case 'product':
        		require(PRODUCT_SCR);
        		break;
        	case 'sale':
        		require(SALE_SCR);
        		break;    		
        	default:
        		require(ADMIN_SCR);
        		break;
    }
    ?>
    

    Any pointers / suggestions would be greatly received.

  15. Hi, I'm trying to display results of the items users request to process an order, however only part of the info is being displayed.

     

    I'm using 3d session arrays with the modelId as the handle.  Like so :

     

    $_SESSION['item_buy'] => modelId1, modelId2, etc.

    $_SESSION['item_buy'][modelId1] => price, qty, net, vat, gross.

    $_SESSION['item_buy'][...etc...] => price, qty, net, vat, gross.

     

    This is displayed via my template, section shown below :

    <table style='width:100%;'>
    <tr>
    	<th width='30%' style='text-align:center;'>Model Number</th>
    	<th width='10%' style='text-align:center;'>Price</th>
    	<th width='12%' style='text-align:center;'>Quantity</th>
    	<th width='14%' style='text-align:center;'>Net Value</th>
    	<th width='13%' style='text-align:center;'>Vat Value</th>
    	<th width='17%' style='text-align:center;'>Gross Value</th>
    	<th width='4%' style='text-align:center; border-right:0px;'> </th>
    </tr>
    <?php foreach ($_SESSION['item_buy'] as $modelId => $val) {
    	static $i;
    
    	$i++;
    	echo "<tr style='border-top:solid 1px navy;' ";
    
    	if ($this->isodd($i) == TRUE) { echo "bgcolor='white'><td>" . $modelId . "</td>"; }
    	else { echo "bgcolor='#99CCFF'><td>" . $modelId . "</td>"; }
    
    	foreach ($_SESSION['item_buy'][$ModelId] as $k => $v) {
    		echo "<td align='center'>$v</td>";
    	}
    
    	echo "<td height='9px'><a style='border:0px; background:none;' href='home.php?content=sale&item=$itemId&status=minus'><img alt='minus' border='0' src='../httpd/images/minus.gif' /></a></td></tr>";
    } ?>
    <tr>
    	<th colspan='3' align='right'>Totals</th>
    	<td style='border-right:solid 1.5px navy;'><?php print($total_array['t_net']); ?></td>
    	<td style='border-right:solid 1.5px navy;'><?php echo $total_array['t_vat']; ?></td>
    	<td><?php echo $total_array['t_gross']; ?></td>
    	<td> </td>
    </tr>
    </table>
    

    The arrays are produced via this code here :

    <?php
    global $modelId, $qty, $price;
    
    if (empty($_POST['qty'])) {
    die("You must have at least one item, twat!<br>");
    }
    
    $modelId = $_POST['modelId'];
    $qty = $_POST['qty'];
    $price = $_POST['price'];
    $stock = PHPApplication::selectRecord('stockAvail', 'products', 'modelId', $modelId);
    
    if ($qty > $stock) {
    "This will produce a back order, items will be shipped in two parts unless arranged otherwise.";
    }
    
    if ($_POST['pay'] == 0) {
    $prod_net = 12;
    $prod_vat = round(12 * VAT, 2);
    $prod_gross = round($prod_vat + $prod_net, 2);
    $_SESSION['item_buy']['Delivery'] = array(12.00, 1, $prod_net, $prod_vat, $prod_gross);
    } else {
    $prod_net = 9;
    $prod_vat = round(9 * VAT, 2);
    $prod_gross = round($prod_vat + $prod_net, 2);
    $_SESSION['item_buy']['Delivery'] = array(9.00, 1, $prod_net, $prod_vat, $prod_gross);
    }
    
    if (is_numeric($qty) && is_numeric($price)) {
    $prod_net = $qty * $price;
    $prod_vat = $prod_net * VAT;
    $prod_gross = $prod_net + $prod_vat;
    
    if (array_search($modelId, $_SESSION['item_buy'])) {
    	$o_qty = $_SESSION['item_buy'][$modelId][1];
    	$qty = $o_qty + $qty;
    	$_SESSION['item_buy'][$modelId][1] = $qty;
    } else {
    	$_SESSION['item_buy'][$modelId] = array($price, $qty, $prod_net, $prod_vat, $prod_gross);
    	//print_r($_SESSION['item_buy'][$modelId]);
    }
    
    foreach ($_SESSION['item_buy'] as $k => $v) {
    	static $total_net, $total_vat, $total_gross;
    
    	foreach ($_SESSION['item_buy'][$k] as $key => $val) {
    
    		if ($key == 3) {
    			$total_net .= $val;
    		}
    
    		if ($key == 4) {
    			$total_vat .= $val;
    		}
    
    		if ($key == 5) {
    			$total_gross .= $val;
    		}
    	}
    }
    
    $total_array = array('t_net' => $total_net, 't_vat' => $total_vat, 't-gross' => $total_gross);
    //print_r($total_array);
    } else {
    die("Can't have textual quatities / prices");
    }
    ?>
    

    When the print_r is uncommented, it displays the correct data, but for some reason the foreach used in the template does not believe there are any values available.  It does print out the Model Id and Delivery <th> but does not print out any of the values, nor does it print out the totals at the bottom of the display, can anyone see why?  Sorry for the long post, thanks for your time ;)

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.