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

  • SEARCH
  • Home
  • 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 8407485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:22:39+00:00 2026-06-09T23:22:39+00:00

I’m trying to display a PHP variable using javascript/jquery but it’s displaying ‘null’. if(mysql_num_rows($checkBan)

  • 0

I’m trying to display a PHP variable using javascript/jquery but it’s displaying ‘null’.

if(mysql_num_rows($checkBan) > 0){
            $bannedDate = $checkBan['banLength'];
            if(preg_match('/[0-9]/',$bannedDate)){      
                list($yyyy,$mm,$dd) = explode('-',$bannedDate);
                 $date = $mm."-".$dd."-".$yyyy;
            }

            //$date = "test"; when this is uncommented it appears in the alert so I know the json_encode is working fine

            ?>
            <script type ="text/javascript">
               var bannedUntil= <?php echo json_encode($date); ?>;
               alert('Your account has been banned until ' + bannedUntil +'. Please contant an administrator if you believe this is an error');
            </script>
            <?

        } 

The alert appears just fine, but the bannedUntil variable is null. However, when the second date variable is uncommented it appears in the alert. It’s not a separate function so I don’t see why the scope would be an issue.

  • 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-09T23:22:41+00:00Added an answer on June 9, 2026 at 11:22 pm

    I am seeing you use $checkBan as a result resource in mysql_num_rows(), then attempt to access an array key from it without fetching. You appear to be missing a call to mysql_fetch_assoc():

    if(mysql_num_rows($checkBan) > 0){
            // Fetch a row from the result resource $checkBan
            $row = mysql_fetch_assoc($checkBan);
            $bannedDate = $row['banLength'];
            // etc...
    }
    

    Another tip: It looks like you are getting a standard MySQL date format back as YYYY-MM-DD and converting it with string operations in PHP to MM-DD-YYYY. Just retrieve it in that format in your query to begin with and avoid the explode() and list() calls in your PHP application code.

    SELECT DATE_FORMAT(banLength, '%m-%d-%Y') FROM yourtable
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I am trying to understand how to use SyndicationItem to display feed which is
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.