Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8266299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:06:36+00:00 2026-06-08T05:06:36+00:00

My same script works on another page, and the other queries on the same

  • 0

My same script works on another page, and the other queries on the same page are using the same connection string. For some reason when I run the ‘filled’ condition it says my connection string is null. “mysql_query() expects parameter 2 to be resource, null given in…” Yet if I run the ‘filled2’ condition it executes just fine. Can anyone see what I don’t?

if (isset($_POST['filled'])) {

    function updateRecords($varA,$varB,$varC){
        $updateMyTable = "UPDATE myTable SET colA='$varA', colB=$varB WHERE colC = $varC";
        if (!mysql_query($updateMyTable,$con)) {
            die('Error 1: '. mysql_error());
        } 
    }

    if ( isset( $_POST['inputArray'] ) ) {
        foreach ( $_POST['inputArray'] as $lilVars ) {
            updateRecords($lilVars['inputA'],$lilVars['inputB'],$lilVars['inputC']);
        }
    } 

} elseif (isset($_POST['filled2'])) {

    $sqlAddRecord="INSERT INTO myTable (ColX, ColY, ColZ2) VALUES ($VarX,'$VarY',$VarZ)";
    if (!mysql_query($sqlAddRecord,$con)) {
      die('Error 2: '.mysql_error());
    }

    echo "New Record Added";

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T05:06:38+00:00Added an answer on June 8, 2026 at 5:06 am

    it is because you are using $con inside of a function. You would need to include “global $con” inside your function definition to make it available to the function from the global scope.

    function updateRecords(...) {
        global $con;
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to run multiple instances of the same script in AutoIt which requires
The upload script in this page is currently uploading the images to the same
The code below works on one page, but not another page (the place it
I have roughly 12 computers that each have the same script on them. This
This one boggles my mind. I've used this same script (different targets of course)
I want to use the same ant script to do a build in either
I'm working with a script that is calling the same class twice and throwing
I have prepared a r script and trying to apply the same codes in
How do I have a PowerShell script embedded within the same file as a
I trying to write a PowerShell script (learning at the same time). I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.