:::: MENU ::::
Browsing posts in: Stackoverflow.com

What does the “Unrecognised SQL statement” mean when I am trying to use IF NOT EXISTS?

May 28, 2017    |      Comments Off on What does the “Unrecognised SQL statement” mean when I am trying to use IF NOT EXISTS?

This is how to do it, I have test it and it works:

$sql = "
    INSERT INTO users (username, password)
    SELECT * FROM (SELECT '$user', '$phash') AS tmp
        SELECT username FROM users WHERE username = '$user'
    ) LIMIT 1;

This solution is inspired from this answer.

The problem is that you can not combine PHP and MySQL statement like you did, you need to encapsulate all MySQL statements in quote ".

What comes RAISERROR, it is not MySQL function, it belongs to Microsoft.

You could easily make php if statement that checks if $sql contain valid username and return your message. That part is left to your fantasy.

XAMPP has no thing to do with the error, it just a software that provides an Apache and MySQL installation for Windows.

Note: P.S. please learn to use parameterized queries, because your
code is vulnerable to SQL injection. thanks to @BillKarwin for mentioning this.

Powered by WPeMatico

Laravel password validation rule

May 21, 2017    |      Comments Off on Laravel password validation rule

I have had a similar scenario in Laravel and solved it in the following way.

The password contains characters from at least three of the following five categories:

  • English uppercase characters (A – Z)
  • English lowercase characters (a – z)
  • Base 10 digits (0 – 9)
  • Non-alphanumeric (For example: !, $, #, or %)
  • Unicode characters

First, we need to create a regular expression and validate it.

Your regular expression would look like this:


I have tested and validated it on this site. Yet, perform your own in your own manner and adjust accordingly.

So your final Laravel code should be like this:

'password' => 'required|


  1. I have tested and validated it on both the regular expression site and a Laravel 5 test environment and it works.
  2. I have used min:6, this is optional but it is always a good practice to have a security policy that reflects different aspects, one of which is minimum password length.
  3. I suggest you to use password confirmed to ensure user typing correct password.
  4. Within the 6 characters our regex should contain at least 3 of a-z or A-Z and number and special character.
  5. Always test your code in a test environment before moving to production.

Some online references

  • http://regex101.com
  • http://regexr.com (another regex site taste)
  • http://www.regular-expressions.info/refquick.html
  • https://msdn.microsoft.com/en-us/library/az24scfc%28v=vs.110%29.aspx
  • http://php.net/manual/en/function.preg-match.php
  • http://laravel.com/docs/5.1/validation#rule-regex

Regarding your custom validation message for the regex rule in Laravel, here are a few links to look at:

  • Laravel Validation custom message
  • Custom validation message for regex rule in Laravel?
  • Laravel custom validation messages
  • How to add regex to attribute name in custom validations in Laravel?

Powered by WPeMatico

open big URL from a batch file

May 20, 2017    |      Comments Off on open big URL from a batch file

This would work

@START /d "C:Program FilesInternet Explorer" IEXPLORE.EXE ""12345678"&MessageText="Test SMS"&ConfirmDelivery=False&Priority=0"

Powered by WPeMatico

Command line progress bar in Java

Apr 13, 2017    |      Comments Off on Command line progress bar in Java

I have made a percentage progress bare to check the remain download file.

I call the method periodically in my file download to check the total file-size and remaining and present that in %.

It can be used for other task purpose as well.

Test and output example

progressPercentage(0, 1000);
[----------] 0%

progressPercentage(10, 100);
[*---------] 10%

progressPercentage(500000, 1000000);
[*****-----] 50%

progressPercentage(90, 100);
[*********-] 90%

progressPercentage(1000, 1000);
[**********] 100%

Test with for loop

for (int i = 0; i <= 200; i = i + 20) {
    progressPercentage(i, 200);
    try {
    } catch (Exception e) {

The method can be easily modified:

public static void progressPercentage(int remain, int total) {
    if (remain > total) {
        throw new IllegalArgumentException();
    int maxBareSize = 10; // 10unit for 100%
    int remainProcent = ((100 * remain) / total) / maxBareSize;
    char defaultChar = '-';
    String icon = "*";
    String bare = new String(new char[maxBareSize]).replace('', defaultChar) + "]";
    StringBuilder bareDone = new StringBuilder();
    for (int i = 0; i < remainProcent; i++) {
    String bareRemain = bare.substring(remainProcent, bare.length());
    System.out.print("r" + bareDone + bareRemain + " " + remainProcent * 10 + "%");
    if (remain == total) {

Powered by WPeMatico

Java Server Thread Error using command line arguments on a mac terminal (Eclipse file)

Apr 9, 2017    |      Comments Off on Java Server Thread Error using command line arguments on a mac terminal (Eclipse file)

You are trying to parse -l to integer, that is the problem.

java DirectMessengerServer -l 6004

Your first argument is String type and the second is Integer.

This exactly what the screen shot error says.

args[0] for -l

args[1] for port number

I am not sure why you have a loop for your arguments but correcting the argument number would solved the problem in your question, that said you are not using port number variable and your code logic can be improved a bit.

Powered by WPeMatico

how to count same token on arraylist in java

Mar 18, 2017    |      Comments Off on how to count same token on arraylist in java

This is also possible with Java8:

Map counts = hasil.parallelStream()
        .flatMap(elm -> Arrays.stream(elm.split(" ")))
        .collect(Collectors.toConcurrentMap(w -> w, w -> 1, Integer::sum));


The output would be:

{saya=3, dimana=1, makan=2, kamu=2}

Powered by WPeMatico

mail smtp host with Java

Mar 17, 2017    |      Comments Off on mail smtp host with Java

Logically if you get one email not the other than it is not your sender software that has problem. This issue is highly related to your mail.smtp.host server or domainCompanynameA.com.

Since mail.smtp.host can send some thing to gmail. I suspect domainCompanynameA.com has blocked your mail.smtp.host for various reasons.

One way to solve this is to white list your mail.smtp.host at domainCompanynameA.com.

Else it requires investigation to locate where the exact problem comes from.

I would highly recommend using 3rd part email api service, hence they are trusted and maintained.

Powered by WPeMatico

alf.nu random4 excercise, what is the answer?

Mar 16, 2017    |      Comments Off on alf.nu random4 excercise, what is the answer?

This question is for learning purpose and to trick you understanding the concept.

The only number that is equal to rand is rand in this case, so if you pass rand to the function than x get the same value as rand.

To test that, just call the function in your console.log and it would return true.


Powered by WPeMatico

Volley request queue can't remove single entry

Feb 21, 2017    |      Comments Off on Volley request queue can't remove single entry

getCache().clear() has perhaps helped in my situation.


Have also a look at this question, it might also enlighten you.

Note: depending on how your code is made, be sure your requestQueue
is only instantiated once.

Powered by WPeMatico