Jump to content

scottybwoy

Members
  • Posts

    532
  • Joined

  • Last visited

    Never

Everything posted by scottybwoy

  1. Hi All, I'm trying to hold bits of info as they become accessible to the script, but when the script finishes it seems to overwrite, or lose it. How would I make it keep the data sent before without overwriting it. Here's what I have to start with : <?php function saleLoad() { global $data_array, $product, $prodId, $template; if (!isset($_SESSION['SALE'])) { $_SESSION['SALE'] = $data_array = array(); } if (isset($_POST['custId'])) { global $data_array; $custId = $_POST['custId']; $company = $this->selectRecord('company', 'customers', 'custId', $custId); $push_array = array('custId' => $custId, 'company' => $company); $this->array_push_associative($data_array, $push_array); } if (isset($_POST['clientId'])) { global $data_array; $clientId = $_POST['clientId']; $name = $this->selectRecord('name', 'client', 'clientId', $clientId); $push_array = array('clientId' => $clientId, 'name' => $name); $this->array_push_associative($data_array, $push_array); } print_r($_SESSION['SALE']); include_once(MK_SALE_PAGE); } ?> As you will probably work out, selectRecord, just selects the record and array_push_associative, adds the second array to the first. I'm trying to put an array into the session data, is that possible? And how do I do it without it overwriting itself each time. Thanks in advance
  2. Thanks for all your help, It worked just by using $_REQUEST or whatever you use to post the data, did not work using $_FILE but may do if you have a unique form for that relevant section. Thanks again peeps
  3. Thats a great start, thanks, I have now a search box, but if I do a print_r($_FILES); It is a blank array? What is meant to be in there?
  4. What you can do is specify only an admin user to be able to run files in protected directories then have your index.php file to be located in an open directory, then have that to redirect users to your first page and have your other files being called within that script. That doesn't even use php, but system security. But it depends on your OS and Server
  5. I'd like to click on a button, to bring up an explorer type search box like opening a file in pretty much most apps. Then the user can locate the file, once located I only want to use the address, not open/upload the file. Then I want to take the address and store it in the database. Hope that clears it up.
  6. Ceps option is the easiest and probably best, although it will need another page. But passing info like <a href="page.php?option=2">Client</a> can supply info to your php to bring up the relevant product info into your template. It can also be done via a button and having a func in your script to grab it, like if (isset($_POST['buy'])) then having a switch case for each 'buy' id. Hope that helps
  7. Whats the problem? it's not being inserted into the database? Give us some code, so we can see what $vars are available and your db layout so we can get more of a picture what is going on
  8. Hi All, What would I use to bring up a file search box? The best way to explain it is to pretend if you want to upload a file, but at the last step, don't. Just get the location of the file to store in a database. Does that make sense? I'm using a button to trigger this from my html, just don't know how to implement it. Thanks
  9. Can this even be done, i can't find much on the web?
  10. Hi All, I have a bit of a complicated issue thats racking my brain.  Was wondering if someone could make sense of it? I have a client page that can be accessed in a couple of ways.  Either from a customer page or from an admin page.  If it comes from the customer page it's ready to insert a new client if the customer does not have a client issued to it, it will not generate an ID and displays the wrong form layout (Select box for customer, when it already has that data). Next problem is, if it comes from the admin button it follows a few clauses:  Like if it has some data it can move on to different stages.  with no data it shows a select menu of customers, on selection of a customer it should bring up a select menu for the available clients for that customer, however it just passes on to the next stage of trying to insert a new client, however without generating an clientID.  I want it to do that process when there are no clients for that particular company, but thats not the case. Let me provide some code to put this in context : [code] <?php function recieveClient() { global $clientId, $custId, $sqlC, $sqlCl, $template; // Makes the select queries for template $sqlC = mssql_query("SELECT custId, company FROM customers") or die("Company Query Failed"); $sqlCl = mssql_query("SELECT clientId, name FROM client WHERE custId = '" . $custId . "'") or die("Client Query Failed"); // no clientId? But making one is possible, do it! if (empty($clientId) && !empty($custId)) { global $clientId, $company; echo "just goes for the first one"; $sql = "SELECT company FROM customers WHERE custId = '" . $custId . "'"; $company = mssql_result(mssql_query($sql), 0, 0); // Don't make one if user may wanna select one themselves. if ($_POST['select'] == 'Select Company') { if (!$row = mssql_fetch_row($sqlCl)) { $clientId = $this->addClient($custId); } } else { $clientId = $this->addClient($custId); } $template = CLIENT_PAGE; return $clientId; // User wants to add something } elseif (isset($_POST['commit']) && $_POST['commit'] == "Commit") { global $clientId; //echo "If commit"; $clientId = $_POST['clientId']; $sql = "SELECT * FROM client WHERE clientId = '" . $clientId . "'"; $qry = mssql_query($sql); if ($row = mssql_fetch_assoc($qry)) { //echo "<br>Update Client"; $data_array = $row; $this->updateClient($data_array); } else { //echo "<br>Insert Client"; $data_array = $_POST; $this->insertClient($data_array); } $template = CLIENT_PAGE; } elseif (!empty($clientId) && !empty($custId)) { global $clientId, $company; echo "final elseif clause"; $sql = "SELECT company FROM customers WHERE custId = '" . $custId . "'"; $company = mssql_result(mssql_query($sql), 0, 0); $template = CLIENT_PAGE; } else { //echo "else clause"; //$template = CLIENT_PAGE; require(CLIENT_PAGE); } return $template; } ?> [/code] Thats generated from my client script. The next part is from the template. [code] <?php if (isset($clientId) && isset($custId)) { ?> <form name="clientAdmin" action='home.php' method='POST'> <div class='l'> <label for='company' class='labelL'>Company :</label> <input type='text' id='company' value='<?php echo $company ?>' name='company' size='25%' class='required labelL' readonly /> </div> <div class='r'> <label for='clientId' class='labelL'>Client ID :</label> <input type='text' id='clientId' value='<?php echo $clientId ?>' name='clientId' size='25%' class='required labelL' readonly /> </div> <?php } elseif ($_REQUEST['select'] == 'Select Company') { ?> <form name="clientSelect" action='home.php' method='POST'> <div class='l'> <label for='company' class='labelL'>Company :</label> <input type='text' id='company' value='<?php echo $company ?>' name='company' width='25%' class='required labelL' readonly /> </div> <div class='r'> <label for='clientId' class='labelL'>Client ID :</label> <?php if (!$row = mssql_fetch_row($sqlCl)) { ?> <input type='text' id='clientId' value='<?php echo $clientId ?>' name='clientId' width='25%' class='required labelL' readonly /> <?php } else { ?> <select action='submit' id='clientId' name='clientId' tabindex='1' width='25%'> <?php while ($clRow = mssql_fetch_array($sqlCl)) { // Loop through each element print("<option value=\'" . $clRow[0] . "\'>" . $clRow[1] . "</option>"); } ?> </select> <input type='submit' name='select' id='select' value='Select Client' class='btn' onmouseover="this.className='btn btnhov'" onmouseout="this.className='btn'" /> <?php } ?> </div> <?php } else { ?> <form name="custSelect" action='home.php' method='POST'> <div> <label for='custId' class='labelL'>Company :</label> <select action='submit' id='custId' name='custId' tabindex='1' width='25%'> <?php while ($cRow = mssql_fetch_array($sqlC)) { // Loop through each element print("<option value=\'" . $cRow[0] . "\'>" . $cRow[1] . "</option>"); } ?> </select> <input type='submit' name='select' id='select' value='Select Company' class='btn' onmouseover="this.className='btn btnhov'" onmouseout="this.className='btn'" /> </div> <?php } ?> [/code] Then the rest of the form. So the data comming from the customer page consists of 2 variable $custId and $company this goes into the client script where it generates the $clientId and diplays the form correctly.  Same data comes if there are no clients to that customer, however it displays the form using the else clause above not the first if clause as expected. For the second part most of the data comes from itself.  i.e. starts on the else clause and should work itself up to the if clause.  But it seems to miss the elseif clause out and display the if clause with no data!  So I hope that someone can spot where I've gone wrong as it is doing my head in, I am now so confused, like I'm stuck in a while (this error occurs) { loop } lol. Thanks
  11. Sorry been preoccupied elsewhere with this one,  I tried the method above nut it still wont work.  Let me draw this out : I have a header file with two search forms (1 input + 1 button each)  It is connected to an external JS file and a php file for some AJAX magic, so whaen user presses a letter it will bring up what ever is in the database (like google suggest) If a user selects the data and presses enter i want it to open up and post the details in the relevant form (It's doing that already).  But if a user types something else that not in the database I want it to bring up a conf box before just adding new data like it does at the mo.  Can it be done?  Is that easy to understand?  Thanks again
  12. I found my problem is that it is actually storing the data but just not displaying it, so when it has no value it tries to store that too. However the the array of data sent to the form to be displayed is queried direct from the db in an assoc array.  then the field values request the valid field in the same way it does all the rest like so. [code] <?php <label for='tel'>Telephone :</label> <input type="text" id='tel' name='tel' value='<?php echo $data_array["tel"]; ?>' size=22% MAXLENGTH="50" ONCHANGE="validateTelnr(this, 'inf_telnr');" tabindex='8' class='required inputR' /> //Telephone works <div> <label for='compNote' class='compNote'>Notes :</label> <textarea type="text" rows='5' id='compNote' name='compNote' value='<?php echo $data_array["compNote"] ?>' tabindex='14'></textarea> </div> // compNote doesn't ?> [/code] Any suggestions is there a difference in the way text area works to other input fields?
  13. Hi again, I have an update query that works but does not insert into one specific field.  In my database the table that I am entering the data into has a text field called compNote, and my Update sql query looks fine the name matches just doesn't hold the data.  And returns no errors either.  Here's my code : [code] <?php function updateCust($data_array, $update) { static $colvals; $custId = $data_array["custId"]; $this->appCon(); $sql = "SELECT * FROM customers WHERE custId = '" . $custId . "'"; $row = mssql_fetch_assoc(mssql_query($sql)); array_shift($update); array_pop($update); $diff = array_diff_assoc($update, $row); if (!empty($diff)) { $colvals = ""; foreach ($diff as $k => $v) { $colvals.= $k . " = '" . $v . "', "; } $colvals = substr($colvals, 0, -2); $sql = "UPDATE customers SET " . $colvals . " WHERE custId = '" . $custId . "'"; echo $sql; $this->appCon(); mssql_query($sql); } else { echo "Nothing to change"; } unset($data_array); } ?> [/code] This is the echo of the sql statement : "UPDATE customers SET compNote = 'this data is not getting stored' WHERE custId = 'MRI000'" Some other examples : UPDATE customers SET country = 'will', compNote = 'wont' WHERE custId = 'TES000' This is interesting though : UPDATE customers SET country = 'does', compNote = '' WHERE custId = 'TES000' Can't see why it always has compNote there tho?  Anyone else?
  14. PS still not sure how to mark as solved am i really that blind
  15. LOL thanks how stupid of me.  Yeah, I knew about the comma, was gonna sort that after. Thanks
  16. Can you include the code of you radio button.  And will the values be static.  You can use name=1stValue value=2ndValue in the radiocode then when it's sent to the php break down the $_POST var by $secondVal = $_POST['1stValue'] then extract the key using something from the manual >> http://fr3.php.net/manual/en/ref.array.php
  17. Well you would need a breaking clause to stop the loop otherwise it can loop continuously and crash your system.  So something like [code] <?php while ($id != "" && $id < 25) // If you want it to loop 25 times {     $id++ } ?> [/code] But thats pretty useless on it's own, not sure what your trying to do.  Hope that helps
  18. Hi I have a function that is tring to make a string out of an array for a sql statement, but my static $var clears each time it's passed through my foreach statement, can anyone see why? [code] <?php function updateCust($data_array, $update) { static $colvals; $custId = $data_array["custId"]; $this->appCon(); $sql = "SELECT * FROM customers WHERE custId = '" . $custId . "'"; $row = mssql_fetch_assoc(mssql_query($sql)); array_pop($update); $diff = array_diff_assoc($update, $row); print_r($diff); $colvals = ""; foreach ($diff as $k => $v) { $colvals = $k . " = '" . $v . "', "; } $sql = "UPDATE customers SET " . $colvals . " WHERE custId = " . $custId; echo $sql; } ?> [/code] I print out the var data and it shows all the details I want, however the sql statement just shows the last key and value pair.  Thanks for taking a peek ;)
  19. Lol yes the <form> is further up.  But was would like to know how 0 is delt with in a $_POST array?  Cos it seems to only happen for those values.  Is their a workaround for this. 
  20. Hi All, I have a problem with my Select, field in my template.  It uses php to recieve the options, which works fine.  Selecting the options is ok except for the first one!  Even if I select another and then select the original.  Here's the code : [code] <?php <label for='type'>Customer Type :</label> <select action='submit' name='type' tabindex='12'> <?php while ($tRow = mssql_fetch_array($sqlT)) { // Loop through each element if ($tRow[0] == $data_array["type"]) { echo "<option value='" . $tRow[0] . "' selected='selected'>" . $tRow[1] . "</option>"; } else { print("<option value='" . $tRow[0] . "'>" . $tRow[1] . "</option>"); } } ?> </select> <div id="inf_type" class='sp'>&nbsp;</div> <label for='pay'>Payment Method :</label> <select action='submit' name='pay' tabindex='13'> <?php while ($pRow = mssql_fetch_array($sqlP)) { // Loop through each element if ($pRow[0] == $data_array["pay"]) { echo "<option value='" . $pRow[0] . "' selected='selected'>" . $pRow[1] . "</option>"; } else { print("<option value='" . $pRow[0] . "'>" . $pRow[1] . "</option>"); } } ?> </select> ?> [/code] Array offset [0] is figures, 0, 1, 2 etc.  Whilst offset [1] is the text.  When int '0' is sent via POST is it classed as NULL?  Thanks
  21. Sorry I don't follow you.  Do you mean having differnt pages displayed for the confirmation?  I'm trying to make it as user friendly as poss, so was hoping to use some AJaX trick but was unsure how.  Am I asking in the wrong place?  Although I would like to understand your method a bit better if you could explain it further and how it would work. Thanks.
  22. How would I go about making an alert box to the user and await their answer.  What I am trying to do is if the user enters a new customer in the search bar, it comes up with a message,  "Are you sure you want to add a new customer, (what they typed)" , "Yes/No".  I have it so that it brings up the alert echoing some javascript like so : [code] <?php if (what they typed exists){     do some stuff } else {   echo '<script language="javascript">confirm("Do you want to insert new customer ' . $company . '?")</script>';   if (empty($_REQUEST['custId']))   {   $custId = $this->makeCustId($company);   $data_array = array("company" => $company, "custId" => $custId);   }   if (isset($_POST['commit']) && $_POST['commit'] == "Commit")   {   $data_array = $_POST;   $this->insertCust($data_array);   } $template = CUST_PAGE;   } ?> [/code] But how would I get it to recognise the answer?  At the mo if I click Yes/No it will just enter the customer anyway.  Thanks in advance.
  23. Thanks Orio, got it sorted now, is validation usually that long?
×
×
  • 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.