jacquesvds Posted February 22, 2021 Share Posted February 22, 2021 $sqlresdays="SELECT DATEDIFF(CURDATE(),MAKEDATE(YEAR(CURDATE()),1)) AS date_difference"; $resdays=mysqli_query($donnees,$sqlresdays); $daysinyr=mysqli_fetch_object($resdays); $divider = $daysinyr->date_difference; When running the sql request raw, no problem, date_difference shows the right number but in the script nothing is echo'd. Thanks for clues on how to resolve this. Quote Link to comment https://forums.phpfreaks.com/topic/312194-a-mysql-function-does-not-produce-an-exploitable-value-in-a-php-script/ Share on other sites More sharing options...
gw1500se Posted February 22, 2021 Share Posted February 22, 2021 First please us the code icon (<>) in the top menu and specify PHP for your code. If what you posted is your script then nothing is echoed because you are not echoing anything. Post all the relevant code. Quote Link to comment https://forums.phpfreaks.com/topic/312194-a-mysql-function-does-not-produce-an-exploitable-value-in-a-php-script/#findComment-1584689 Share on other sites More sharing options...
jacquesvds Posted February 22, 2021 Author Share Posted February 22, 2021 2 minutes ago, gw1500se said: First please us the code icon (<>) in the top menu and specify PHP for your code. If what you posted is your script then nothing is echoed because you are not echoing anything. Post all the relevant code. $sqlresdays="SELECT DATEDIFF(CURDATE(),MAKEDATE(YEAR(CURDATE()),1)) AS date_difference"; $resdays=mysqli_query($donnees,$sqlresdays); $daysinyr=mysqli_fetch_object($resdays); $divider = $daysinyr->date_difference; echo $divider; $finalpop=intval($pop/$divider); The above is the complete code. I actually try to divide the $pop (containing a big number) by the number of days in the actual calendar year. Quote Link to comment https://forums.phpfreaks.com/topic/312194-a-mysql-function-does-not-produce-an-exploitable-value-in-a-php-script/#findComment-1584690 Share on other sites More sharing options...
gw1500se Posted February 22, 2021 Share Posted February 22, 2021 (edited) $sqlresdays="SELECT DATEDIFF(CURDATE(),MAKEDATE(YEAR(CURDATE()),1)) AS date_difference"; $resdays=mysqli_query($donnees,$sqlresdays) or trigger)_error("Query failed: ".mysqli_error($donnees); if ($resdays->num_rows>0) { $daysinyr=mysqli_fetch_object($resdays); $divider = $daysinyr->date_difference; echo $divider; $finalpop=intval($pop/$divider); } else { echo "No resullts returned from query"); } Edited February 22, 2021 by gw1500se Quote Link to comment https://forums.phpfreaks.com/topic/312194-a-mysql-function-does-not-produce-an-exploitable-value-in-a-php-script/#findComment-1584691 Share on other sites More sharing options...
Barand Posted February 22, 2021 Share Posted February 22, 2021 Alternatively $pop = 54321; $res = $pdo->prepare("SELECT ROUND( ? / DAYOFYEAR(CURDATE()))"); $res->execute([$pop]); echo $res->fetchColumn(); //--> 1025 or (no database required)... echo round($pop / (date('z')+1)); //--> 1025 Quote Link to comment https://forums.phpfreaks.com/topic/312194-a-mysql-function-does-not-produce-an-exploitable-value-in-a-php-script/#findComment-1584692 Share on other sites More sharing options...
jacquesvds Posted February 22, 2021 Author Share Posted February 22, 2021 52 minutes ago, gw1500se said: $sqlresdays="SELECT DATEDIFF(CURDATE(),MAKEDATE(YEAR(CURDATE()),1)) AS date_difference"; $resdays=mysqli_query($donnees,$sqlresdays) or trigger)_error("Query failed: ".mysqli_error($donnees); $daysinyr=mysqli_fetch_object($resdays); $divider = $daysinyr->date_difference; echo $divider; $finalpop=intval($pop/$divider); Quote Link to comment https://forums.phpfreaks.com/topic/312194-a-mysql-function-does-not-produce-an-exploitable-value-in-a-php-script/#findComment-1584693 Share on other sites More sharing options...
jacquesvds Posted February 22, 2021 Author Share Posted February 22, 2021 Thank you very much Barand. I run on PHP 5,6 in procedural style and I do not know whether I can mix your proposed PDO in my script. $resdays=mysqli_query($donnees,$sqlresdays) or trigger)_error("Query failed: ".mysqli_error($donnees); appears to be faulty ... Thank you for trying Quote Link to comment https://forums.phpfreaks.com/topic/312194-a-mysql-function-does-not-produce-an-exploitable-value-in-a-php-script/#findComment-1584694 Share on other sites More sharing options...
Barand Posted February 22, 2021 Share Posted February 22, 2021 The main point is the query. Use DAYOFYEAR to get the number of days from start of year, it's easier and doesn't produce a zero value. (and you can use that same query just as well with MySqli) Yours will fail (div by 0) if you run it on the 1st Jan. Also note the use of SQL is overkill when you can do what you want with a simple one liner in PHP. Quote Link to comment https://forums.phpfreaks.com/topic/312194-a-mysql-function-does-not-produce-an-exploitable-value-in-a-php-script/#findComment-1584695 Share on other sites More sharing options...
jacquesvds Posted February 23, 2021 Author Share Posted February 23, 2021 The query works very well on its own but the script returns a no result... Quote Link to comment https://forums.phpfreaks.com/topic/312194-a-mysql-function-does-not-produce-an-exploitable-value-in-a-php-script/#findComment-1584711 Share on other sites More sharing options...
Barand Posted February 23, 2021 Share Posted February 23, 2021 Do you charge per line of code, or are you of the school of programming that thinks "Why use one line of code when you can do it with several?" Anyway, here's a mysqli version $pop = 54321; $result = $donnees->query("SELECT DAYOFYEAR(CURDATE()) as dayno"); $row = $result->fetch_assoc(); echo round($pop / $row['dayno']); //--> 1006 Quote Link to comment https://forums.phpfreaks.com/topic/312194-a-mysql-function-does-not-produce-an-exploitable-value-in-a-php-script/#findComment-1584712 Share on other sites More sharing options...
jacquesvds Posted February 23, 2021 Author Share Posted February 23, 2021 Thank you. I applied your code and got INF as a result of echo round($pop / $row['dayno']); ? This is real weird. Sorry for the code writing.. I am just an autodidact amateur trying to assist an NGO in running their app . Further, I do not charge anything for this volunteer work. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/312194-a-mysql-function-does-not-produce-an-exploitable-value-in-a-php-script/#findComment-1584713 Share on other sites More sharing options...
Barand Posted February 23, 2021 Share Posted February 23, 2021 (edited) 42 minutes ago, jacquesvds said: I applied your code and got INF as a result Show your current code that gives that result. Why do you insist on usng SQL for this? Edited February 23, 2021 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/312194-a-mysql-function-does-not-produce-an-exploitable-value-in-a-php-script/#findComment-1584714 Share on other sites More sharing options...
jacquesvds Posted February 23, 2021 Author Share Posted February 23, 2021 Here is the code: $result = mysqli_query($donnees,"SELECT DAYOFYEAR(CURDATE()) as dayno"); $row = mysqli_fetch_assoc($result); echo round($pop / $row['dayno']); I use sql as I do not know any other way to program this. The whole app is written in PHP 5,8 and databases are mysql. Quote Link to comment https://forums.phpfreaks.com/topic/312194-a-mysql-function-does-not-produce-an-exploitable-value-in-a-php-script/#findComment-1584722 Share on other sites More sharing options...
Barand Posted February 23, 2021 Share Posted February 23, 2021 57 minutes ago, jacquesvds said: I use sql as I do not know any other way to program this I gave you a one line PHP solution in my first post Your code works for me. It could be a conection problem. Check for mysql errors using mysqli_report() (EG this is my mysqli connection code)... mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $db = mysqli_connect(HOST,USERNAME,PASSWORD,$database); $db->set_charset('utf8'); Quote Link to comment https://forums.phpfreaks.com/topic/312194-a-mysql-function-does-not-produce-an-exploitable-value-in-a-php-script/#findComment-1584723 Share on other sites More sharing options...
jacquesvds Posted February 24, 2021 Author Share Posted February 24, 2021 You are right, it was a connection problem. Sorry for the trouble and thank you for simplifying the code . I learned something. Quote Link to comment https://forums.phpfreaks.com/topic/312194-a-mysql-function-does-not-produce-an-exploitable-value-in-a-php-script/#findComment-1584751 Share on other sites More sharing options...
Barand Posted February 24, 2021 Share Posted February 24, 2021 15 minutes ago, jacquesvds said: I learned something. It certainly wasn't how to read replies and take advice 🙂 , so again, in case you missed it, here's the 1 line solution with no SQL required echo round($pop / (date('z')+1)); Quote Link to comment https://forums.phpfreaks.com/topic/312194-a-mysql-function-does-not-produce-an-exploitable-value-in-a-php-script/#findComment-1584754 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.