cereal 1,524 Nearly a Senior Poster Featured Poster

It can happen because the sizes input field is disabled, so it will not be sent with the POST request. In order to work fine, you should remove the disabled attribute:

sahilmohile15 commented: Thanks but what should i use to make read-only +0
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

which library are you using? In the UI I only see dialog() not modal(). Build an example page with full requirements, so that we can test, or share the libraries you're using. A part that you could check the values sent to the form through console.log(jQuery('#sizes').val()); in browser side and var_dump($_POST);, on PHP side, to see what you get from the form request.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

the foreach construct only accept these syntaxes:

foreach (array_expression as $value)

And:

foreach (array_expression as $key => $value)

it seems you're trying to extract two keys, it won't work. The array_combine() function does accepts only two arguments, you're submitting three arguments (arrays) so it will fail.

If these are multidimensional arrays the you could use array_merge() and write:

$data = array_merge($image, $page, $name);
foreach($data as $key => $value) {

But consider the following statements from the documentation:

If you want to append array elements from the second array to the first array while not overwriting the elements from the first array and not re-indexing, use the + array union operator

And:

The keys from the first array will be preserved. If an array key exists in both arrays, then the element from the first array will be used and the matching key's element from the second array will be ignored.

Documentation:

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, have you tried to set the headers like in command line?

cereal 1,524 Nearly a Senior Poster Featured Poster

@DuuBinJaX hi, please open your own thread, share your code and explain your issue.

cereal 1,524 Nearly a Senior Poster Featured Poster

You question is not clear, files are copied in the usb? How big are these 10 files?

cereal 1,524 Nearly a Senior Poster Featured Poster

With MySQL you can use FIND_IN_SET():

SELECT * FROM `example` WHERE FIND_IN_SET(192, `paricipantsId`);

Docs: http://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_find-in-set

Or, if you need something more complex and you switch to MariaDB, then you can use some new features for dynamic columns:

However, instead of storing this information in CSV style, consider to normalize it, in general this should give better performance, for more information check point 8 of diafol's tutorial:

cereal 1,524 Nearly a Senior Poster Featured Poster

Concerning the color: it can be different due to the monitor calibration, you should calibrate in both systems to get the same results.

cereal 1,524 Nearly a Senior Poster Featured Poster

It's up to you. I use arrays, like:

<?php

    return [
            'paths' => [
                'images' => '/path/to/images/directory/',
                'styles' => '/path/to/styles/directory/',
                # ...
            ],

            # ...
        ];

And/or dotenv: https://github.com/vlucas/phpdotenv

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi Davy, could you please use the code tag when you share code on this forum?

cereal 1,524 Nearly a Senior Poster Featured Poster

@Elva_1 hi, please open you own thread.

cereal 1,524 Nearly a Senior Poster Featured Poster

@Vinod you can do:

SELECT * FROM `table_name` WHERE `column_name` = '';

This will return only the empty strings, NULL values will be ignored by the statement. An example: http://sqlfiddle.com/#!9/0aa0bb/1

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

you mean you want to send an email in HTML format rather than plain-text? Check example 4 in the documentation of the mail() function:

However, I suggest you to look into libraries like PHPMailer or SwiftMailer.

cereal 1,524 Nearly a Senior Poster Featured Poster

Probably because of Username='{s}', by setting an existent username you should get the row, which means the query executes fine, which implies there is something else wrong in the code. Is $user defined?

$user = getUserData('users', 'UserUsername');
cereal 1,524 Nearly a Senior Poster Featured Poster

This happens for a typo, you're using partially uppercase variables:

$DBUser   = 'root';
$DBPass   = '';
$DBName   = 'upstrey';

While, in the connection, those variables are lowercase:

$mysqli = @new mysqli($DBServer, $dbuser, $dbpass, $dbname);

So for the mysqli class the database was not selected. Fix it and repeat.

cereal 1,524 Nearly a Senior Poster Featured Poster

In that case you would get the error message from the die() construct. Check the error log of the database or

I have executed successfully in phpMyAdmin

try to play the query returned by the error message directly into a MySQL client and see if you get some warnings SHOW WARNINGS;

Also you could try to replicate the query into a separated script:

$mysqli = @new mysqli('localhost', $dbuser, $dbpass, $dbname);

if($mysqli->connect_errno)
    die(sprintf("CONNECT ERROR: %s: %s", $mysqli->connect_errno, $mysqli->connect_error));

$result = $mysqli->query("YOUR QUERY");

if($mysqli->errno)
    die(sprintf("ERROR: %s [%s]: %s", $mysqli->errno, $mysqli->sqlstate, $mysqli->error));

while($row = $result->fetch_row())
    print $row[0];

And see what you get.

cereal 1,524 Nearly a Senior Poster Featured Poster

By commenting line 22 or by setting the trigger on the error number, can you get the MySQL error code? The message refers to the query, but it seems fine, so the error code should give the correct information. Alternatively check the MySQL server error log.

cereal 1,524 Nearly a Senior Poster Featured Poster

No, I was referring to the MySQL error code that you can display by using $conn->errno:

Replace line 21 with this:

echo "db problem: " . conn->errno;

Currently with line 22 you are only displaying the error message.

cereal 1,524 Nearly a Senior Poster Featured Poster

What's the error number? Do: echo $conn->errno;

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

the above code will download the file to the web server executing the script, not to the home directory of the client browser.

In practice: if the path /home/jiby/Downloads/image.jpg does not exists in the web server root, then the script will fail.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,
follow the documentation and read also the comments on the same page:

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, can you show what generates the error and the error code and message?

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, I don't think PHP 8 exists at all at this point. Where did you read about it?

cereal 1,524 Nearly a Senior Poster Featured Poster

In addition, for a simple approach you could use require to load the generator file and loop the offerid to it, for example:

<?php

    # example array
    $offerid = range(1, 10);

    foreach($offerid as $value)
        require 'archiveinv.php';

Then in archiveinv.php instead to refer to $_GET['offerid'] use $value which is set in the loop:

<?php
    # your code here
    print $value;

Otherwise create a set of functions or a class, load the file once and then loop the methods to generate the file:

<?php

    require 'archiveinv.php';

    $offerid = range(1, 10);

    foreach($offerid as $value)
        echo printIt($value);

And in archiveinv.php:

<?php

    function printIt($var)
    {
        return $var;
    }

This is more the PHP way. In any case there are at least two issues:

  1. it is synchronous, so the user must wait for the script to complete the execution
  2. the script can timeout and break the flow

To avoid them I would use cronjob or, if I want to start the job immediately, Beanstalkd with a good client:

cereal 1,524 Nearly a Senior Poster Featured Poster

Sorry if I insist but it's not clear:

Yes, the target is to producing html-files. Create them as many as selected by first guery, like all offers included specified time-window.

So the goal is to generate a cache system or simply to show the selected offers? If you want to show the offer why you want to generate an HTML file for each id? Could you just populate the script?

Is the submitter going to browse the new generated files right after the generation?

You could do something similar to your approach by using curl with an HEAD request, but it will open a new connection for each offerid (unless you set up for reuse) and with the current approach it will perform a new query to the database for each offerid. This will slow down the execution. You could fork but how many concurrent executions can your server support?

Only one by one.
With PHP, can it be done as looping scripts, like with cmd-scripts. I have seen only query results done by loop, showing the data, but executing actions, can it?

You can execute an action, but there are several ways to do it: if your goal is to generate something in background you could save the offerid list to a database table and then use cronjob to execute the task by batching the result set, but it will execute a batch per minute and you will have to batch otherwise the script …

cereal 1,524 Nearly a Senior Poster Featured Poster

I would like to understand better what's your goal: producing HTML files for archiving? The result is needed in the following step by the user?

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

it happens because the header('Location: url'); will be overwritten by the last loop value, which is what will be executed. You cannot start multiple redirections.

Also, what is this line supposed to do?

$key . " : " . $value . "";

Print?

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, are you sure the database system allows remote connections? The default setup for MySQL listens on localhost. Consider also that some hosting services provide access only from a restricted range of IPs, usually their web servers.

cereal 1,524 Nearly a Senior Poster Featured Poster

I wondered if their syntax was safe against sql attacks, though in fact could be improved with the inclusion of the bind, but do not know how to make them better.

Use prepared statements, add a second parameter to the getOne() and getAll() methods and send an array, for example:

function getOne($query, $input) {
    $result = $this->conn->prepare($query);
    $ret = $result->execute($input);
    if (!$ret) {
       echo 'PDO::errorInfo():';
       echo '<br />';
       echo 'error SQL: '.$query;
       die();
    }
    $result->setFetchMode(PDO::FETCH_ASSOC);
    $reponse = $result->fetch();

    return $reponse;
}

function getAll($query, $input) {
    $result = $this->conn->prepare($query);
    $ret = $result->execute($input);
    if (!$ret) {
       echo 'PDO::errorInfo():';
       echo '<br />';
       echo 'error SQL: '.$query;
       die();
    }
    $result->setFetchMode(PDO::FETCH_ASSOC);
    $reponse = $result->fetchAll();

    return $reponse;
}

Then when you execute the query you do:

$input = [1, 2, 3];

$db = new db;
$result = $db->getAll("select * from users where id IN(?, ?, ?)", $input);
cereal 1,524 Nearly a Senior Poster Featured Poster

the written file doesn't have nothing inside

it happens because the source is not found, so even if a new file is created it will be empty, you could try:

if(file_exists($source))
{
    # execute copy code here
}

Consider also that your forms sends getfile and then you search for file.

target is to put script to real web-site, and get files from it to local machine

If you run the script from local, and the source path is remote (an URL not an internal path) then it can work, as in my previous example. But file_put_contents() executed on remote server cannot copy the file to local. Here you can use FTP as already noted by you, but you can also force a download:

<?php

    # check if file index exists in $_POST array
    # and if is not empty
    if(array_key_exists('file', $_POST) && ! empty($_POST['file']))
    {

        # file position: 'http://www.domain.tld/files/hello.gif'
        # $_POST['file'] value: 'hello.gif'
        $file = pathinfo($_POST['file'])['basename'];

        # internal path: /var/www/domain.tld/files/hello.gif
        $path = $_SERVER['DOCUMENT_ROOT'] . '/files/';
        $filepath = $path . $file;

        if(file_exists($filepath))
        {
            header('Content-Description: File Transfer');
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename="'.basename($filepath).'"');
            header('Expires: 0');
            header('Cache-Control: must-revalidate');
            header('Pragma: public');
            header('Content-Length: ' . filesize($filepath));
            readfile($filepath);
            exit;
        }

        else
            error_log('ERROR: file not found');
}

else
    error_log('ERROR: "file" index not set in POST array.');

# in case of error redirect to form
  header('Location: ' . $_SERVER['HTTP_REFERER']);

The example source: http://php.net/manual/en/function.readfile.php
Check also: http://php.net/pathinfo

Live example: http://code.runnable.com/VwjTLtHI25Me5nn4/testing-download

cereal 1,524 Nearly a Senior Poster Featured Poster

In addition: check also about composer, it's a dependency manager for PHP, most frameworks support it and it allows to easily share and include libraries into a project:

However you don't really need to use a framework to take advantage of composer, you can use flat PHP. A part that a framework can be useful because it provides a defined and tested structure.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

I didn't downvoted but I suspect it happened because you should show some efforts on your side and share the code you've written to achieve the requested goals. This forum is not a code service.

In other words if you have doubts about a specific step of your code, we can help.

cereal 1,524 Nearly a Senior Poster Featured Poster

@masimies Hericles suggested you add the second argument to the file_put_contents() function:

the first argument define the path in which the file will be saved and the filename, the second argument is the data you want to copy into that file. From your replies I don't understand if you have changed line 5, to reflect the suggestion. As example:

<?php

# source path
$source = 'https://upload.wikimedia.org/wikipedia/commons/5/56/Answer_to_Life.png';

# read the data
$data = file_get_contents($source);

# define destination path & filename
$path = 'download/the_answer.png';

# save it
file_put_contents($path, $data);

Once this is assumed you have to check the paths, for example on line 3 and 4 you set:

$file = $_POST['file'];
file_get_contents('files/$file');

Which:

  1. is unsafe because, if not sanitized, it allows a directory traversal attack which allows a user to copy an arbitrary file from the serving file system
  2. if the script is not in the parent directory of files/, then it can fail, here you should define an absolute path or relative to the script

For example:

/form/script.php
/files/
/download/

Then the relative path would be ../files/ and ../download/. To simplify the debugging enable the error reporting, set this command at the very top of your script:

error_reporting(E_ALL);

And, in case you still have doubts, paste the errors here.

cereal 1,524 Nearly a Senior Poster Featured Poster

@masimies hi, can you show the updated code?

cereal 1,524 Nearly a Senior Poster Featured Poster

By loading your data with that table structure I get:

load data local infile '/tmp/march2016.csv' into table refs fields terminated by ',' enclosed by '"' escaped by '' lines terminated by '\n' ignore 1 rows;
Query OK, 1 row affected, 3 warnings (0.02 sec)      
Records: 1  Deleted: 0  Skipped: 0  Warnings: 3

> show warnings;
+---------+------+----------------------------------------------------+
| Level   | Code | Message                                            |
+---------+------+----------------------------------------------------+
| Warning | 1265 | Data truncated for column 'date_received' at row 1 |
| Warning | 1261 | Row 1 doesn't contain data for all columns         |
| Warning | 1261 | Row 1 doesn't contain data for all columns         |
+---------+------+----------------------------------------------------+
3 rows in set (0.00 sec)

But the data is inserted, however it seems that your csv has only 58 columns, while the table has 60 columns, so this generates the warnings with code 1261.

You could also check if an SQL Mode is enabled, you can do that by running:

SELECT @@sql_mode;

In some cases, for example when strict mode is enabled, the insert can be rejected. More info here:

cereal 1,524 Nearly a Senior Poster Featured Poster

Your query, with a custom table and data, works fine for me. Could you provide your table schema? Run this:

show create table `refs`\G

Also: is the above example data still valid? So that I can test it.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

look at the result message:

Query OK, 0 rows affected, 33 warnings (0.00 sec)
Records: 11 Deleted: 0 Skipped: 11 Warnings: 33

by running SHOW WARNINGS; after the load query, you should get some information about the statement issues.

cereal 1,524 Nearly a Senior Poster Featured Poster

No, she's checking if the article exists in the articles table, if TRUE then she adds the rating to the articles_rating table.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

it seems fine to me. Make sure the database connection is available by adding an error check:

if ($db->connect_errno) {
    die('Connect Error: ' . $db->connect_errno);
}

Check also if you get through each IF condition by placing something like die('stop at ' . __LINE__); and so on after each condition, so you can see where the script stop its execution, for example:

if(isset($_GET['article'], $_GET['rating'])) {

    $article = (int)$_GET['article'];
    $rating = (int)$_GET['rating'];

    if(in_array($rating, [1, 2, 3, 4, 5])) {

        $exists = $db->query("SELECT id FROM articles WHERE id = {$article}")->num_rows ? true : false;

        if($exists) {
            $db->query("INSERT INTO articles_ratings (article, rating) VALUES ({$article}, {$rating})");
            die('stop at ' . __LINE__);
        }

        die('stop at ' . __LINE__);
    }

    die('stop at ' . __LINE__);
    header('location: article.php?id=' . $article);
}

die('stop at ' . __LINE__);

You could also add the third parameter to the in_array() function, it's boolean TRUE and it is used to enable a type check, so:

if(in_array($article, range(1, 5), TRUE) {

Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster
cereal 1,524 Nearly a Senior Poster Featured Poster

Look also at a PHP Accellerator like APC: https://en.wikipedia.org/wiki/List_of_PHP_accelerators

cereal 1,524 Nearly a Senior Poster Featured Poster

The column is a string type and the value is literally something like 0 values or is an integer, float column?

Can you show the table schema and an example of data?

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, the attachment is sent to Gmail servers. Yahoo will only deliver the mail.

In practice the email body attachment part is composed by an header and by the content, some examples here:

cereal 1,524 Nearly a Senior Poster Featured Poster

Which PHP version are you using? Note that the fork is using at least a function available only on PHP 5.5.0+, hash_pbkdf2 used to hash the password:

Consider that I haven't tested the original code neither this fork, so I'm not sure the latter is fully functional.

Look, I hate to have a negative attitude but, in this case, consider that this library:

  • is not documented
  • is not actively maintained
  • embeds an outdated (2007) class dependency (PHPMailer v 2.0.9) in the package, while the latest version is currently 5.2.14 and now available through composer

Ok, PHPMailer should be easy to upgrade but, in my opinion, the main library should use a generic interface, so that you could easily switch the underlying code.

In such situation, I would prefer to start from scratch rather than trying to fix and build my own system, it's a lot easier.

If you're still interested then wait for other responses, you could receive better advices.
Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

You could try to add some conditions to the methods involved in the process, to see if you can track down the error, otherwise try to contact the current maintainer, to see if he can suggest you how to fix it.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

you can find a fork of the original code on GitHub, which has been updated to MySQLi, here's the link to the code:

The upgraded fork was started after the pull request was not merged, as you can read here:

Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

It's used to load an external resource, in this case a stylesheet with specific rules for a printer version of the HTML page, check:

The above is almost equivalent to:

<style>
    @import '/styles/print.css' print;
</style>
cereal 1,524 Nearly a Senior Poster Featured Poster

Do you mean a payment from user A to user B without involving your account? Check the Adaptive Payments API:

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, it could be a problem with the innodb_buffer_pool_size, the default value is 128MB of RAM, try to increase it, you can follow the suggestions in the documentation:

If this does not help check the others processes to see if something else (the web server) is using too much resources.

cereal 1,524 Nearly a Senior Poster Featured Poster

2 & 3 are obvious, yes, I was repeating them just to clarify point 7: not all hostings will allow Tor nodes in their networks, so it would be difficult to perform the necessary steps to build such config.

Point 4: when you start the database connection with something like new mysqli() or new PDO() and add the onion link (e.g. mysql=host:0123456789abcdef.onion) the system will call the system glibc function getaddrinfo() to resolve the link with a DNS query and then the connect() function, at least in linux. The onion link is not resolvable with a DNS call and MySQL will not try to inject the request in the Tor node, so the connection will fail.

You could use the PHP socket extension but then you cannot use the MySQL APIs and you will have to submit the queries in raw mode and then parse the results which is like a telnet session, or like running queries from command line:

mysql -s -r -D DBNAME -e "SELECT * FROM `table_name`;"

The alternative is to force the API connection through socks but the MySQL (API) client does not support them directly, so you will need something like socat to create the local entry point, some examples, here:

This, for example, works fine for me:

socat TCP-LISTEN:3308 SOCKS4A:localhost:0123456789abcdef.onion:3306,socksport=9050

Then you can connect to the database through the local tunnel opened on port 3308:

$conn = new PDO("mysql=localhost:3308;dbname=DATABASE", "USER", "PASS");

Unless you are meaning that …