cereal 1,524 Nearly a Senior Poster Featured Poster

After the execute() do:

$id = $con->lastInsertId();

Docs: http://php.net/manual/en/pdo.lastinsertid.php

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

you can get a list in JSON format here:

you can get a free API key for 1000 request per month and get currency rates hourly updated:

And build your own system, but you should consider using a library, like MoneyPHP:

The doc directory has many examples, as how converting between currencies.

cereal 1,524 Nearly a Senior Poster Featured Poster

Ok, it happens because the topics table is not listed it the FROM statement, add it as a JOIN, it should fix this issue.

cereal 1,524 Nearly a Senior Poster Featured Poster

Good, can you show also the query cited in your first post?

cereal 1,524 Nearly a Senior Poster Featured Poster

Ok, can you show the full query and the create table statement? Run: show create table topics;

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

topics.id stands for tableName.columnName, if this is not the case and you have a column name with a dot, then do:

SELECT `topics.id` FROM `topics`;

This will select the column with the dot. If it was a table name, instead it would be:

SELECT `topics`.`id` FROM `topics`;

Ref: http://dev.mysql.com/doc/refman/5.7/en/identifiers.html

cereal 1,524 Nearly a Senior Poster Featured Poster

Set exit; after the redirect, as in this comment:

That will stop the execution of the following code. Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, use the search box in the developers website:

From there you can see how the add and update metadata functions are used and in which files are written.

See also:

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, I use this tool: http://www.generatedata.com/

The online version is limited to 100 entries, but it can be downloaded for free from github and loaded in local PHP server, just do php -S localhost:8000.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

just add delimiters to the pattern variable, in your case it's $word, for example:

<?php

    $color = 'red';
    $text  = 'This is an example text sentence.';

    $eregPattern = 'example';
    $pregPattern = '/example/';

    $replacement = '<font style="background:' . $color . ';">\0</font>';

    echo eregi_replace($eregPattern, $replacement, $text);
    print PHP_EOL;

    echo preg_replace($pregPattern, $replacement, $text);
    print PHP_EOL;

I how do I check preg_replace function is executed or not?

From the documentation:

preg_replace() returns an array if the subject parameter is an array, or a string otherwise.

If matches are found, the new subject will be returned, otherwise subject will be returned unchanged or NULL if an error occurred.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, s stands for string, if you want two conditions, for example a string and a digit you will write:

$city = 'Aurora';
$state_id = 1;
bind_param("si", $city, $state_id)

Read the documentation to see the data types you can define:

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, don't use single or double quotes around table and column names, otherwise these are interpreted as strings, use backticks, so:

INSERT INTO `members` (`username`, `password`, `email`) VALUES ('axe', 'axe', 'weql');
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, in this case it would be bindColumn() instead of bind_result() as the OP is using PDO, not MySQLi:

// edit
I added the PDO tag to the thread, to avoid confusion, bye! :)

cereal 1,524 Nearly a Senior Poster Featured Poster

Hello, have you tried with a left join? If table 1 is reference then try this example for MySQL:

SELECT `r`.`no`, `r`.`referenceno`, `r`.`date`, `m`.`controlno` FROM `reference` AS `r` LEFT JOIN `marine` AS `m` ON `m`.`referenceno` = `r`.`referenceno` AND `r`.`marine` = 'y' ORDER BY `r`.`no`;

Live example here: http://sqlfiddle.com/#!9/b2fca/1

Knowing the data model relationship (one to many, one to one, ...) and the database (MSSQL, MySQL, PostgreSQL, ...) could help.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

at the moment you're using the $username variable directly inside the query and without quotes:

where username = $username

change it to the placeholder:

where username = :username

as is set by the bindValue() method.

Also, if not used, remove the :roleid bindValue() as that will produce:

'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens'

i.e. a fatal error that will stop the script.

If this still does not solve, then enable the PDO exceptions and the PHP error logging and post back with detailed errors.

cereal 1,524 Nearly a Senior Poster Featured Poster

Use intval() as suggested or $id = (int) $_GET['id'];, see:

Or in case of validation use filter_input():

$id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);

Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

Sorry, due to the PHPMailer tag I thought you were using the library.

From what I see you're using fsockopen() which works, but depending on the authentication mode your SMTP client must be required to reply to the server, before actually sending the message and, if this does not happen, then it will throw an error and close the connection. For this reason you should check the SMTP server logs.

If you can't, then try to use the linked library, it handles multiple authentication methods and it allows to debug easily.

cereal 1,524 Nearly a Senior Poster Featured Poster

I am unable to send a mail. Please help me to fix the issue.

Hi, unable in which sense? The script fails the connection with the SMTP or something else? Do you have PHP error logs or SMTP error logs?

Replace lines below and including 47 with:

if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

You should get some additional information about the error. You can also raise the debug level through $mail->SMTPDebug = 2;.

Some notes about the debugging with PHPMailer:

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, I'm not sure I've understood: line 26 of check.php is line 1 of the other code block?

cereal 1,524 Nearly a Senior Poster Featured Poster

Have you tried with DateTime?

<?php

$one = '09:30 am';
$two = '11:00 AM';

$time1 = new Datetime($one);
$time2 = new Datetime($two);

$diff = $time1->diff($time2);

print_r($diff);

Which outputs a DateInterval object like this:

DateInterval Object
(
    [y] => 0
    [m] => 0
    [d] => 0
    [h] => 1
    [i] => 30
    [s] => 0
    [weekday] => 0
    [weekday_behavior] => 0
    [first_last_day_of] => 0
    [invert] => 0
    [days] => 0
    [special_type] => 0
    [special_amount] => 0
    [have_weekday_relative] => 0
    [have_special_relative] => 0
)

From there, then it should be easy to perform the statements. Docs:

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, you can explode() by comma and trim(), try:

$tags = 'cats, funny, hair cut, funny hair cut';
$result = array_map('trim', explode(',', $tags));
cereal 1,524 Nearly a Senior Poster Featured Poster

If the update is limited to a single row, as in your example query, you could add rec_id = LAST_INSERT_ID(rec_id) to register the value to the function and then select it, for example:

UPDATE tier_".$tier_num."
SET payer_ID = '".$payer."', sub_ID = '".$payer_sub."', create_date = '".$created."',  status = 'I', rec_id = LAST_INSERT_ID(rec_id)
WHERE status = 'V'
ORDER BY rec_ID asc
LIMIT 1

And then just run:

SELECT LAST_INSERT_ID() as `rec_id`;
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi

And also, the checkbox says it's all ticked even the values are different (lines 61 - 63 of index.php)

what do you mean?checked is a boolean attribute, which means:

A number of attributes are boolean attributes. The presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value.

If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace.

The values "true" and "false" are not allowed on boolean attributes. To represent a false value, the attribute has to be omitted altogether.

Source: https://developers.whatwg.org/common-microsyntaxes.html#boolean-attribute

so in order to set a checkbox you have to verify the value returned by the row and decide if you want to include the attribute, for example:

<input type="checkbox" name="present" id="present"<?php echo $row['present'] > 0 ? ' checked':'';?>>
cereal 1,524 Nearly a Senior Poster Featured Poster

And $sizes will be an array, correct? From your previous code I see you set two different variables: $sArray or an empty $sizesArray. You can save an array into a table column, but you have to convert it to a string:

  • through $data = implode(',', $sizes); to generate a CSV list;
  • or to a JSON string through $data = json_encode($sizes);;
  • or use $data = serialize($sizes);.

An alternative is the dynamic column available in MariaDB, a MySQL fork, which allows you to store data as JSON in a blob column type, for example:

<?php

    $conn = require 'pdo.php';
    $sizes = [123, 456, 789];
    $quantities = [17, 23];

    $stmt = $conn->prepare('INSERT INTO `test` SET `features` = COLUMN_CREATE(?, ?, ?, ?)');
    $stmt->execute(['sizes', implode(',', $sizes), 'quantities', implode(',', $quantities)]);

Which then looks like:

SELECT COLUMN_JSON(`features`) AS `features` FROM `test`;
+----------------------------------------------+
| features                                     |
+----------------------------------------------+
| {"sizes":"123,456,789","quantities":"17,23"} |
+----------------------------------------------+
1 row in set (0.00 sec)

And allows a bit more flexibility when storing variable attributes like above. Docs: https://mariadb.com/kb/en/mariadb/dynamic-columns/

cereal 1,524 Nearly a Senior Poster Featured Poster

Try to replace disabled with readonly:

But if it is for security, don't rely on this solution, as one can easily edit the form and submit arbitrary input. Please, reply with a post not with a comment, thanks.

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

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

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, can you show what generates the error and the error code and message?

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

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

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, 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 …

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, what's the result of curl_error()?

cereal 1,524 Nearly a Senior Poster Featured Poster

Is there a specific reason for this setup? Some points to consider:

  1. MySQL does not support socks connections, you can create a socket unix file, but it's not the same thing
  2. you will have to setup Tor nodes in both ends: application server and database server
  3. you will have to setup an hidden service in order to generate private & public key in the database server
  4. share the public key in the application server and connect through a Tor client or proxy
  5. latency issues
  6. the database will still be exposed to attacks and if an attacker can access the application server or run SQL injections, then it can track back the database server location
  7. does your hosting allows such setups?

It would be a lot easier to set up a SSH tunnel or to use Tor to serve an HTTP database interface and then use curl to perform CRUD operations, but this will avoid only point one of the above list, the other points will still be valid.

cereal 1,524 Nearly a Senior Poster Featured Poster

I'm thinking not because I don't really want "smutt" related to my website.

It's probably the same for your other clients, I doubt they would like to be associated with an adult site.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, in practice this is a page that waits for a POST form submission, made by the PayPal service. An example can be found in their GitHub account:

You receive data and send it back to check if it's valid, then you can use save it.

Source:

By the way, I prefer using Guzzle instead of cURL, if you want to consider it here's the documentation:

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

if you have, or can enable, the intl extension then use the IntlDateFormatter class:

Look also at the comments in the documentation page.

cereal 1,524 Nearly a Senior Poster Featured Poster

i have deleted them and placed my files there. Maybe its because of them ?

This should not affect the execution of your scripts or the connection, in general, to the database.

So i need to pay for my account to use 000webhost ?

No, unless you want to connect directly to the database from another host (i.e. localhost, or another web hosting service).

Also i had on the same server other files and it was working good.. so now when im uploading this new files that error appear.

This confuses me: the error reported in your first post returns a Macedonian IP address, which means the attempt connection was executed from a script in a computer in Macedonia, not from a 000webhost machine.

If $DBServer is a 000webhost database and the scripts are executed in a 000webhost hosting then, you may want to ask help to their support or to their forums.