0

Why is it that when I run this script that shifts database values, it gives me errors?

<?php
$connection = mysqli_connect('localhost', 'root', '', 'pointsmanager');
$script="UPDATE points_history 
SET
    7d_before = 6d_before,
    6d_before = 5d_before,
    5d_before = 4d_before,
    4d_before = 3d_before,
    3d_before = 2d_before,
    2d_before = 1d_before,
    1d_before = (
        SELECT 
            today_points
        FROM
            points
        )
"
mysqli_query($connection, $script);

?>

I get

Parse error: syntax error, unexpected 'mysqli_query' (T_STRING) in C:\xampp\htdocs\demo\argon-dashboard-master\CronScript.php on line 18

Thanks!

1 Answers1

1

you forgot semicolon

Your Code :-

 <?php
    $connection = mysqli_connect('localhost', 'root', '', 'pointsmanager');
    $script="UPDATE points_history 
    SET
        7d_before = 6d_before,
        6d_before = 5d_before,
        5d_before = 4d_before,
        4d_before = 3d_before,
        3d_before = 2d_before,
        2d_before = 1d_before,
        1d_before = (
            SELECT 
                today_points
            FROM
                points
            )
    "
    mysqli_query($connection, $script);
    
    ?>

Corrected Code :-

<?php
$connection = mysqli_connect('localhost', 'root', '', 'pointsmanager');
$script="UPDATE points_history 
SET
    7d_before = 6d_before,
    6d_before = 5d_before,
    5d_before = 4d_before,
    4d_before = 3d_before,
    3d_before = 2d_before,
    2d_before = 1d_before,
    1d_before = (
        SELECT 
            today_points
        FROM
            points
        )
";
mysqli_query($connection, $script);

?>

semicolan after declaring $sript = "your query";

Parth B Thakkar
  • 115
  • 2
  • 10
  • 1
    Please don't post answers to questions which are just simple typos. Instead, make a comment and flag the question as "off-topic" due to a non-reproducible or typographical error. Questions like this add no value to the site and will likely eventually be deleted, thus causing you to lose any reputation that you may gain from answering. See [Should one advise on off topic questions?](https://meta.stackoverflow.com/q/276572/1768232) – Nick Sep 13 '20 at 12:15
  • 1
    if the user is new to this site / specific language you should encourage him by giving him proper answers, i know this problem could have been solved by just a comment but i gave answer so he gets helpful and easy answers from the site. marking question as duplicate or flagging the questions demotivates the new user. Old users and experienced programmer won't do this kind of mistakes. hope you got my point @Nick – Parth B Thakkar Sep 14 '20 at 13:11