2

I have a V-server by 1and1. Unfortunately the support is not sufficient.
This code is part of a login file and has been working for nearly 1½ year. Since yesterday the execute statement return false. I have tried different things, but I cannot find out why execute return false ?

$mail     = "test";
$password = "test";
$prep = "SELECT id FROM member WHERE address=? AND password=?";
if ( $stmt = $mysqli->prepare($prep))
{
$stmt->bind_param( "ss", $mail, $password );
$stmt->execute();
$stmt->bind_result($id);
if ($stmt->fetch())
..........

When I reduce the SELECT statement and remove AND, the $stmt->execute() returns TRUE.

$mail     = "test";
$password = "test";
$prep = "SELECT id FROM member WHERE address=?";
if ( $stmt = $mysqli->prepare($prep))
{
$stmt->bind_param( "s", $mail );
$stmt->execute();
$stmt->bind_result($id);
if ($stmt->fetch())
..........

When I add an AND either an OR it fails again ?

$mail     = "test";
$password = "test";
$prep = "SELECT id FROM member WHERE address=? OR password=?";
if ( $stmt = $mysqli->prepare($prep))
{
$stmt->bind_param( "ss", $mail, $password );
$stmt->execute();
$stmt->bind_result($id);
if ($stmt->fetch())
..........
  • Bear in mind that hosting support can never extend to debugging programs - that responsibility always lies with the customer. Debugging is a minefield that no sensible host will ever enter into. – halfer Jul 05 '14 at 15:15
  • Add error reporting to the top of your file(s) `error_reporting(E_ALL); ini_set('display_errors', 1);` see if it yields anything. – Funk Forty Niner Jul 05 '14 at 15:16
  • If the `if` fails, look up the error using the appropriate error getter on `$mysqli`. (@Fred's advice is sound, but if you make that change on a live site, make sure you change it back again - live sites should not leave error reporting enabled). – halfer Jul 05 '14 at 15:17
  • does the `password` column still exist? – FuzzyTree Jul 05 '14 at 15:20
  • Thank you for your fast response. I will add the error reporting and see what I get beck. Yes, the password still exist. The select query work also when I exchange mail with password. Only when I have 2 columns in the select it fails. But it is execute that returns FALSE back. prepare and bind_param returns TRUE. I agree halfer. But this is not a new development. This side runs over a year without change. I expect from a host that they could inform what they have change if from one day to another this occur. – user3807924 Jul 05 '14 at 16:18

2 Answers2

2

Probably query became not valid.(i know that it was working) try ti see the errors report

printf("%s\n", $mysqli->info);
printf("Errormessage: %s\n", $mysqli->error);

I think, the mysqli bind_param is not working corectly with not English letters so if you have some letters or symbols....... try to put this line before prepare statement

$connection->set_charset('utf8');
volkinc
  • 2,143
  • 1
  • 15
  • 19
  • Errormessage: Incorrect arguments to mysqld_stmt_execute – user3807924 Jul 05 '14 at 16:47
  • OK, that explains the return of FALSE from execute, but what is wrong ?? In my local host it runs without problems on the same mysql databse ?? – user3807924 Jul 05 '14 at 16:49
  • please, print out the sql query.and try it at phpmyadmin directly – volkinc Jul 06 '14 at 02:36
  • The SQL query works in the phpmyadmin directly, but not in the prepared statement ? – user3807924 Jul 06 '14 at 07:33
  • If the host changed suddently the php version, can that occure in such a result ? Normally I can with php 5.2. – user3807924 Jul 06 '14 at 07:43
  • updated the answer, I think you have non ascii symbols so try $connection->set_charset('utf8'); before prepare statement – volkinc Jul 06 '14 at 13:58
  • 1
    In have tried to find a similar error: http://stackoverflow.com/questions/10053955/mysqli-bind-param-giving-error-1210-incorrect-arguments-to-mysql-stmt-execute he statet with the mysql client version 50095 he has a problem in the prepare statement to have more than one parameters. I hvae the version 50096. So that could be a similar error in mysql ? – user3807924 Jul 06 '14 at 19:38
0

Check whether the member table exists and whether it has an id, a password and an address field. If so, then try to run your query directly. See if it fails and what is the error. Also, check whether your connection to the database is valid.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
  • Then you might have a problem with the connection. Can you check your connection? – Lajos Arpad Jul 05 '14 at 16:35
  • It works also when I modify the select and only have one line instead of 2 – user3807924 Jul 05 '14 at 16:57
  • @user3807924 Can you check whether your connection used in your PHP project to your database is correct? Yes or no? – Lajos Arpad Jul 06 '14 at 00:39
  • The connection works, all other select inside the code works, only that prepared statement ? THe point is that is has worked before. – user3807924 Jul 06 '14 at 07:35
  • Let's think about the last time it worked and the first time it didn't work. What happened between the two? – Lajos Arpad Jul 06 '14 at 07:51
  • It was from the evening 03.07.2014 to the morning 04.07.2014 and I have definately nothing changed. It is an intranet for some schools and the pupils are not able to enter the system. – user3807924 Jul 06 '14 at 09:41
  • Do you have a backup from 02.07.2014? Can you try the query with that one? – Lajos Arpad Jul 06 '14 at 10:18
  • Yes, I have tried this. Updateted the member database from an old version. With the same result. It seems, that my host has changed the php version ?? Could that occure in such a result. Normally I run with pht 5.2. – user3807924 Jul 06 '14 at 14:37