Jump to content

Omzy

Members
  • Posts

    314
  • Joined

  • Last visited

    Never

Everything posted by Omzy

  1. Let's say I am currently viewing a dynamic page: http://www.mydomain.com/directory/index.php?type=flowers I want this URL to be output on the page, but not including the end parameters.
  2. So you mean to say I can eliminate the use of hidden variables by using sessions?
  3. Well it's just a basic multi part form. I've managed to create it so that data is being passed via $_POST as the form progresses. At the last stage the form data is sent via email to me. The form data doesn't need to be used anywhere else on the site, so I dnt think I need to use sessions?
  4. Anyone? Alternatively is it possible to write (add/update/delete) items from an array stored in a file?
  5. Basically the front page of my site displays details of the 5 most recent customers added to the site. It gets this information from the database - very basic stuff. As the site is getting busier its slowing down due to the number of requests to the database. Is it possible I could have a file on the server that I can run manually everytime some new data is added to the database, and will put this data into an array so it can be displayed on the front page? This way there would not be a call to the database upon site load.
  6. I'm just in the process of building a multi part/page form. I have been advised to use SESSIONS, however I'm struggling to think of the benefits of using sessions to pass data when everything is being passed via $_POST anyway. Can someone shed some light on this?
  7. I've got code as follows: $query="SELECT * FROM customer WHERE id='$_GET['id']'"; $results = mysql_query($query); while($row=mysql_fetch_array($results, MYSQL_ASSOC)) { //assign all the $row variables; } Now because the ID field is unique, it will always bring back one record only, which is just what I need it to do. This code works fine, but I want to know is this the most efficient way of doing it? Should I put in a "LIMIT" parameter on the SQL query, do I really need to use a WHILE loop?
  8. How can I output the exact response that mysql produces?
  9. Lets say I run a mysql query in my php script, I want a message to be output with the mysql response, for example "1 row added", or "2 rows affected". Currently I've got it to output an error message if it fails, as follows: mysql_query($query) or die("<b>Error " .mysql_errno($connect). " - " .mysql_error($connect). "</b>");
  10. Crikey, no need to get all arsey about it! Anyway I'll wait for someone more pleasant to respond.
  11. Surely there must be a way of knowing what "position" each sub-array is, for example 'basic' would be position 0 but I can always "plus 1" the position to get what I want...
  12. Come on, where are all you php freaks today lol.
  13. Well if I remove those brackets it won't work lol. So the brackets ARE needed lol. Yeah it's all fine and dandy now :-)
  14. I have an array as such: $types=array( 'basic'=>array('Basic Package', '3', '140'), 'standard'=>array('Standard Package', '3', '140'), 'premium'=>array('Premium Package', '5', '200'), ); In my database the 'type' field has been stored as a number, so 1=basic, 2=standard and 3=premium How can I refer to the correct item in the array and output the first item in that array? Ideally I don't want to change the entries in the database... The 'type' field can be referred to as $type
  15. Cheers mate, that has worked. How come it needs to be put in brackets?
  16. I tried this: value="', !isset($_POST[$key]) && $key=='url' ? 'http://' : isset($_POST[$key]) ? $_POST[$key] : null ,'" But it gives me an error notice on page saying: Undefined index: url in ... How is it undefinded?
  17. Basically I have a text input form which is built up from an array called $fields: $fields=array( 'name'=>array('Contact Name', '1', '25'), 'company'=>array('Company Name', '1', '25'), 'phone1'=>array('Tel Number 1', '1', '25'), 'email'=>array('Email Address', '1', '35'), 'url'=>array('Website URL', '0', '35'), ); foreach($fields as $key => $value) { echo ' <b>'.$value[0].'</b> <input type="text" name="'.$key.'" value="', isset($_POST[$key]) ? $_POST[$key] : null ,'" size="'.$value[2].'"/> '; } As you can see the VALUE attribute is null upon page load or otherwise populated with its POST value if the form gets posted and has to be re-displayed. This all works fine, however I need to extend the ternary statement to do an 'ELSE>IF' type operation. Basically the default value for the field 'url' needs to be 'http://' upon page load. I have tried several different ways of doing this but it just won't work for me! Any ideas anyone?
  18. Omzy

    in_array()

    Cool. I was just after the most efficient method, i.e. I only want to search on the array values and not the keys.
  19. Omzy

    in_array()

    No, because it's checkboxes, all checkboxes have to have the same NAME, therefore I've declared it as an array - <input type="checkbox" name="selection[]" value="..........
  20. I have a checkbox array called 'selection' ($_POST['selection']) If I want to check for a value against the values held in the array, is it best to use: 1) if (in_array($value, $_POST['selection'])) or: 2) if (in_array($value, array_values($_POST['selection']))) Form my testing both of these methods work. Also I found that method 1 does not match against the array INDEX/KEY - is this the correct behaviour?
  21. Well I've seen the output from some contact forms which give you the country name and ISP of the sender, how can I do something similar on my contact forms?
  22. Yeah I understand that, but what I'm saying is why does PHP need to convert it back to '&' - why can't it just leave it as it is!
  23. But that's what I don't understand - in the source the value is "&" - that is the posted value, i.e whatever is in the source should be passed forward, not what gets displayed on screen!
  24. I POST the following as a hidden variable in my first form: echo '<input type="hidden" name="username" value="'.htmlentities($_POST['username']).'"/>'; This takes you to the second form, which has the following: echo '<input type="hidden" name="username" value="'.$_POST['username'].'"/>'; I assume it would carry forward the exact value that has been POSTed. I tested this using a string with an 'ampersand' (&) and in the first form it works as expected, by converting '&' into '&'. However in my second form it seems to convert it back to '&'. Is this the default behaviour/do I have to re-convert it using htmlentities() in my second form, or have I missed something out?
×
×
  • 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.