-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
Why are you converting a perfectly readable date/time format into a non-readable hard to comprehend format? If you kept the date/time in the original format you can easily modify the date using the dateTime class A couple of examples $date = new DateTime(); $date->add(new DateInterval('P1D')); // add 1 day to todays date echo $date->format('Y-m-d') . "\n"; // Adds 1 hour to an existing date/time $date = new DateTime('2014-04-22 11:23:00'); $date->add(new DateInterval('PT1H')); // add 1 day to todays date echo $date->format('Y-m-d g:i:s') . "\n"; I don't understand that due to the hard to comprehend date formats you're posting.
-
By passing it as an argument when it is called $val = 'some value'; $answer = array('val1', 'val2'); numcheck($val, $answer);
-
Use DateTime to convert it. $time = new DateTime('18:00:00'); echo $time->format('g:iA');
-
Aslong as the HTML is enclosed in quotes that is fine. The problem with the OP's code is the double quote at the end of line 16
-
What? Your code makes no sense. What is it you're trying to do?
-
Yea, probably scared them away with my wall of text.
-
Sorry I dont know what the issue is. I only know that if you're using a VC11 64bit build of PHP you must install a VC11 64bit build of apache from apachelounge.com and make sure you have the C++ Redistributable installed that I linked to in my earlier post. The guys over at apachelounge.com maybe able to assist you further. If you still cant solve the error then maybe try a pre-packaged AMP stack such as WAMP or XAMPP instead.
-
Where did you download Apache from? If you got it from apache.org uninstall that version and download the x64 VC11 build of apache from apachelounge.com instead. Also make sure you have the Visual C++ Redistributable for Visual Studio 2012 installed too (download and install that from MS if you're not sure)
-
How to get this script in a lower version of PHP
Ch0cu3r replied to alpha_01's topic in PHP Coding Help
I think that is the version of PHPMyAdmin your host uses. This does not indicate the actual version PHP. To find out the version of PHP, use either phpinfo() or phpversion(); -
Your query has most likely encountered an error. Use mysql_error() to find out what the error is. Also you should stop using mysql_* functions these are deperecated and could soon be removed from future versions of PHP. I'd advise you to use either mysqli or PDO from now on.
-
@Gebbie I have formatted your post for you, but next time please wrap code in tags.
-
How to retain Select option after submitting the form in php
Ch0cu3r replied to raymak's topic in PHP Coding Help
@Ansego I do not understand why you find it is necessary to have a separate query for selecting the chosen options? I feel this makes things more complex. All you need to do is compare the $_POST in the while loop, if the current item matches add the selected attribute to the <option>. <?php while ($line = mysqli_fetch_array($resultservice)) { $selected = (isset($_POST['service']) && $_POST['service'] == $line['serviceid']) ? ' selected="selected"' : ''; ?> <option<?php echo $selected ?> value="<?php echo $line['serviceid']; ?>"> <?php echo $line['service'];?> </option> <?php } ?>- 12 replies
-
- php coding
- web application
-
(and 1 more)
Tagged with:
-
Also the values in the sql query needs to be wrapped in quotes $sql="INSERT INTO persons (FirstName, LastName, Age) VALUES ('$firstname', '$lastname', '$age')";
-
How to get this script in a lower version of PHP
Ch0cu3r replied to alpha_01's topic in PHP Coding Help
What! You said earlier you're using PHP5.5.9 now its PHP4.1.8 That version of PHP was released way back in 2002! You should not even be running that version of PHP. PHP4 has not seen any security/maintenance updates since 2008. You should be using atleast PHP5.3 -
You'd use imagecopy
-
Umm, not sure but looking at zwinky.class.php there appears to be a closing brace missing at the end of the file. After line 51 add a }
-
No not at all you have only defined them within the respective methods, for example $firstname is defined in the retrieve_person_first_name() method and $lastname is defined in the retrieve_person_last_name() method. Just because you defined them in a method does not mean they are available outside of that method. You need to read up on variable scope. You also do not appear to be executing these methods at all in person.php. You have only initiated the $class_person object $class_person = new Person(); After this you should be claling the firstname and lastname methods from the $class_person object, eg for the firstname $first_name = $class_person->retrieve_person_first_name(); Problem is upon calling this method you'll now get even more errors. public function retrieve_person_first_name() { db_connect(); //$user_id = $_GET['user_id']; //$first_name = $_GET['first_name']; $query = "SELECT first_name FROM presidents WHERE user_id = 18 LIMIT 0,1"; $result = $conn->query($query); $record = $result->fetch(PDO::FETCH_OBJ); $first_name = $record->first_name; return $first_name; exit(); } This is because when you call the $class_person->retrieve_person_first_name() method it will try to call a function called db_connect() on line 57. But there is no function called db_connect() defined by your code. However there is a method called db_connect() in the person class ( on line 38). You cannot call a method from within a class in this way. Instead you'll prefix the method name with $this-> eg: $this->db_connect(); But this should not even be happening. The database connection should not even be handled by the firstname/lastname methods. The database connection should either be initiated by the class constructor or by passing in the database instance to the constructor upon instantiation . The database instance should then be defined as a property to the class. Personally I take the latter approach. So the database connection code should now be outside of the person class, person.php should now read as <?php include('person.class.php'); $host = 'localhost'; $database = '21500TestDatabase'; $user = '21500student'; $pwd = '21500-student-general-access'; // try to connect to datatabase try { $conn = new PDO('mysql:host=' . $host . ';dbname=' . $database, $user, $pwd); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $conn->exec('SET NAMES "utf8"'); } //catch statement catch(PDOExeception $e) { die('Unable to connect to the database server' . $e->getMessage()); } // pass the database instance ($conn) to the Person class $class_person = new Person($conn); $first_name = $class_person->retrieve_person_first_name(); $last_name = $class_person->retrieve_person_last_name(); ?> <!doctype html> <html> <body> <p>The presidents name is <?=$first_name;?> <?=$last_name;?>.</p> </body> </html> Next the start of the person class definition should read as /* Person Class */ class Person { /* Attributes */ private $first_name; private $last_name; // database property private $conn; /* Constructor function */ public function __construct($conn) { //This code will run when the object is created. $this->conn = $conn; // defone database instance as a property } .... So now in the retrieve_person_first_name() method delete the call to $this->db_connect(); We no longer need this now. And change $conn->query to $this->conn->query So now hopefully when when we call the $class_person->retreive_person_first_name() it should return the firstname $first_name = $class_person->retrieve_person_first_name(); echo 'Firstname: ' .$first_name; You'll now apply the same changes for the lastname method. But our class still has issues. It only returns the firstname and lastname for the 18th person in the database. This is not good what we want to be able to do is make the firstname and lastname methods reusable so we can get other peoples names from the database too. We'll do this by passing the row id as an argument to the method. While we're at this stage I think it is a good idea to combine the firstname and lastname methods into one method as mysql can retrieve more then one piece of data from a query. There is no need to have separate methods. Deletinng the firstname and lastname class methods lets create a new method call get_by_userid public function find_by_userid($id) { // find the user by id retuning the first_name and last_name columns $query = 'SELECT first_name, last_name FROM presidents WHERE user_id = '.intval($id).' LIMIT 0,1'; $result = $this->conn->query($query); if($result) { if($row = $result->fetch(PDO::FETCH_OBJ)) { // define first_name and last_name as propeties $this->first_name = $row->first_name; $this->last_name = $row->last_name; return true; } } return false; } Now in person.php we can replace $first_name = $class_person->retrieve_person_first_name(); $last_name = $class_person->retrieve_person_last_name(); With $class_peron->find_by_userid(18); We can also replace <?=$first_name;?> <?=$last_name;?> with a method call to retrieve_full_name() which will return the a string formatted with the persons firstname and lastname <p>The presidents name is <?=$class_person->retrieve_full_name(); ?>.</p> So now hopefully the code should now be running as expected. Hope you learned something along the way.
-
A little story of my situation and a multi-array help.
Ch0cu3r replied to mustiej's topic in PHP Coding Help
In index.php delete lines 13 to 21. I do not understand what you're trying to do there. The correct code you need is for some reason commented out (lines 22 to 30). So this is what index.php should look like after edits <html> <head> <title>test</title> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <?php include 'EA.inc.php'; if(isset ($_GET['ean'])) { $eannummer = $_GET['ean']; eannummer($eannummer, $ean); } else { doorLopen($ean); } ?> </body> </html> The problem lies in the eannummer() function located in EA.inc.php. On line 47 you have this line if($val['EAN'] == $eannummer) $val['EAN'] should be $key. But there is a more efficient way to code that function which is like this function eannummer($eannummer, $ean) { $output = "<div class=wrapper>"; if(isset($ean[ $eannummer ])) { $output .= "<table width=500>"; foreach($ean[ $eannummer ] as $title => $merk) { $output .= "<tr><td>". "$title : </td><td class=left>" .$merk."</td></tr>"; } $output .= "</table>"; } else { $output .= 'Product #'.$eannummer. ' does not exist'; } $output .= "</div>"; echo $output; } -
The zwinky class has a method called authenticate_login() which you can use to check to see if the user is logged in. So in the pages you want the user to be logged in you'll have these two lines at the top of the page after the opening php tag require 'zwinky.class.php'; // require zwinky zwinky::authenticate_login(); // authenticates user, redirects user to login.php if they are not logged in.
-
That link does not work either. Just post the code here in tags or just attach the necessary files to this post.
-
The link you provided does not work. But basically you need to use sessions. When the user successfully logs in you set a logged in flag $_SESSION['loggedIn'] = true; // do this when user has logged in Now at the top of each page you only want only logged in users to see you'd do something like <?php session_start(); // check if user is logged in if(!isset($_SESSION['loggedIn']) || (isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] !== true)) { // user not logged in, redirect to the login page header('Location: /path/to/login_page/'); exit(); // kill the script } // user is logged in, display the restricted content To log the user out, you unset the $_SESSION['loggedIn'] variable.
-
You want to enable the intl extension and then use the NumberFormat class to format the currency
-
You just call sort, you dont assign sort to a variable $countries_array = array_unique($countries_array); sort($countries_array); print_r($countries_array);
-
You are getting that error because you do not have the openssl extension enabled. You need to open your php.ini and enable the openssl extension. You appear to be using WAMP. If I rememeber you can open the php.ini file from the wamp taskbar icon, by left clicking it and selecting PHP > php.ini now find the following line ;extension=php_openssl.dll and remove the semi-colon at the start of the line. Save the php.ini and restart Apache.