Jump to content

Cannot resolve: Warning: Use of undefined constant


Poet

Recommended Posts

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 by Poet
Link to comment
Share on other sites

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 by benanamen
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.