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 3605216
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:05:46+00:00 2026-05-18T21:05:46+00:00

Why is this not working? <?php mysqli_select_db($connect,dev); $response = Select response from revbut where

  • 0

Why is this not working?

<?php 

mysqli_select_db($connect,"dev");
$response = "Select response from revbut where session='$u'";
$rquery  =  mysqli_query($connect,$response);

$responseanswer = mysqli_fetch_array($rquery);
$re  = $responseanswer['response'];
?>

<script type="text/javascript">
<?php echo $re; ?>
</script>

$re inside JavaScript is not getting echoed. But if I place it inside the above PHP function, it is getting echoed.

EDIT – BUT THEN WHY IS THIS NOT WORKING?

if(<?php echo $re; ?>){
    document.getElementById('hide').style.display = "none";
}

if I PLACE the hide function outside the if – it is working.

  • 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-05-18T21:05:46+00:00Added an answer on May 18, 2026 at 9:05 pm

    It get’s echoed, but you won’t see anything on your page as the text will be written within the Javascript-tag which is not displayed by the browser. Look at your page source to verify that the text is really there.

    EDIT

    Try

    if(<?php echo json_encode($re); ?>){
        document.getElementById('hide').style.display = "none"; 
    }
    

    This will ensure that your PHP string will be converted into the appropriate Javascript type – in case of strings it’ll ensure that the string is enclosed in " and is escaped properly.

    EDIT again

    When you do the following

    <script type="text/javascript"> 
    if(<?php echo $re; ?>){
        document.getElementById('hide').style.display = "none"; } 
    </script>
    

    this is what is written to the HTML page (that’s then interpreted by the browser)

    <script type="text/javascript"> 
    if(whatever is in the $re vairable){
        document.getElementById('hide').style.display = "none"; } 
    </script>
    

    But this is not even valid Javascript. What you want is

    <script type="text/javascript"> 
    if("whatever is in the $re vairable"){
        document.getElementById('hide').style.display = "none"; } 
    </script>
    

    Note the " which ensures that the whole thing is valid Javascript and that the contents of $re will be interpreted as an Javascript string by the Browser’s Javascript engine. The call to json_encode() does exactly this – it transforms PHP variables into the appropriate Javascript variables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't know if my mind is not working today or if this is
I thought this would be simple, but its not working .. in both the
I've been trying this a couple of different ways, but it's not working for
Sorry for this not being a real question, but Sometime back i remember seeing
Under what circumstances would this or would this not be safe? I have a
Ok, so, my visual studio is broken. I say this NOT prematurely, as it
$(#dvMyDIV).bind(resize, function(){ alert(Resized); }); or $(#dvMyDIV).resize(function(){ alert(Resized); }); The questions Why is this not
This is not a new topic, but I am curious how everyone is handling
This is not exactly a programming question, but it's highly related. We are writing
This is not a technical problem, but very annoying. Does anyone know how to

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.