spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » PHP » Page 4
Compare two numbers in PHP
This is normal when using floats. Try use this code: if (abs($amount-$balance) > 0.001) { throw new Exception('Error updating balance! ' . $balance . " instead of " . $amount); } If you're caught out by this, remember to properly round as well. This is NOT easy. When to round, and how to round, is done differently by a lot of people. Note that the PHP round() function now allows you to ch

Categories : PHP

Cannot get Laravel relationships working, newbie
With $blog = new Blog; you are starting to create a new blog entry. What you really need to do is query the blog table and get the users, which can be done quite easily with eager loading. Try this... $blogs = Blog::with('users'); Then when you are creating your view, you want to send the blogs in your view using something like this... The first parameter of the with() method is the name you

Categories : PHP

Php put this in global var
Reserved word global is for accessing a global variable from a function scope. To define a new variable in a global scope use: $GLOBALS[$search][$exp_t] If $search contains foo, you'll have the variable $foo defined in a global scope. Example: function set_foo() { $search = 'foo'; $GLOBALS[$search] = 'bar'; } set_foo(); var_dump($foo); ...will output string(3) "bar" If you want to

Categories : PHP

Number of variables doesn't match - prepared statement
It's very confusing, but you can try: if (strlen($search) > 0) { $query = "SELECT p.product_id,p.account_id,i.image_id,a.email,p.title,p.price,MATCH(p.title) AGAINST('?' IN BOOLEAN MODE) AS score FROM products AS p LEFT OUTER JOIN products_images AS i ON p.product_id = i.product_id AND i.featured=1 AND i.deleted=0 INNER JOIN accounts AS a ON p.account_id = a.account_id

Categories : PHP

Which should I use? SQL Triggers or Cron Jobs?
I would use neither. I'd have a 'goLive' datetime and a 'retire' datetime for each piece of content. Then when you select which content to show, you'd have a where clause like this where current timestamp between goLive and retire Then your content appears at the 'goLive' time and disappears at the 'retire' time.

Categories : PHP

PHP create associative array from list($key, $value)
Just build the array with the $key and $value: $exploded = explode(" ",$string); foreach($exploded as $iteration) { list($key, $value) = explode(":",$iteration); $result[$key] = $value; } print_r($result);

Categories : PHP

Foreach and arrays
This is a comment: i want the formatting: Your code is incorrect, try this before your HTML of: <!DOCTYPE html: <?php session_start(); if(!isset($_SESSION['myusername'])) { header('Location:index.php'); } echo $_SESSION['myusername']; echo '<a href="logout.php"><span>Logout</span></a></li>'; ?>

Categories : PHP

Laravel - Combine JOIN data to one result
$arr = Video::distinct()->join("videos_languages","video_id","=","videos.id")->where("approved", 0)->get(); That should clean up duplicates from your results. Also note where() instead of whereRaw().

Categories : PHP

php CLI mode -f flag
PHP has a very long history with a lot of the design decisions lost in the mists of time; I'm not sure anyone will be able to tell you for certain why there's both a -f option and the ability to run a file without any options at all. However, it certainly seems designed for user convenience; most command line users would expect an interpreter to interpret a filename provided as a single parameter

Categories : PHP

Encrypt Image in Php Using AES Algorithm
The problem is that you don't encrypt the image, but only the filename. So you need to read the file contents from the temporary file, encrypt the contents and write the contents to the target file. The temporary file is deleted afterwards. if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { $fileData = file_get_conten

Categories : PHP

PHP PDOStatement prepare and bindValue methods
You should add error handling to your database calls, for example by setting up PDO to throw exceptions. Your current problem is that you don't actually execute() the statement: $select->bindValue(":name","1"); $select->execute(); After that you would need to fetch() results from the result set to actually see the values in your database: while ($row = $select->fetch()) { // do som

Categories : PHP

printing array values into a single cell through while loop in fpdf
This should work: while($result=mysql_fetch_array($query3)) { $queryResult = $queryResult . ', ' .$result[0]; } $pdf->Cell(55, 6, $queryResult, 1, 0, 'L', 1); The above is adding each result to $queryResult and adding a comma after it, then when all the results are printed it will print the $queryResult to the cell. Also you should avoid using mysql_* as this answer: The MySQL extens

Categories : PHP

WooCommerce - send custom email on custom order status change
The hook you need is: woocommerce_order_status_changed add_action("woocommerce_order_status_changed", "my_awesome_publication_notification"); function my_awesome_publication_notification($order_id, $checkout=null) { global $woocommerce; $order = new WC_Order( $order_id ); if($order->status === 'completed' ) { // Create a mailer $mailer = $woocommerce->mailer();

Categories : PHP

ImpressPages add pages custom fields
You can definitely add your fields to page details. Check the plugins for examples (this plugin adds it's own section - http://market.impresspages.org/plugins/PageImage). However, I doubt that you can add fields to a modal. If you really need this, create a feature request on GitHub.

Categories : PHP

Delete row wordpress custom database table
If jquery is an option , then it is very simple : $(".delete").on('click',function(){ $(this).parents("tr").remove(); }) check this

Categories : PHP

PHP ArrayAccess - multidimensional array and offsetGet with reference
I think this is becuase you are returning the result of an expression, not a variable. Try writing the if statement out and return the actual variable. see php manual -> second note

Categories : PHP

TLS Public Key Pinning with PHP + Curl?
"(No certificate authorities involved.)" By default, curl is setup to not trust any CAs. So there's that. And without going into great detail or opinion based responses, here's a well organized "Pinning Cheat Sheet" that may be of some help to you: https://www.owasp.org/index.php/Pinning_Cheat_Sheet (no bounty necessary <3)

Categories : PHP

Symfony2, add additional parameters to the route sent by the form
This is not a good way to create a sortable list, not in symfony. I suggest you take a look at KnpPaginatorBundle - SEO friendly Symfony2 paginator to sort and paginate. But, if you need to use code written above. I suggest you do the second select, separate to choose ASC / DESC.

Categories : PHP

PHP - Get REAL ipaddress
Use isset on all the checks. function get_client_ip_server() { $ipaddress = ''; if (isset($_SERVER['HTTP_CLIENT_IP'])) $ipaddress = $_SERVER['HTTP_CLIENT_IP']; else if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR']; else if(isset($_SERVER['HTTP_X_FORWARDED'])) $ipaddress = $_SERVER['HTTP_X_FORWARDED']; else if(isset($_SERVER['HTTP_FORWARDED_FOR'

Categories : PHP

htaccess - Redirect EVERYTHING through php file
You can use: RewriteEngine on RewriteCond %{REQUEST_URI} !(.|/$) RewriteRule (.*) %{REQUEST_URI}/ [R=301,L] RewriteRule ^((?!api.php$).*)$ api.php?url=$1 [L,QSA,NC] Lookahead (?!api.php$) means rewrite everything except /api.php to /api.php with query parameter url.

Categories : PHP

PHP ZipArchive extractTo() stalls with large files
A traditional .zip archive is limited in size to 4GB: The maximum size for both the archive file and the individual files inside it is 4,294,967,295 bytes (232−1 bytes, or 4 GiB minus 1 byte) for standard .ZIP, and 18,446,744,073,709,551,615 bytes (264−1 bytes, or 16 EiB minus 1 byte) for ZIP64. To decompress larger archives using ZIP64 in PHP, you'll need to use PHP 5.6 that uses libzip

Categories : PHP

HTML inside php condition
A little change to your code, although this is rather an ugly way to do it. <?php some logic = $usermatch if($usermatch) { ?> <img src="example1.php" /> <?php } ?>

Categories : PHP

str replace / preg replace hebrew words to hebrew words using array
You need to use mb_ereg_replace: setlocale( LC_CTYPE, 'en_US.UTF-8' ); header( 'Content-Type: text/plain; charset=utf-8' ); echo mb_ereg_replace( 'עיצוב-פנים', 'עיצוב פנים', 'Hebrew string is here: עיצוב-פנים ; and back to Latin.' ); This is because Hebrew letters are composed of multiple bytes and str_reaplce and preg_replace (by default) do not understand these.

Categories : PHP

How to use a remote database in Laravel
Granting Access Granting access to a user from a remote host is fairly simple and can be accomplished from just a few steps. First you will need to login to your MySQL server as the root user. You can do this by typing the following command: mysql -u root -p This will prompt you for your MySQL root password. Once you are logged into MySQL you need to issue the GRANT command that will enable ac

Categories : PHP

Get specified info from my database
Disabled form fields do NOT submit with the rest of the form: <textarea name="shout_name" class="form-control" disabled><?php echo etc... ^^^^^^^^^^ You don't show how/where you define $shout and $shout_name, but most likely you're not validating the form input at all, and are almost certainly vulnerable to sql injection attacks.

Categories : PHP

Umlauts and special characters are not displayed in php mysql
This sounds like an issue with character encoding, you need to use utf-8. I think the default is ascII. I only write pages in English but this guy has all of the steps needed.

Categories : PHP

PHP Show Div Amongst Other Divs
Count 6 outputs and concatenate your advert div: ... $i = 1; while($article = mysqli_fetch_assoc($get_article_res)){ if(6 === $i++) { $list_articles .= '<div class="advert">ADVERT CODE</div>'; } ...

Categories : PHP

PHP SimpleXML failure after slight change
$element->getElementsByTagName() returns a DomNode object, but $xml->createElement() asks for two strings. So when you try to create an element with $name or $vendor as a value, you're asking PHP to cast a DomNode to a string, but it's not able to do that. You may find some errors like this in your log file : Catchable fatal error: Object of class DOMElement could not be converted to string

Categories : PHP

Check if something exists in MySQL database
Try $sql = mysql_query("SELECT steamid FROM blacklist WHERE steamid =". $steamid); if(mysql_num_rows($sql)>0) { echo "not added as we already have that ID in the database"; }

Categories : PHP

preg_match_all undefined offset notice encountered
print_r(preg_match_all('/ logo += (.*)/', $a, $result, PREG_PATTERN_ORDER)); echo trim($result[0][0]); There are two errors in this sample of code. First there is a space before "logo" in the pattern. Your test string doesn't seem to have this space. Second, when you use preg_match or preg_match_all and want to use the match result, you need to use an if statement (because if the pattern is not

Categories : PHP

Simple way to get distinct column names in mysql
You can automatically enumerate columns in a way similar to this: $cols = []; $stmt = $db->exec("SHOW COLUMNS FROM events"); foreach($stmt as $r) $cols []= "e.{r['Field']} as e_{r['Field']}"; // the same for the second table, then $cols = implode(',', $cols); "SELECT $cols FROM ..." If you're doing many queries like this, you can cache generated column lists somewhere to avoid excess

Categories : PHP

php escape sequence not working
Try This: <pre><?php echo " hello!<br>"; echo " ", "hello!<br>"; echo " "."hello!<br>"; ?></pre> I would say you are probably viewing the generated page (html) rather than the page source.

Categories : PHP

CakePHP count all items with ID within a certain parrent
I would not define a virtual field in the model based on an aggregate function. I think what you need is a query that looks like: SELECT Content.destination_id, COUNT(Content.template_id) AS template_count FROM contents AS CONTENT GROUP BY Content.destination_id Try using this Cakephp code: $this->find('all' array( 'fields' => array('Content.destination_id' , 'COUNT

Categories : PHP

Sort MYSQL TABLES using a button with JQUERY
If I understand your question correctly, you want to extract the results of your MySQL database and you want to sort the ascending or descending tables. The best way to achieve your purpose is to use Datatable And more precisely Server-side processing

Categories : PHP

Jquery to serialize and submit form among several other forms
var $this = $(this); var tzip = $this.find('input.zip').val(); The problem here is that $(this) here select your submit button and not your form. Therefore $this.find('input.zip').val() does not return any value since there in no 'input.zip' in your submit button. To fix the problem you should replace this line with somthing like that for example: var tzip = $this.parent('form').find('input.zip

Categories : PHP

Execute MySQL from Vagrant machine that hasn't access to remote DB
It kinda worked for me doing the following: [vagrant@develpment ~]$ ssh -f username@remote_host -L 3306:mysql.host.lan:3306 -N [vagrant@develpment ~]$ mysql -h 127.0.0.1 -u usernamewrite -pPasswordOverPowered ... mysql> wohoooc Explaining, ssh -L forwards all the connections on localhost 3306 to remote_host and then connects to mysql.host.lan on port 3306. I had to shut down mysqld becau

Categories : PHP

Fixing a Wordpress Plug-in's HTTPS error in PHP, mixed content error when I know which files are creating the error?
The root of my problem was none of the above and it was a change in the way Wordpress internal variables worked. The plug-in I was attempting to troubleshoot was utilizing the following: define('WPA_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . WPA_PLUGIN_NAME); define('WPA_PLUGIN_URL', WP_PLUGIN_URL . '/' . WPA_PLUGIN_NAME); New Code which per these two links stating to do not use the internal Wordpres

Categories : PHP

Rewritten URL causes 406 error
Try RewriteEngine on RewriteCond %{REQUEST_FILENAME} -f RewriteRule method method.php [L] Your operation did not fail. Your backend service is saying that the response type it is returning is not provided in the Accept-Type HTTP header in your Client request. Ref: http://en.wikipedia.org/wiki/List_of_HTTP_header_fields Find out the response (content type) returned by Service. Provide this (

Categories : PHP

Mod_rewrite change url
Try: RewriteEngine On RewriteRule ^categories/gumball/(.*)$ /categories/gumball.php?categories=$1 [L] RewriteRule ^tags/gumball/(.*)$ /tags/gumball.php?tags=$1 [L] but make sure they're before any wordpress rules you already have in your document root.

Categories : PHP


Recently Add
Extracting sentences from text based on particular pattern
How to include tags in createNotification in PushApps api?
clarification on $_Files php command
Multiple where clause on Eloquent ORM Laravel
How to get the value in field by new line and update into the column in table with same id in php mysql?
Accessing session data in other method in same controller is not working in codeigniter
Bootstrap button, how to click multipite times
How to use __autoload function when use composer load
Not sure how to handle a fairly involved query with PHP/MySQL
Regex for detecting a word enclosed but in order
Using wpdb to search usermeta values
Codeigniter Multi Insert Query
exec() error, i cant figure it out how to make it work
how to Remove array and created new array in php
Proxy server in php
Cannot install YOURLS (PHP Parse error: syntax error, unexpected ';', expecting ')' in config.php on line 66)
Codeigniter if id = 1 it's work multiple image update but id =2 it's not working
How to add more than one tabs to a single facebook page by sdk in php
php server parse simple string using JSON to Android client
Mysql - most optimal way (performance and scalability) to store and retreive multiple lines of text
Break one array in to two different array in php
remove quotes from criteria params
CodeIgniter query result (class) includes non-property fields
How to delete the original image after resizing it
Sorting An Array By Key Value
PHP function On Each Page Causes Redirect Loop
Split date ranges into corresponding weeks
codeigniter do_upload is missing argument 1 on ubuntu server
Comparing only dates From the database Timestamp Laravel
Changing an individual foreach array field tag input type
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.