-1

i have this error:

Parse error: syntax error, unexpected '', 0);'' (T_CONSTANT_ENCAPSED_STRING) on line 18 (my first INSERT)

but i cant find the prob... can you help?

<?php


$link = mysql_connect('localhost', 'user', '');
if (!$link) {
    die('Connexion impossible : ' . mysql_error());
}
$db_selected = mysql_select_db('woe_site', $link);
if (!$db_selected) {
   die ('Impossible de sélectionner la base de données : ' . mysql_error());
}

$query1 = 'SELECT account FROM vote_voteurs WHERE account NOT IN (SELECT account FROM boutique_clients);';

$result1 = mysql_query($query1, $link);

while ($row1 = mysql_fetch_assoc($result1)) {
    $query2 = 'INSERT INTO boutique_clients (account, credit, date_ouverture, last_achat, nb_achats) VALUES ('.$row1['account'].', 0, NOW(), '', 0);';
    mysql_query($query2, $link);
}

$query3 = 'SELECT account FROM vote_voteurs';
$resul3 = mysql_query($query3 , $link);
while ($row3 = mysql_fetch_assoc($result3)) {
    $query4 = 'UPDATE boutique_clients SET credit = credit+ (SELECT (totalVotes+monthVotes) *0.0025 FROM vote_voteurs WHERE account='.$row3['account'].') WHERE account = '.$row3['account'].';';
    mysql_query($query4, $link);
}

mysql_close($link);
Lino
  • 19,604
  • 6
  • 47
  • 65
Laurent
  • 1
  • 2
  • $query2 = 'INSERT INTO boutique_clients (account, credit, date_ouverture, last_achat, nb_achats) VALUES (".$row1['account'].", 0, NOW(), "", 0)'; – Krishna Gupta Dec 08 '15 at 07:21

7 Answers7

1

based on the code you gave

on line 18 change:

$query2 = 'INSERT INTO boutique_clients (account, credit, date_ouverture, last_achat, nb_achats) VALUES ('.$row1['account'].', 0, NOW(), '', 0);';

to

$query2 = 'INSERT INTO boutique_clients (account, credit, date_ouverture, last_achat, nb_achats) VALUES ('.$row1['account'].', 0, NOW(), "", 0);';

change the single quotes to double qoutes

roullie
  • 2,830
  • 16
  • 26
1

Have a look at line 18. You have unescaped single quotes in your string literal.

Try with this one:

$query2 = "INSERT INTO boutique_clients (account, credit, date_ouverture, last_achat, nb_achats) VALUES ('".$row1['account']."', 0, NOW(), '', 0);";
Lino
  • 19,604
  • 6
  • 47
  • 65
1

change this line

$query2 = 'INSERT INTO boutique_clients (account, credit, date_ouverture, last_achat, nb_achats) VALUES ('.$row1['account'].', 0, NOW(), '', 0);';

to

 $query2 = 'INSERT INTO boutique_clients (account, credit, date_ouverture, last_achat, nb_achats) VALUES ('.$row1['account'].', 0, NOW(), "", 0);';

you can use this link to see how to work with quotes

MR.masoud
  • 137
  • 11
0

Update your insert query as like :

$query2 = "INSERT INTO boutique_clients (account, credit, date_ouverture, last_achat, nb_achats) VALUES ('$row1["account"]', 0, NOW(), '', 0)";
Krishna Gupta
  • 695
  • 4
  • 15
0

There are 3 possibilities to solve it:

Change

$query2 = 'INSERT INTO boutique_clients (account, credit, date_ouverture, last_achat, nb_achats) VALUES ('.$row1['account'].', 0, NOW(), '', 0);';

to

$query2 = 'INSERT INTO boutique_clients (account, credit, date_ouverture, last_achat, nb_achats) VALUES ('.$row1['account'].', 0, NOW(), \'\', 0);';

or

$query2 = 'INSERT INTO boutique_clients (account, credit, date_ouverture, last_achat, nb_achats) VALUES ('.$row1['account'].', 0, NOW(), "", 0);';

or

$query2 = "INSERT INTO boutique_clients (account, credit, date_ouverture, last_achat, nb_achats) VALUES (".$row1['account'].", 0, NOW(), '', 0);";
mario.van.zadel
  • 2,919
  • 14
  • 23
0

'', 0 should be "", 0.

You are using single quotes inside another single quotes which is breaking the string.

Ashish Choudhary
  • 2,004
  • 1
  • 18
  • 26
0
On line 18 you you have inclose sql query by single inverted coma, in same line during insert value you use again single inverted coma sot that inside value single inverted coma break you line. so
either
 $query2 = 'INSERT INTO boutique_clients (account, credit, date_ouverture, last_achat, nb_achats) VALUES ('.$row1['account'].', 0, NOW(), "", 0);';
    mysql_query($query2, $link);
Or
 $query2 = "INSERT INTO boutique_clients (account, credit, date_ouverture, last_achat, nb_achats) VALUES ('.$row1['account'].', 0, NOW(), '', 0);";
    mysql_query($query2, $link);