boompa
Members-
Posts
305 -
Joined
-
Last visited
-
Days Won
1
Everything posted by boompa
-
Save yourself from this hassle in the future by using a source code control repository like git, hg, svn, etc. For best results either use a hosted repository (github, bitbucket, CloudForge, Assembla, etc) or back up your repo off-site.
-
Read this: Survive the Deep End: PHP Security
-
The problem is you have a " inside another ". You have a few options. One of these is to escape, via a backslash (\), the double quotes within the outer double quotes (and you're missing the last double quote too), like this: $sql = "INSERT INTO `qsolog` (`call`) VALUES ('{$record[\"call\"]}' )"; You could also break the string up like so: $sql = "INSERT INTO `qsolog` (`call`) VALUES ('" . $record["call"] . "' )"; Also, where you're already inside of quotes, I believe you can forgo the quotes around the array key of call, like so: $sql = "INSERT INTO `qsolog` (`call`) VALUES ('{$record[call]}' )";
-
How you can figure this stuff out on your own in the future: <?php $xml = simplexml_load_file('Jim.xml'); // Check out the contents print_r($xml); ?> SimpleXMLElement Object ( [@attributes] => Array ( [timeStamp] => 2014-02-04T23:59:52 [machineID] => TM-N158 [lineID] => M200 ) [TrackingData] => SimpleXMLElement Object ( [@attributes] => Array ( [stationName] => HousingHeight [partNumber] => 3051006070 [modelNumber] => [serialNumber] => 14BMJ03570 [LotNumber] => 879066 ) [KanbanNo] => 0 [Data] => SimpleXMLElement Object ( ) ) )
-
The proper element for this particular situation is not a radio button, but a checkbox.
-
Hashing != encryption.
-
PHP & Curl, Help Translating Curl API To PHP
boompa replied to inVINCEable's topic in PHP Coding Help
-u translates to using curl_setopt with the CURLOPT_USERPWD option. -
Crap! I've been asked to change my PHP ! Its been working for years!
boompa replied to JTapp's topic in PHP Coding Help
https://www.google.com/search?q=calling+a+rest+api+from+php -
If you dump the value of $xmlMetar with print_r($xmlMetar), you get this: SimpleXMLElement Object ( [@attributes] => Array ( [version] => 1.2 ) [request_index] => 5490740 [data_source] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => metars ) ) [request] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => retrieve ) ) [errors] => SimpleXMLElement Object ( ) [warnings] => SimpleXMLElement Object ( ) [time_taken_ms] => 2 [data] => SimpleXMLElement Object ( [@attributes] => Array ( [num_results] => 1 ) [METAR] => SimpleXMLElement Object ( [raw_text] => KARR 251852Z 31023G33KT 10SM CLR M09/M19 A2972 RMK AO2 PK WND 30033/1846 SLP074 T10941189 [station_id] => KARR [observation_time] => 2014-01-25T18:52:00Z [latitude] => 41.77 [longitude] => -88.48 [temp_c] => -9.4 [dewpoint_c] => -18.9 [wind_dir_degrees] => 310 [wind_speed_kt] => 23 [wind_gust_kt] => 33 [visibility_statute_mi] => 10.0 [altim_in_hg] => 29.719488 [sea_level_pressure_mb] => 1007.4 [quality_control_flags] => SimpleXMLElement Object ( [auto_station] => TRUE ) [sky_condition] => SimpleXMLElement Object ( [@attributes] => Array ( [sky_cover] => CLR ) ) [flight_category] => VFR [metar_type] => METAR [elevation_m] => 215.0 ) ) ) As you can see, the METAR element is within a data element, so you must access that before METAR: $metarKARR=$xmlMetar->data->METAR->raw_text;
-
You should change this $this->$Database = $Database; to $this->Database = $Database, although I would question why you're using a global instead of just passing in the $Database variable like this: function __construct($database) { $this->Database = $database; } And you create the object with $products = new Products($Database); Global variables as a rule are a bad thing.
-
Here's a screenshot from your page: See the icon there? That means your website is using a CMS called Joomla! Here's the Joomla! website to help you out.
-
Another option: $json = json_decode($f); $zone = new DateTimeZone($json->tide->tideInfo[0]->tzname); $unit = $json->tide->tideInfo[0]->units; echo ("<table>\n"); echo ("<tr><th>Date/Time</th><th>Height</th><th>Type</th></tr>\n"); // Iterate through each tide->tideSummary object in the array foreach($json->tide->tideSummary as $tide) { // Create the DateTime object $dt = DateTime::createFromFormat('U', $tide->utcdate->epoch); // Must specifically set TZ, else UTC is used $dt->setTimeZone($zone); // Echo out the table row echo("<tr>\n"); // Format the DateTime as desired // See http://us1.php.net/manual/en/datetime.format.php echo("<td>{$dt->format('Y-m-d H:i:s e')}</td>\n"); // Use printf to extract just the numeric part of the height, // then add the unit (which is the full spelling, rather than // the abbreviation provided within the height element). // This is a fault of the API; if it is going to provide the // unit as it is, it should now be adding that to it (or it // should be providing a raw numeric value) if (!empty($tide->data->height)) { printf("<td>%0.2f %s</td>\n", $tide->data->height, $unit); } else { // Just print an empty cell echo("<td> </td>\n"); } echo("<td>{$tide->data->type}</td>\n"); echo("</tr>\n"); } echo("</table>\n");
-
That warning is at the top of the file. Any changes you make to the file directly will not be saved. You probably need to use whatever tools IPB provides to make changes.
-
Lookup and Find a table and show data based on another table
boompa replied to ArthurHick's topic in PHP Coding Help
This sounds like a poor database design. Based on what little you've told us, you should have a single Alarms table with a foreign key which links the alarm to the controller. controllers ======== id <other fields> alarms ===== id controller_id <other fields> where controller_id is a foreign key referencing the id of the controllers table. Assuming MySQL this requires InnoDB table types. -
Cron Job! Seems to be something wrong with my php
boompa replied to oracle765's topic in PHP Coding Help
Use <?php rather than just <? Actually, add this at the top of the script: #!/usr/bin/env php Line should be mysql_select_db('mydatabase') or die('Could not select database.<br>' . mysql_error()); although I'm not sure why you're using an HTML tag there. -
How can I properly insert latest id into table with PHP?
boompa replied to therocker's topic in PHP Coding Help
Assuming the ID of the new record is an AUTO_INCREMENT field, you can use mysqli->insert_id. -
The latter. One product has many pictures. Read up on database normalization. products ---------- id int primary key autoincrement quantity int price decimal desc text product_pictures ------------------- id primary key autoincrement product_id int -- foreign key to products.id image_path varchar(2048) -- path to picture in the filesystem Get product info with pictures: SELECT p.id, p.quantity, p.price, p.desc, pp.image_path FROM products p JOIN product_pictures pp ON pp.product_id = p.id
-
A ReST API would not use SOAP. ReST is an alternative -- in fact, a vastly superior alternative -- to SOAP. These days in creating an API server you should avoid SOAP. And NuSOAP is not necessary if you're using any modern version of PHP (i.e., PHP 5+), as there are SOAP classes in PHP itself. NuSOAP dates back to PHP 4. A ReST call to get all players, as you are trying here, would look something like this: GET http://myserver/restapi/players Getting a single player would look like GET http://myserver/restapi/players/42 (where 42 would be the player ID) In general you would want to return JSON to the caller. Using a PHP framework like Laravel (or any other frameworks) makes this easy. Here is a relevant tutorial. Also, if you don't know what those GET lines above mean (i.e., what GET does), you don't know how the web works, you're not ready to be writing an API server. Start by learning how the web works by reading up on HTTP.
-
http://technaugh.com/technaugh/dotproject/call-to-undefined-function-mb_strpos-or-mb_stripos-or-mb_strlen-or-mb_strtoupper-or-mb_stristrll/
-
A Google search with your thread's title yields quite a few resources. Not everyone. A relatively small subset of PHP developers will need to authenticate via LDAP.
-
Which one is better for a Login system, Sessions of Cookies
boompa replied to Andor's topic in PHP Coding Help
Using the suggestions given in this thread, your class should look something like this: <?php class auth { private $db; public function __construct($db) { $this->db = $db; } private function user_info_check( $username, $password ) { $sql = " SELECT * FROM users WHERE username = '".$username."'"; if(!$result = $this->db->query($sql)){ die('There was an error running the query [' . $db->error . ']'); } if ( $result->num_rows < 1 ) die('Account doesn\'t exist'); $row = $result->fetch_assoc(); $pass1 = $row['password']; $user1 = $row['username']; $permission = $row['permission']; if ( $username != $user1 ) { die('Account dosen\'t exists'); } if ( $password != $pass1 ) { die('Wrong Password'); } return array($username,$permission); } public function login($username, $password) { // Returns the User's Username and Permission $info = $this->user_info_check($username,$password); setcookie($info[0]."-permission", $info[1], time()+3600); setcookie("user-".$info[0], $username, time()+3600); } } Other bad things in this include: 1. Saving passwords in cleartext in the database. You should be storing salted cryptographically-strong hashes; see password_compat for PHP 5.3 or 5.4, use the internal password hashing functions on 5.5+. 2. Putting permissions into a cookie which could be modified by the end-user, instead of using session variables which are stored on the server. 3. No obvious DB input validation/sanitization could lead to SQL injection attacks; your DB class may be doing some sanitization, but chances are it's still using the outdated, deprecated, and unsafe mysql_* functions under the covers. You should use PDO or [url=http://php.net/manual/en/book.mysqli.php]mysql[/il] with prepared statements to prevent SQL injection. -
$string_exp = "/^[0-9]{3}[0-9]{3}[0-9]{4}$/i"; if(!preg_match($string_exp,$phone)) { $error_message .= 'The Phone Number you entered does not appear to be valid. Please enter only 10 numbers without - or spaces. Example: 7787787780 <br />'; } if(strlen($city) < 2) { $error_message .= 'The City you entered do not appear to be valid.<br />'; } if(!preg_match($string_exp,$gender)) { $error_message .= 'Please specify your gender<br />'; } Do you really expect gender to contain a 10-digit number?
-
And its corollary, "I learn better by example so please provide revised code."