Poet Posted February 7, 2021 Share Posted February 7, 2021 (edited) I've followed every piece of advice (quotes, no quotes, $...) and nothing works. Here is the snippet of code that's generating the error. This woks fine in PHP 5, but I have to upgrade to 7. Warning if for line 71, which corresponds to where query3 starts. if($numRows == 0) { $query3 = "INSERT INTO comments (article_id, status, date_posted, feedback, visName, visEmail, notify) VALUES ('".$_POST[article_id]."', '0', NOW(), '$visFdbk', '$nameOfVis', '$emailOfVis', 'y');"; }else{ $query4 = "INSERT INTO comments (article_id, status, date_posted, feedback, visName, visEmail, notify) VALUES ('".$_POST[article_id]."', '0', NOW(), '$visFdbk', '$nameOfVis', '$emailOfVis', '');"; } } Earlier in code, I define this: $numRows = mysql_num_rows($r); Thanks in advance for any help you can lend. Edited February 7, 2021 by Poet Quote Link to comment https://forums.phpfreaks.com/topic/312106-cannot-resolve-warning-use-of-undefined-constant/ Share on other sites More sharing options...
benanamen Posted February 7, 2021 Share Posted February 7, 2021 (edited) You need to use Prepared Statements and your problem will be solved. NEVER EVER put variables in your query and NEVER EVER trust user supplied data. But as to why the problem, there are no quotes in your $_POST values. You have $_POST[article_id] instead of $_POST['article_id'] Edited February 7, 2021 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/312106-cannot-resolve-warning-use-of-undefined-constant/#findComment-1584294 Share on other sites More sharing options...
Barand Posted February 7, 2021 Share Posted February 7, 2021 4 hours ago, Poet said: Earlier in code, I define this: $numRows = mysql_num_rows($r); The "mysql_*" functions were deprecated a decade ago and have been removed from PHP 7. You need to use mysqli or PDO (better). Quote Link to comment https://forums.phpfreaks.com/topic/312106-cannot-resolve-warning-use-of-undefined-constant/#findComment-1584300 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.