Why does PHP DATE_ADD() function returns a syntax error

Prog_Rookie

Im trying to populate a table using some other specific tables(there's a set of tables known as table_1,table_2,table_3 etc) in the same database by giving a date interval(to obtain rows which are recorded within a month). below is the code im using

<?php
include("functions.php");
connect();
$table_count = mysql_query("SELECT COUNT(*) AS cnt FROM information_schema.tables WHERE table_schema = 'mydb' AND table_name LIKE 'mytable_%'");



$row = mysql_fetch_assoc($table_count);
$loop_var = ($row["cnt"]);


for ($x=1; $x<=$loop_var; $x++) {


mysql_query("INSERT INTO stats (`useragent_browser`, `useragent_OS`, `timestamp`)
SELECT `useragent_browser`, `useragent_OS`, `timestamp` FROM table_'.$x.'
WHERE `timestamp` > DATE_ADD(NOW(), INTERVAL -1 MONTH)") or die(mysql_error());
}
?>

but at the moment this returns as errror saying

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''.1.' WHERE timestamp > DATE_ADD(NOW(), INTERVAL -1 MONTH)' at line 2

can anybody help on me soughting this out

Manwal

Try this:

mysql_query("INSERT INTO stats (`useragent_browser`, `useragent_OS`, `timestamp`)
SELECT `useragent_browser`, `useragent_OS`, `timestamp` FROM table_$x
WHERE `timestamp` > DATE_ADD(NOW(), INTERVAL -1 MONTH)") or die(mysql_error());
}

or

mysql_query("INSERT INTO stats (`useragent_browser`, `useragent_OS`, `timestamp`)
SELECT `useragent_browser`, `useragent_OS`, `timestamp` FROM table_".$x."
WHERE `timestamp` > DATE_ADD(NOW(), INTERVAL -1 MONTH)") or die(mysql_error());
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why does the php 'date' function returns a wrong time (off by ~24 seconds)?

Why does 00.0 cause a syntax error?

Why does <!-- Not Throw a Syntax Error?

Why does this definition returns a function?

Why does Kotlin need function reference syntax?

Why does a function in bash script throw syntax error as root (using sudo) while as standard user it works?

Why does this IAM policy have a syntax error?

Why does my php mail function give error 500

Why does this function call throws "await is only valid in async function" Syntax Error even though the function is asyn?

Why does MPI_REDUCE returns a syntax error at compile time?

Why does this getter inside a function produce a syntax error?

Why does <!-- return undefined and not a syntax error?

php syntax error while am trying to add foreach inside function

Why does this SQL query give a syntax error?

Function syntax error in PHP

Why does this generator expression raise a syntax error?

Why does this code output a syntax error? (python)

Why does a syntax error occur after restart?

Why does the below code have a syntax error?

Syntax Error: Unexpected Identifier - Higher Order Function that Returns a Function in JavaScript

Why does this php array function gives me an error

Spark dataframe throws error while doing logic for date_add function

Why TypeScript compiler does not give error when function returns undefined while function's return type is number?

DATE_ADD Function

why typescript typing syntax error for filter function

Why PHP function returns TRUE?

Why does Python magic timeit function return a syntax error?

Proper syntax for raising an error that a function returns

Why does my Python always say "Syntax Error" when using the (f" function?