Jump to content

JonnoTheDev

Staff Alumni
  • Posts

    3,584
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by JonnoTheDev

  1. If you want to remove duplicates in an array simply use array_unique() <?php $x = array('red','green','blue','red'); $x = array_unique($x); print_r($x); ?> Alternatively when you are building and array do not allow duplicates to be inserted into it. You can us the functions in_array() or array_key_exists() to check for values already in the array. <?php $x = array('red','green','blue','red','green','blue','red','green'); $y = array(); foreach($x as $colour) { if(!in_array($colour, $y)) { $y[] = $colour; } } print_r($y); ?>
  2. For large files use the function passthru() <?php $path = '/full/path/to/file/'; $filename = 'xyz.mp3'; header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=".$filename.";"); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($path.$filename)); passthru("cat \"$path.$filename\""); exit(); ?>
  3. Ok that's fine. I thought that you were talking thousands of records.
  4. I would also suggest moving away from using MySQL to search, using LIKE, MATCH, etc, bad, bad, bad if you have a large database. I would recommend a proper search index such as Lucene or Sphinx. If you have a website with that sort of traffic, do you make any revenue? If so I would invest in a dedicated server and tell your host where to go. If your code is inefficient at least you can fix it without someone pulling your service.
  5. You have bad parenthesis around you conditionals within your switch case. here it is cleaned up: <?php switch($_GET['action']){ case 'write_ok': $sql = "INSERT INTO project_data (Date_Of_Birth, Gender, Title, First_Name, Last_Name, Address_Line_1, Address_Line_2, City, Postcode, Contact_No, Email, Additional_Comment) VALUES ('".$_POST[dateofbirth]."','".$_POST[gender]."','".$_POST[title]."','".$_POST[firstname]."','".$_POST[lastname]."','".$_POST[address1]."','".$_POST[address2]."','".$_POST[city]."','".$_POST[postcode]."','".$_POST[contactno]."','".$_POST[email]."','".$_POST[note]."')"; if(!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } else{ echo '<script>alert("Data Has Been Successfully Updated");</script>'; echo '<meta http-equiv="Refresh" content="0;URL=switch.php">'; } break; case 'edit_ok': if((!isset($_GET['id']) || trim($_GET['id']) == '')) { die('Missing record ID!'); } $id = $_GET['id']; mysql_query("UPDATE project_data SET Date_Of_Birth='".$_POST[dateofbirth]."',Gender='".$_POST[gender]."',Title='".$_POST[title]."',First_Name='".$_POST[firstname]."',Last_Name='".$_POST[surname]."',Address_Line_1='".$_POST[address1]."',Address_Line_2='".$_POST[address2]."',City='".$_POST[city]."',Postcode='".$_POST[postcode]."',Contact_No='".$_POST[contactno]."',Email='".$_POST[email]."',Additional_Comment='".$_POST[note]."' WHERE ID='".$_GET['id']. "'") or die ("Error in query: $query. " . mysql_error()); echo '<script>alert("Data Has Been Successfully Updated");</script>'; echo '<meta http-equiv="Refresh" content="0;URL=switch.php">'; break; case 'delete_ok': #########Delete OK Start################# $id= $_GET['id']; $result = mysql_query("DELETE FROM project_data WHERE ID = '$id'") or die ("Error in query: $query. " . mysql_error()); echo '<script>alert("Data Has Been Successfully Updated");</script>'; echo '<meta http-equiv="Refresh" content="0;URL=switch.php">'; #########Delete OK End ################# break; } ?> Use proper indentation in your code. It makes it much clearer to see where you have made an error.
  6. This is real basic stuff in terms of networking. The switch boxes you talk about are nonsensical. You have 8 computers, yes. They all must be on the network, forget about access to what in terms of a physical network. Evertyhing on a network has to be hard wired in (or wireless these days). So you need a 12 port (minimum) hub /switch in the center. Connect all PCs to it via CAT5 cable. Now plug your Router into the hub / switch via CAT5 also and connect the RJ11 or Coax socket (dependent on the type of broadband you have) into the phone line. Now, the way I would setup such a small network would be to use fixed IP addresses. Do not have your Router giving out addresses over DHCP. You want a private range so for example you could give your PCs addresses from 192.168.10.2 - 192.168.10.9 Give the router a fixed IP of 192.168.10.1 In the TCP/IP settings for ach PC add the IP addresses and if you want them to access the Internet give them the gateway address of the router. Done, you now have a network. Now if I want to be more secure on giving people Internet access and protecting my network (as anyone, who has a bit of IT nouse could add the gateway address of the router to give themselves access) I would insert a firewall between the router and the network. With this I can setup rules for incoming / outgoing traffic, block ports, etc and also restrict the IP addresses that can access the router (the web). So I could not allow PCs with the IP address of 192.168.10.2 / 3 to access the web via the firewall. What you would do to setup the firewall is give the routers original IP address of 192.168.10.1 and the router would be connected via CAT5 to the firewall's WAN port. The router would be then given an address on a completely different subnet from your network i.e 10.0.0.1 or a public address of lets say 212.36.52.145. The firewall forwards traffic between the public network and router. A PC on the network can never talk directly to the router without passing through the firewall. Some routers have IP blocking, firewalls etc built into them if you do not want to have a separate box, but for any network I would always have a firewall protecting the private LAN. I have attached a file to show you how simple this looks. [attachment deleted by admin]
  7. If a client wants paypal integration then there are more than just buy now buttons that you can offer. In fact this is probably the worst kind of integration that you can offer for most dynamic websites as you usually will want to update your own database when a payment is made or rejected or whatever. For a simple buy now button all you need is to ask the client to generate the HTML themsleves and email it to you if they do not want to give you access to their account. You can talk them through it. It takes all of 2 minutes. For a proper solution, you do not need any customer details. Use the Paypal sandbox to test your implementation of Direct Pay, Express Checkout, or IPN integrations. As a developer you should have a Paypal sandbox account setup. If not, get one setup. Once you have the integration sorted you just need your client to give you the API username / password / key (not the same as the login details to Paypal) details for their account and add it to your code instead of the test details. For a proper integration customers should have a Paypal business account. If it is a small little home project HTML website selling cookies & cupcakes then a business account is not needed and a simple buy now button would suffice. You should not be setting up Paypal accounts for clients. It is their responsibility to read the documentation and familiarise themselves with Paypal if they are going to be using it for transactions from their business. You wouldn't have your friend open a bank account for you, would you? You can offer help on how to go about setting up the type of account they need, but never do it for them.
  8. Yes, via AJAX. However, to make sure that your site still functions when Javascript is not enabled you should alway use a form for user input.
  9. First do this: http://kb.mediatemple.net/questions/625/How+do+I+enable+root+access+to+my+%28dv%29%3F#dv Now, in windows, open up putty. For the hostname put the server's IP address in, and select port 22. Click Open. You should now get the login prompt. For the username simply type: root Press enter. Enter the password that you setup for root by using the instructions in the link above. Press enter. Done.
  10. I think that is written in Java
  11. This is far too vague. Every application written in PHP that requires MySQL will read / write data to the database from forms and queries. What kind of application do you need? Is it a CRM? Chances are, what you are looking for is a niche and you will have to write it yourself. Have you tried looking on script websites such as http://www.hotscripts.com
  12. Should be for($divIdx=1; $divIdx<=$divsToDisplay; $divIdx++) not for($divIdx=1; $divIdx<=$divsToDisplay; $divIdx++
  13. In an example a single user object would be stored in a session when a user logs into a website. The object will persist throughout the website. The fact it is a singleton means that multiple instances of the same class cannot be created.
  14. You can also use the singleton pattern to make sure you don't create multiple instances of the same class all over the place. For instance if I was to create a user object when someone logs into a website you don't want to be creating multiple instances of the same class for a single user. <?php class Foobar { public $name; private static $instance = NULL; public static function get_instance() { if(self::$instance === NULL) { self::$instance = new self(); } return self::$instance; } public function __construct() { } } ?> So instead of <?php /* 2 different objects $x is overwritten */ $x = new Foobar(); $x->name = "Joe"; print "My name is: ".$x->name."<br />"; $x = new Foobar(); print "My name is: ".$x->name."<br />"; ?> We can do <?php /* $x is the same object */ $x = Foobar::get_instance(); $x->name = "Fred"; print "My name is: ".$x->name."<br />"; $x = Foobar::get_instance(); print "My name is: ".$x->name."<br />"; ?>
  15. Come on mjdamato that's god awful code. If they were to add more elements to the select list are you going to keep adding conditionals to the script? A simple loop will suffice and requires no modifications on change of the number of list elements.
  16. The error reporting level differs between servers. When this code was on your other server, the error still existed however it did not show because of the error reporting level set in the server's php.ini file. You should always fix errors, however if you do not want NOTICE errors to be displayed you can add this to the very to of your script. <?php error_reporting(E_ALL & ~E_NOTICE); ?> If you have access to the server's php.ini file you can ammend the error reporting level globally there.
  17. Of course. Just use a simple loop i.e <?php /* num from previous page */ $limit = 4; /* loop out the divs */ for($x = 1; $x <= $limit; $x++) { echo "<div id=\"".$x."\">".$x."</div>"; } ?>
  18. Wow, loads of the same reply in one go. Well done guys
  19. Because $results = mysql_fetch_array($sql); always equates to true in your loop while($row = $results) Here's how it should be written. <?php $result = mysql_query("SELECT * FROM cities"); while($row = mysql_fetch_assoc($result)) { echo $row['City']."<br />"; } ?>
  20. Not free but I use IonCube http://www.ioncube.com/
  21. I gave you the code in the first reply I put on this topic that will do exactly what you are asking for. Why did you not implement this in your code for any fields that should be NULL when no data is entered into the corresponding field? It goes into your SQL query. Here it is again <?php mysql_query("INSERT INTO database_table SET field_name=".(strlen(trim($_POST['field_name'])) ? "'".mysql_real_escape_string($_POST['field_name'])."'" : "NULL").", another_field_name=".(strlen(trim($_POST['another_field_name'])) ? "'".mysql_real_escape_string($_POST['another_field_name'])."'" : "NULL").""); ?> If you want more data validation checks then do them before the insert query i.e <?php /* check the following fields contain letters only */ $fields = array('firstname','lastname'); foreach($fields as $field) { if(strlen(trim($_POST[$field]))) { if(!ctype_alpha($_POST[$field])) { /* destroy POST data if not valid */ $_POST[$field] = NULL; } } } mysql_query("INSERT INTO database_table SET firstname=".(strlen(trim($_POST['firstname'])) ? "'".mysql_real_escape_string($_POST['firstname'])."'" : "NULL").", lastname=".(strlen(trim($_POST['lastname'])) ? "'".mysql_real_escape_string($_POST['lastname'])."'" : "NULL").""); ?>
  22. Wow, that's worse than the original joke! A fox & a spider, mmm...
  23. Unless this is your own dedicated server a hosting company will not let you login to a server as the root user. Get the correct username. Also you just use the username to login without any @ipaddress whatever that is i.e user: root password: abcdef
  24. You could also do something like below <?php mysql_query("INSERT INTO database_table SET field_name=".(strlen(trim($_POST['field_name'])) ? "'".mysql_real_escape_string($_POST['field_name'])."'" : "NULL").""); ?> If the field_name field has a value it will get stored else it will use NULL
×
×
  • 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.