Jump to content

scottybwoy

Members
  • Posts

    532
  • Joined

  • Last visited

    Never

Posts posted by scottybwoy

  1. How do I get to see the result of this Array :
    [code]
    <?php
    echo "You searched for $company";

      $this->appCon();

      $sql = mssql_query("SELECT * FROM customers WHERE company = '" . $company . "'")
      or die("Customer query failed");

      $recordset_array = mssql_fetch_assoc($sql);
      print "This Array contains $recordset_array ";
    ?>
    [/code]
    All it prints is this :

    You searched for CYMAR ELECTRONICS LTDThis Array contains Array

    I just want to test that it is returning the right info
  2. At the same time can this function be done easier :
    [code]
    <?php
    function makeCustId($company)
    {
    $company = preg_match('|^[A-Z]+$i', $company);
      $company = substr($company, 0, 2);

      $this->appCon();

      $sql = mssql_query("SELECT custId FROM customers WHERE custId LIKE '" . $company . "'%");
      $rowcount = mssql_num_rows($sql);
      $rowInt = intval($rowcount);
      $rowInt ++;

      if ($rowInt <= 9)
      {
      implode(00, $rowInt);
      } else if ($rowInt <= 99) {
      implode(0, $rowInt);
      }

      $custId = implode($company, $rowInt);
      return $custId;
    }
    ?>
    [/code]
    I want it to get the first 3 letters from the company name then see if there are any others in the db and prepend them with incremental 3 digit value on a first come first serve basis.  Code is unchecked so may not work, but wanted to see if it can be done smoother first.  Thanks
  3. Thanks Orio for correcting my error, I was begining to see that.  So I think I need to make a new class for dealing with where the info needs to be put, ( a customer class) how would I include that with the way I'm displaying the content at the moment or is there a better way?
  4. Ello everyone,  I have a sigle field form in my header.htm that Is used for searching for customers,  I have it so it uses a google sugest type dropdown, I use $_GET for Submit button to send the data to my php file.  But am unsure how to process that data so that if it has a value it will query the database and post the details into the form.  Here's my code so far :
    [code]
    <?php

    function displayHome()
    {
        $content = $_REQUEST['content'];
        $company = $_REQUEST['company'];
        $product = $_REQUEST['product'];

        if (isset($company))
        {
        $company = preg_match('|^[a-z0-9]+$i |', $company);
      $company = strtoupper($company);

      $this->appCon();

      $result = mssql_query("SELECT * FROM customers WHERE company = '" . $company . "'")
      or die("Customer query failed");

      if (isset($details))
      {
      $content = "custAdmin";
      $_POST($details);
      } else {
      $content = "custAdmin";
      }

        } else if (isset($product)) {
        // Code yet to be done !!
        } else if ($content == "") {
    $content = "admin";
    }

    require_once(HEADER);

    echo<<<END
    <table width=100% valign="left"><tr>
    <td rowspan="2" width=60%>
    END;
    include(TEMPLATE_DIR . "/$content.inc");
    echo "</td><td width=40%>";
    include(TEMPLATE_DIR . "/inform.php");
    echo "</td></tr><tr><td>";
    include(TEMPLATE_DIR . "/prodDisp.php");
    echo "</td></tr><tr><td colspan='2'>";
      require_once(TEMPLATE_DIR . '/footer.php');
    echo "</td></tr></table>";

    }
    ?>
    [/code]
    And this is custAdmin.inc :
    [code]
    <table align="center" class="canvas" width=99%>
    <tr>
    <td align="center" width="600" cellspacing="3">
    <form name="custAdmin" action="{SELF_PATH}" method="GET">
    <!-- START_CUST -->
    <table width="570" class="form">
    <tr>
    <td width="160" class="labelL">Company Name</td>
    <td width="200"><input type="text" name="company" value="" size="40" style="font-family: MS Sans Serif; font-size: 10px; background-color:#FFFFFF"><!-- COMPANY --></td>
    <td width="160" class="labelR">Customer Id</td>
    <td width="50"><input type="text" name="custId" value="" size="15" style="font-family: MS Sans Serif; font-size: 10px; background-color:#FFFFFF"><!-- CUST_ID --></td>
    </tr>
    </table>
    <table width="570" class="form">
    <tr>
    <td width="120" class="labelL">Address 1</td>
    <td width="100"><input type="text" name="add1" value="" size="30" style="font-family: MS Sans Serif; font-size: 10px; background-color:#FFFFFF"><!-- ADD1 --></td>
    <td width="150" class="labelR">Telephone :</td>
    <td width="100"><input type="text" name="tel" value="" size="30" style="font-family: MS Sans Serif; font-size: 10px; background-color:#FFFFFF"><!-- TEL --></td>
    </tr>
    <tr>
    <td width="120" class="labelL">Address 2</td>
    <td width="100"><input type="text" name="add2" value="" size="30" style="font-family: MS Sans Serif; font-size: 10px; background-color:#FFFFFF"><!-- ADD2 --></td>
    <td width="150" class="labelR">Fax :</td>
    <td width="100"><input type="text" name="fax" value="" size="30" style="font-family: MS Sans Serif; font-size: 10px; background-color:#FFFFFF"><!-- FAX --></td>
    </tr>
    </table>
    <table width="570" class="form">
    <tr>
    <td width="120" class="labelL">Town / City</td>
    <td width="100"><input type="text" name="town" value="" size="30" style="font-family: MS Sans Serif; font-size: 10px; background-color:#FFFFFF"><!-- TOWN --></td>
    <td width="70" class="labelR">e-mail :</td>
    <td width="280"><input type="text" name="email" value="" size="48" style="font-family: MS Sans Serif; font-size: 10px; background-color:#FFFFFF"><!-- EMAIL --></td>
    </tr>
    </table>
    <table width="570" class="form">
    <tr>
    <td width="120" class="labelL">County</td>
    <td width="100"><select name=county>
    <option value="">Select a County</option>
    <option value={COUNTY}><!-- COUNTY --></option>
    </select></td>
    <td width="330">&nbsp;</td>
    </tr>
    <tr>
    <td width="120" class="labelL">Country</td>
    <td width="100"><input type="text" name="country" value="" size="30" style="font-family: MS Sans Serif; font-size: 10px; background-color:#FFFFFF"><!-- COUNTRY --></td>
    <td width="150" class="labelR">Customer Type</td>
    <td width="100"><select name=type>
    <option value="">What type of customer</option>
    <option value={CUST_TYPE}><!-- TYPE --></option>
    </select></td>
    </tr>
    <tr>
    <td width="120" class="labelL">Post Code :</td>
    <td width="100"><input type="text" name="postcode" value="" size="15" style="font-family: MS Sans Serif; font-size: 10px; background-color:#FFFFFF"><!-- POSTCODE --></td>
    <td width="150" class="labelR">Payment Method</td>
    <td width="100"><select name=pay>
    <option value="">Choose a Payment Method</option>
    <option value={CUST_PAY}><!-- PAY -->}</option>
    </select></td>
    </tr>
    </table>
    <table width="570">
    <tr>
    <a href="home.php?content=client" class="butText">Add Client</a>
    <input type="submit" value="Commit"  onmouseover="this.className='actionBtn actionBtnhov'" onmouseout="this.className='actionBtn'" class="btn">
    </tr>
    </table>
    </form>
    <!-- END_CUST -->
    </table>
    [/code]

    So if someone can send me on the right track for my php I'd b much apreciated and also if I've laid out my HTML right for recieving the info?  Thanks
  5. Ok sussed this one, where my javascript code had originally asked for the php file it now started its root from the php that created the page, for anyone else out there bamboozled by this little puzzle ;)

    However now I get the Data into my Input box, what do I need to put on my button to send that data to php. Like my <a href> buttons do in the original post and also bring up the customers form with the data already filled in?

  6. Hi programmers, web developers,

    Not really sure if this shud be here but you may be able to help.  I have a home.php script that build my main page like so :
    [code]
    <?php
        function displayHome()
        {
        $content = $_REQUEST['content'];

        if($content == "")
        {
    $content = "admin";
    }

    require_once(HEADER);

    echo<<<END
    <table width=100%>
    <tr width=100% class="canvas">
    <a class="butText" href="home.php?content=client">Client</a>
    <a class="butText" href="home.php?content=sale">Sale</a>
    <a class="butText" href="home.php?content=admin">Admin</a>
    <a class="butText" href="home.php?content=report">Report</a>
    <a class="butText" href="home.php?content=rma">RMA</a>
    </tr></table>
    <table width=100% valign="left"><tr>
    <td rowspan="2" width=60%>
    END;
    include(TEMPLATE_DIR . "/$content.inc");
    echo "</td><td width=40%>";
    include(TEMPLATE_DIR . "/inform.php");
    echo "</td></tr><tr><td>";
    include(TEMPLATE_DIR . "/prodDisp.php");
    echo "</td></tr><tr><td colspan='2'>";
      require_once(TEMPLATE_DIR . '/footer.php');
    echo "</td></tr></table>";

    }
    ?>
    [/code]
    And within my HEADER I have a little AJAX magic it includes two JavaScript files that I know it's finding as it sort of works.

    Basically it is a dynamic Drop down list that works like Google Suggest except for Companies in the database.  So it captures the key click and sends it to a .php file in the same directory which queries the database and sends back the result.

    I edited this file so that it didn't wait for a keyclick but used static data within the file and ran it from it's directory to see if it was working and it did.  So changed it back.

    If I run the .html file itself it works fine, but if I run it throught my php script it doesn't bring up any data.  All directories remain the same.

    Here's the html :
    [code]
    <td width=20%><input type="text" id="company" name="company" value="" onkeyup="ajax_showOptions(this,'getCountriesByLetters',event)"></td>
    [/code]
    Here's the .php :
    [code]
    <?php
    if(isset($_GET['getCountriesByLetters']) && isset($_GET['letters']))
    {
    $letters = $_GET['letters'];
    $letters = preg_replace("/[^a-z0-9 ]/si","",$letters);
    $res = mssql_query("select custId, company from customers where company like '" . $letters . "%'") or die("Stupid database");
    //echo "1###select custId, company from customers where company like '" . $letters . "%'|";
    while($inf = mssql_fetch_array($res))
    {
    echo $inf["custId"] . "###" . $inf["company"] . "|";
    }
    }
    ?>
    [/code]

    Any Ideas?
  7. Thanks Thorpe, Yeah that was my problem I had sorted it out php manual echo, while were on the subject though is there a way to get it to recognise styles if the sheet is called on the header prior to the echo html syntax?
  8. Hi I have an echo <<<EOF blah over some lines, and it isn't closing on EOF; and then I tried to use making a var $var = "content over some lines" but errors occur as no ; on the end of each one.  Does anyone know why this could be.  By the way I'm using IIS5 php 5.1.4, Thanks
  9. I have it solved now, It was how I was calling the function, I changed it to this :
    [code]
    <?php

            global $username;

            sessCon();

    $username = $this->getUserName();
    $sql = mssql_query("SELECT * FROM sessTbl WHERE value LIKE '%" . $username . "%'");

            if (!$row = mssql_fetch_row($sql))
            {
            $this->login();
            }
    ?>
    [/code]

    Now it works!!
  10. Realised that was never going to work as the old data would always be (until carbage collection) there so I changed it back to this :
    [code]
    <?php
    function login()
    {
    $this->authorise($this->getUserName());

    if ($this->authorise->success = TRUE)
    {
    global $username, $user_id;

    session_start();

    if (!isset($_SESSION["SESSION_USER_ID"]))
    {
    $_SESSION["SESSION_USER_ID"] = $user_id;
    $_SESSION["SESSION_USERNAME"] = $username;
    }

    } else {
    die ("Get Out!");
    }

    }
    ?>
    [/code]
    But now it still keeps making a new session ID, surely this is a standard procedure script, that many of you already have a good working way round, so please could you share a moment to help me please.  This is the second time i've posted on this issue and find it hard getting my head around it :(
  11. Hi,  I have a login function that goes off anf finds the relative details for logging in and then procedes to open up the session to insert the data.  Let me show you what I have :
    [code]
    <?php

    function login()
    {
    $this->authorise($this->getUserName());

    if ($this->authorise->success = TRUE)
    {
    global $username, $user_id, $data;

    $this->sessCon();

    session_start();

    $data = $_SESSION["SESSION_USER_ID"];
    $qry = mssql_query("SELECT * FROM sessTbl WHERE value LIKE '%" . $data . "%'")
    or die("Session ID Query Failed");

    $username = $this->getUserName();
    $user_id = $this->getUserId($username);

    if (!$row = mssql_fetch_row($qry))
    {
    $_SESSION["SESSION_USER_ID"] = $user_id;
    $_SESSION["SESSION_USERNAME"] = $username;
    }

    } else {
    die ("Get Out!");
    }

    }
    ?>
    [/code]

    I tried using an If (!isset($_SESSION["SESSION_USER_ID"]))  But that didn't work it just tried writing the new session data over the top of the existing data, but as am using database storage for it I just got an error of trying to put data in twice.

    But now all it does is wright the username and ID in, but on refresh it will just make a new session key and not put any data in at all, so it's a bit closer but not what I want.

    Can anybody help me out on what I can do to make it work, thanks
  12. OK Today this script decided not to give me an error, however it now inserts a new entry into the session table.  Say if further on into the Intranet, the user decides to Refresh, will this clear their data? As it would make them a new session Id.  I thaught I understood these sessions and now I'm begining to get confused.
  13. If you look at some ajax examples like this one http://www.tizag.com/ajaxTutorial/index.php you will see how you can use events to triger a call to your php page, also parse variables to your php and get the php to send strings to the javascript to work with.  Database action is a bit more tricky, but with a little google action I'm sure you can work it out ;)
  14. Probe, morning all ;/  This is my login script :

    [code]
    <?php

    function login()
    {
    $this->authorise($this->getUserName());

    if ($this->authorise->success = TRUE)
    {
    global $username, $user_id;

    session_start();

    $username = $this->getUserName();
    $user_id = $this->getUserId($username);

    if (!isset($_SESSION["SESSION_USER_ID"]) || ($_SESSION["SESSION_USER_ID"] == ""))
    {
    $_SESSION["SESSION_USER_ID"] = $user_id;
    $_SESSION["SESSION_USERNAME"] = $username;
    }

    } else {
    die ("Get Out!");
    }

    }
    ?>
    [/code]

    Which is called by the child class in home.php.  But the second if clause unables it to work.  Initially I did not have the If clause but then realised I need one encase the user refreshes.  So what would you suggest?
  15. my sessions are stored in a table like so :

    sesskey
    expiry
    value

    and i have a user table in a seperate db with these columns :

    userId
    uName
    uLName
    active
    level
    ...and some others

    How would you competant lot suggest I get my script to check the session data before trying to insert it again, if a user presses refresh?

    Surely someone has had to get around this before??
  16. Basically what I'd like is to know what to use to get my sess_read(key) function to check the database first, but I don't know what php function invokes it.  So far standard php session calls, invoke the custom session handler.  So can someone point me in the right direction?
  17. I have my sessions stored in a database and a custom handler that puts them in there, trouble is I thinks it's too slow for !isset($_SESSION['$myVar']) to find out if its there or not.  So when I refresh the page I always get the sql error as the primary key is the same so it won't enter the data.  But thats not what I want, I want it to look and see if the data is already there for that particular session key and if so not to bother trying to put it in there.  Any sugestions or tactics that you experienced types use?

    Here's my sess handler :

    [code]
    <?php

        function sess_open($save_path, $session_name)
        {
    return true;
        }

        function sess_close()
        {
            return true;
        }

        function sess_read($key)
        {
    global $DEBUG, $SESS_LIFE;

    sessCon();

    $statement = "SELECT * FROM sessTbl WHERE sesskey = '$key' AND expiry > '" . time() . "'";
            $result = mssql_query($statement);
    echo "<br />" . msql_error() . "<br />\n";

            if ($DEBUG)
            {
              echo "sess_read: $statement <br>result: $result<br>";
            }

            if ($result)
            {
    $row = mssql_fetch_assoc($result);
    return $row['value'];
    }

    return false;
    }

        function sess_write($key, $val)
        {
    global $DEBUG, $SESS_LIFE;

            $expiry = time() + $SESS_LIFE;
            $value = addslashes($val);

            sessCon();

            $statement = "INSERT INTO sessTbl VALUES ('$key', $expiry, '$value')";
            $result = mssql_query($statement) or die ('Query failed.');

            if ($DEBUG)
            {
            echo "sess_write: $statement <br>result: $result<br>";
            }

            if (! $result)
            {
    $statement = "UPDATE sessTbl SET expiry = $expiry, value = '$value' WHERE sesskey = '$key' AND expiry > " . time();
                mssql_query($statement) or die ('Query failed.');
    }

            return $result;
    }

        function sess_destroy($key)
        {
        global $DEBUG;
    sessCon();

            $statement = "DELETE FROM sessTbl WHERE sesskey = '$key'";
            $result = mssql_query($statement);
            if ($DEBUG)
            {
              echo "sess_destroy: $statement <br>result: $result<br>";
            }

        return $result;
    }

        function sess_gc($maxlifetime)
        {
        global $DEBUG;
       
            sessCon();

    $statement = "DELETE FROM sessTbl WHERE expiry < " . time();
            $qid = mssql_query($statement);
            if ($DEBUG)
            {
              echo "sess_gc: $statement <br>result: $result<br>";
            }

            return 1;
    }

        session_set_save_handler(
              "sess_open",
              "sess_close",
              "sess_read",
              "sess_write",
              "sess_destroy",
              "sess_gc");
    ?>
    [/code]

    Here's my session data insert :
    [code]
    <?php
    if (!isset($_SESSION["SESSION_USER_ID"]) || ($_SESSION["SESSION_USER_ID"] == ""))
    {
    $_SESSION["SESSION_USER_ID"] = $user_id;
    $_SESSION["SESSION_USERNAME"] = $username;
    }
    ?>
    [/code]
    BUt it doesn't work :(
  18. OK, here's where I have go upto, just not sure on how to include my php file think it's set up to read the string to put into the javascript array.  Here's the java :
    [code]
    <src=common.js + actb.js/> // Provided by the tutorial site
    // Browser Support code
    function ajaxFunction()
    {
    var ajaxRequest;  // The variable that makes Ajax possible!

    try {
    // Opera 8.0+, Firefox, Safari
    ajaxRequest = new XMLHttpRequest();
    } catch (e){
    // Internet Explorer Browsers
    try {
    ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try {
    ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e){
    // Something went wrong
    alert("Your browser broke!");
    return false;
    }
    }
    }

    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = custLookup(v,custArray){
    if(ajaxRequest.readyState == 4){
    var custArray = new Array(ajaxRequest.responseText);
    }
    }

    ajaxRequest.open("GET", "ajaxCust.php", true);
    ajaxRequest.send(null);

    }
    [/code]
    The php :
    [code]
    <?php

      function company_col()
      {
      $sql = "SELECT company FROM customers";
        $result = mssql_query($sql) or die("SQL Error selecting customers");
        $companies = array();
        while ($row = mssql_fetch_assoc($result)){
          $companies[] = '"'.addslashes($row['company']).'"';
      }

        $companylist = implode(",", $companies);
        return $companylist;
      }
    ?>
    [/code]
    And the html bit :
    [code]
    <form name="headmenu" method="POST">
    <input type='text' id='customer' backspace='false'>
    // <cript> phpfreaks doesn't like scripts
    var obj = actb(document.getElementById('customer'),custArray);
    </cript>
            </form>
    [/code]

    It's still not working so i think it's the way the file is included, or maybe I shouldn't use return for the php, i tried echo -> no joy.  Any suggestions?  It should work like google suggest!
  19. Hi Huggie, yeah I have already downloaded the source and added it like so :
    [code]
    //phpfreaks does not like this <script type="text/javascript/" language="javascript" src="actb.js">
    [/code]
    I was a little unclear on where to put the widget so I put it in both the script section and under the text field, like so :
    [code]
    <input type='text' id='customer' onChange="actb(document.getElementById('customer'),customarray);">
    [/code]
    However I thaught that it would be something to do with this bit of code here :
    [code]
    customarray = <?= company_col() ?>;
    [/code]
    But I'm not really sure what to do with it.  The tutorial uses this :
    [code]
    customarray = new Array('apple','pear','mango','pineapple',
            'orange','banana','durian', 'jackfruit','etc');
    [/code]
    And I think some of my other code posted befor doesn't need to be in there now it's a bit messy, Thanks for your time
  20. Right OK, well we have the php working so I won't bother posting that again.
    I have a text field and a submit, when a user starts entering details it will bring up a dropdown list to select the company name to bring up the details. like in the example here : [url=http://www.codeproject.com/jscript/jsactb.asp?df=100]http://www.codeproject.com/jscript/jsactb.asp?df=100[/url] but the array used in this is predefined so I wanted it to dynamically retrieve the data to be used form the database for the list.  So I think we are halfway there.  Here's my code so far (it's a bit messy and won't work yet, cos I was sorting out the php first) :
    [code]
    // Browser Support code
    function ajaxFunction()
    {
    var ajaxRequest;  // The variable that makes Ajax possible!

    try {
    // Opera 8.0+, Firefox, Safari
    ajaxRequest = new XMLHttpRequest();
    } catch (e){
    // Internet Explorer Browsers
    try {
    ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try {
    ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e){
    // Something went wrong
    alert("Your browser broke!");
    return false;
    }
    }
    }

    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function(){
    if(ajaxRequest.readyState == 4){
    var ajaxDisplay = document.getElementById('ajaxDiv');
    ajaxDisplay.innerHTML = ajaxRequest.responseText;
    customarray = <?= company_col($dataset) ?>;  //need to put something else here
    }
    }

    var customer = document.getElementById('customer').value;
    var queryString = "?customer=" + customer;
    ajaxRequest.open("GET", "ajaxCust.php" + queryString, true);
    ajaxRequest.send(null);

    }

    actb(document.getElementById('customer'),ajaxDisplay);
    [/code]

    Thanks Huggie, your very helpfull
×
×
  • 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.