Jump to content

Frank_b

Members
  • Posts

    155
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by Frank_b

  1. Take a look to this example: <?php // be sure that dir/filename.ext will be a valid path and that you have write permissions $uploads_dir = 'uploads/'; // if we got something posted if($_SERVER['REQUEST_METHOD'] == 'POST') { // Let's see what the hack is into the $_FILES array for learning purposes echo '<pre>'; print_r($_FILES); echo '</pre>'; // walk through the error codes for each separate file foreach ($_FILES['file']['error'] as $key => $error) { if ($error == UPLOAD_ERR_OK) { // now move the uploaded file to uploads/<filename> $tmp_name = $_FILES['file']['tmp_name'][$key]; $name = $_FILES['file']['name'][$key]; move_uploaded_file($tmp_name, $uploads_dir.$name); } } } ?> <html> <head> <title></title> </head> <body> <form enctype="multipart/form-data" action="" method="POST"> <input type="file" name="file[]" id="file" ><br> <input type="file" name="file[]" id="file" ><br> <input type="file" name="file[]" id="file" ><br> <input type="file" name="file[]" id="file" ><br> <input type="submit" value="upload"> </form> </body> </html>
  2. Also you can make the sort routine more advanced. What if the skill points are equal? Maybe you would like to have the lowest id on top in that case. <?php function advancedSort($a, $b) { if($a['Skill_Points'] == $b['Skill_Points']) return $a['Skill_Id'] > $b['Skill_Id']; return $a['Skill_Points'] > $b['Skill_Points']; } echo '<pre>'; // sort the array first on points and if equel on id usort($yourarray, 'advancedSort'); print_r($yourarray); echo '</pre>'; ?>
  3. Your array is a two dimensional array. het main array or maybe you like to call it the outer array has 9 elements. All the 9 elements has a value 'array' check it out: foreach($yourarray as $arr) echo $arr; besides warnings you will see a value that is all the time the same. That is why a regular sort function wont work Luckly php have usort(). with usort you can give a callback function to compare two elements in the array on just the way you like. <?php function sortSkillId($a, $b) { return $a['Skill_Id'] > $b['Skill_Id']; } function sortSkillPoints($a, $b) { return $a['Skill_Points'] > $b['Skill_Points']; } echo '<pre>'; // sort the array on the Skill_Id elements usort($yourarray, 'sortSkillId'); print_r($yourarray); // sort the array on the Skill_Id elements usort($yourarray, 'Skill_Points'); print_r($yourarray); echo '</pre>'; ?>
  4. Here it is absolutely working so i tried it with your html. i have found out that when you use the <footer></footer> section marker that it won't work but as soon you replace that for <div id="footer"></div> then it will work just fine.
  5. php tries to open the file CaptchasDotNet.php but was not able to find it. Did you save the file in the same directory where this script is?
  6. The $_POST['checkbox'] value will only exist if the checkbox is checked. Thats why you have to reset the corresponding database field to NULL or 0 by default. And then you have to test if the $_POST['checkbox'] exist with the isset() function. If it does then you set the database field to 1.
  7. Hi glassfish, I should not focus on blogs. Its like you say that you search for a driver license for a BMW while you can drive any car with a license :-) From a dutch PHP board i can recommend this book: PHP Object-oriented Solutions
  8. Like this? <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> <style> #page { display:none; } #advert { border: solid 1px black; position: fixed; left: 50%; top: 50%; background-color: white; z-index: 100; height: 400px; margin-top: -200px; width: 600px; ; } </style> <script> window.onload = function() { setTimeout(function() { document.getElementById('advert').style.display = 'none'; document.getElementById('page').style.display = 'block'; }, 3000); } </script> </head> <body> <div id="page"> <h3>Hello</h3> <p>Welcome on my website</p> </div> <div id="advert">Hello this is an Advert!</div> </body> </html>
  9. http://ryanfait.com/sticky-footer/
  10. the content of your pages is somewhere else and could be even somewhere in the database.
  11. <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> <style> #advert { display:none; border: solid 1px black; position: fixed; left: 50%; top: 50%; background-color: white; z-index: 100; height: 400px; margin-top: -200px; width: 600px; ; } </style> <script> window.onload = function() { var ad = document.getElementById('advert'); setTimeout(function() { ad.style.display = 'block'; }, 3000); document.getElementById('close').onclick = function() { ad.style.display = 'none'; return false; } } </script> </head> <body> <h3>Wait ...</h3> <div id="advert">Hello this is an Advert!<a id="close" href="#">Close</a></div> </body> </html>
  12. Do you use a php editor ? You should see at once that you miss a php close tag. or is it because bad copy and paste work to this board? start all over like this: <?php $firstname = ''; $error = NULL; if($_SERVER['REQUEST_METHOD'] == 'POST') { $firstname = $_POST['firstname']; //validation if(strlen($firstname) < 2) $error = 'Please fill in your firstname!'; if(!$error) { // do some actions like sending an email // redirect header('Location thankyou.html'); } } ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>My first Form</title> </head> <body> <p><?php echo $error; ?></p> <form action="" method="post"> <input type="text" name="firstname" value="<?php echo $firstname; ?>" /> <button type="submit">Send</button> </form> </body> </html>
  13. <?php // Here we will prepare the page. We do NOT output anything. // That means that we do not use echo OR printf functions! // imagine this comes out of the database: $myname = 'Frank'; ?> <!------ HERE STARTS THE OUTPUT --------> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Learning Document</title> </head> <body> <h1>Hello <?php echo $myname; ?></h1> </body> </html>
  14. I don't have to look into your code, this question is asked so many times! mysql_query gives a resource on succes but FALSE if an error occurs. then on the next rule you get an error because you did not deliver an resource to the function mysql_fetch_array() Some other tips: - Use mysqli or PDO - Use mysql(i)_fetch_assoc and then you could get your data like this: echo $r1['columnname'] That will make your code much more readable! - Keep your php logic (where you run your queries etc) seperated from your output. Just start with <?php ......... ?> and then at the bottom of the page comes your HTML inwhere you use snippets of PHP code just to output your variables
  15. Believe me, you dont want to include a php file over the http. To include php files into your script you need to have the php files installed on the same server and then you need to use a systempath e.g. linux: /home/frank/domain.com/libraries/functions.php or with a windows server: c:\path\to\webroot\libraries\functions.php if you have troubles to find the right path you could use this in your scriptfile to get it: echo __DIR__;
  16. Just add a column with a name like 'deleted' and set a 1 if a user deletes the record instead of really deleting the record. Then change yr select queries, you will need to add a WHERE deleted != 1 And ready.
  17. Now you are able to test your code simply to open this path in your browser: http://yourdomain.com/stock/ajax/search Replace yourdomain for your own domain name and search for an applicable searchtext. You should than see a JSON string in your browser eg ["stock1","stock2","stock3"]
  18. In Codeigniter you should run your queries in the Model and not in the Controller. More or less you should make one one Model per database table. <?php // The Model class StockModel extends CI_Model { function __construct() { // Call the Model constructor parent::__construct(); } function getAll() { $query = $this->db->get('stocks'); /* foreach ($query->result() as $row) { echo $row->stock_desc; } */ return $query->result(); } function findStockDescriptions($searchtext) { $query = $this->db->query("SELECT stock_desc FROM stocks where stock_desc LIKE '".strtoupper($searchtext)."%'"); /* foreach ($query->result() as $row) { echo $row->stock_desc; } */ return $query->result(); } // Add more query function that belongs to the stocks table } // The Controller class Stock extends CI_Controller { public function ajax($searchtext) { $this->load->model('StockModel'); $stocks = $this->StockModel->findStockDescriptions($searchtext); $data = array(); foreach($stocks as $stock) { $data[] = $stock['stock_desc']; } echo json_encode($data); exit; // In this case we don't need to load a view, instead we echo the JSON directly out of the controller. } } ?>
  19. instead of an empty value you may also set a default value: function round($number, $decimals = 2 ){ ... }
  20. i fully agree with QuickOldCar. In addition if you do not receive any emails try the following in a test srcipt <?php mail('your-own-mailaddress@domain.com','Test mail','Hello did you receive this email?'); ?> You should receive an email on the address that you replaced for your-own-mailaddress@domain.com. If that is true try to solve the errors that appear on the screen after you added error_reporting() like QuickOldCar told you. You could copy and paste the error messages to this board if you want help from us. If you still do not get any email (also not in your spam folder!) then is the mail() function switched off or not good configurated on your webserver. In that case there would be two solutions: 1. Your provider configurates your webserver until the mail function works again. And 2. Instead of using the mail() function you could download and install PHPMailer on the website and you change your code so that it will use PHPMailer over the SMTP protocol. (You will need help to do the last option).
  21. http://php.net/manual/en/function.headers-list.php
  22. after that you will get an error that will help you to solve your problem. Mysql_* functions are deprecated. I advise you to use mysqli_* functions with prepared statements OR the PDP class.
  23. after rule 23 with the mysql_query function you should check if $result is not FALSE. If $result has the value FALSE then you should use mysql_error() to get the error message: $result=mysql_query($sql); if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $sql; die($message); }
  24. While reading your last message i wrote the following possible classnames: Product ProductCategory Customer Pricelist To be clear: the classes can hold only one of the object it stands for: class Product can hold only one product class Customer can hold only one customer etc. To hold more entities eg customers you should use array's class Customer { private $companyName; private $email; // and more properties like password, clientlevel, address, telephone etc public function setCompanyName($companyName) { $this->companyName = $companyName; } public function getCompanyName() { return $this->companyName; } public function setEmail($email) { $this->email = strtolower($email); } public function getEmail() { return $this->email; } } $customers is array() $customer = new Customer(); $customer->setCompanyName('Google'); $customer->setEmail('info@google.com'); $customers[] = $customer; $customer = new Customer(); $customer->setCompanyName('Microsoft'); $customer->setEmail('info@microsoft.com'); $customers[] = $customer; foreach($customers as $customer) echo $customer->getName() . '<br>';
×
×
  • 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.