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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:30:47+00:00 2026-06-09T20:30:47+00:00

I need to temporarily store the value in a PHP variable because the value

  • 0

I need to temporarily store the value in a PHP variable because the value should be sent together with a comment. A user cannot send a rating without entering a comment, that’s why I decided to make this.

Why is that when PHP calculates the value my variable returns a value of zero?

I have this code:

<a href='#' onclick='rate(1); return false;' class='one-star'>1</a>

<script type="text/javascript">
     function rate (amnt){
     <?php
         $currentRating = amnt;
         $ratingImageWidth = $currentRating * 25;
         echo "alert($ratingImageWidth)";
     ?>
     }
</script>

Note:

  • It outputs an alert with 0;
  • $currentRating variable is not null, I tried to include it in the alert function, and it returns the right value.
  • I tried these to convert the $currentRating variable to an int:

  • settype($currentRating, "integer");
  • (int)$currentRating;

    Nothing happened, it still returns Zero. does anyone know how to solve this? Big thanks to those who will help.

    • 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-09T20:30:48+00:00Added an answer on June 9, 2026 at 8:30 pm

      PHP runs on the server, so your JavaScript actually looks like:

      function rate(amnt) {
          alert(0)
      

      It’s surprising that it works at all given the missing } at the end…

      The point is, you can’t mix PHP and JS in this way. Why don’t you just do alert(amnt*25)?

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

    Sidebar

    Related Questions

    I need a way to store a value somewhere for temporarily by say Process
    I need something like a temporary in-memory key-value store. I know there are solutions
    I need to temporarily store my macro's settings for each worksheet. I thought about
    I only want to remove a value.. I don't need to use the variable
    Traditionally, we try to avoid LazyInitializationException s. However, I need to temporarily allow them
    I need to setup temporary User models for each visitors, where the visitors are
    Need a map reduce function by mongo in php This my mongo structure [_id]
    So I am looking for a way to temporarily store values so they can
    I need to change the value of an XML attribute stored in a column
    I need to store the result set of a stored procedure in a temporary

    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.