Hi I have some problem with a php file i´me trying to use as a cron job. When i execute the php file (through browser) it runs perfectly, but nothing happens in the DB.... (a few hours ago, i inserted the mysql_error to try to find out the problem, but still can´t understand it.... This is the code.... (username, password, and table info "hidden") <?php error_reporting(E_ALL); $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("account_table", $con) or die(mysql_error()); echo "connected"; mysql_query("UPDATE phcdl_users SET user_uploads = (SELECT COUNT(file_id) FROM phcdl_files WHERE phcdl_files.file_author = phcdl_users.user_name GROUP BY user_id"); echo "<br/>1# done"; mysql_query("UPDATE phcdl_users SET total_downs = (SELECT SUM(file_downloads) FROM phcdl_files WHERE phcdl_users.user_uploads > '0' AND phcdl_files.file_author = phcdl_users.user_name GROUP BY user_id");echo "<br/>2# done"; mysql_query("UPDATE phcdl_users SET total_cmmnts = (SELECT SUM(file_total_comments) FROM phcdl_files WHERE phcdl_users.user_uploads > '0' AND phcdl_files.file_author = phcdl_users.user_name GROUP BY user_id");echo "<br/>3# done"; mysql_query("UPDATE phcdl_users SET total_views = (SELECT SUM(file_fiews) FROM phcdl_files WHERE phcdl_users.user_uploads > '0' AND phcdl_files.file_author = phcdl_users.user_name GROUP BY user_id") ;echo "<br/>4# done"; mysql_query("UPDATE phcdl_users SET total_votes = (SELECT SUM(file_votes) FROM phcdl_files WHERE phcdl_users.user_uploads > '0' AND phcdl_files.file_author = phcdl_users.user_name GROUP BY user_id");echo "<br/>5# done"; echo mysql_errno($con) . ": " . mysql_error($con) . "\n"; mysql_close($con); ?> Code (php): Which output this : connected 1# done 2# done 3# done 4# done 5# done 1064: 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 '' at line 1 Code (markup): All the SQL commands run without any problem on PhpMyAdmin. if anyone can help me with the problem here i´d appreciate a lot
use mysql_error as below, so you will get which query is causing the error. if(!mysql_query($query)) { echo mysql_error(); }
Try to use numbers without inverted commas (phcdl_users.user_uploads > '0'), like (phcdl_users.user_uploads > 0) if it is integer and you send it like a string that can cause a problem.
Thanks, I´ve tried that but i still get an error related to the 1st line..... connected 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 '' at line 1 Code (markup): <?php $con = mysql_connect('localhost','account','password'); mysql_select_db("table", $con); echo "connected<br/>"; $q1 = "UPDATE phcdl_users SET user_uploads = (SELECT COUNT(file_id) FROM phcdl_files WHERE phcdl_files.file_author = phcdl_users.user_name GROUP BY user_id"; if(!mysql_query($q1)) { echo mysql_error(); } mysql_close($con); ?> Code (PHP): I´ve just used one query now to try to fix the problem with a smaller code.... (all the queries are based on the first one, so if the error is on the query the 1st one is enough xD) I also removed the commas like you said, digiklan (before trying the code above) but got the same error....
i think it´s working fine now, thank you (don´t know how i missed it xD because i´ve tried to put the bracket, but guess i were trying at the wrong place xD)