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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:42:28+00:00 2026-05-28T04:42:28+00:00

How would I do that? According to PHP.net, $a = hi; $hi = 2;

  • 0

How would I do that?

According to PHP.net,

$a = "hi";
$hi = 2;
$$a; // returns 2

However, I need:

$i = 2;
$_POST['link$i'];  // I need this to return the same thing as $_POST['link2']

Here is how I have my code.

      for ($i = 1; $i <= 40; $i++)
      {
        if(!empty($link$i))
        {
        $link$i = mysql_real_escape_string($_POST['link$i']);
        mysql_query("
          INSERT INTO links (link, rimageid) VALUES
          ('".$link$i."', '".$id."') ");
        } else { }
      }

The reason I’m doing this is because I have a lot of text input fields posting their values to this file, and I’d like to define and insert each of their values via a for loop instead of manually inserting each single link into mysql.

Right now, I get:

Parse error: syntax error, unexpected T_VARIABLE, expecting ')' in C:\xampp\htdocs\new2.php on line 22

How would I go about doing this?
Thanks!

  • 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-28T04:42:29+00:00Added an answer on May 28, 2026 at 4:42 am

    For array index concatenation, ok, but this code

    for ($i = 1; $i <= 40; $i++)
          {
            if(!empty($link$i))
            {
            $link$i = mysql_real_escape_string($_POST['link$i']);
            mysql_query("
              INSERT INTO links (link, rimageid) VALUES
              ('".$link$i."', '".$id."') ");
            } else { }
          }
    

    won’t work as you expect, i.e. name a variable like the result it’s not necessary, why would you want to do that? PHP doesn’t care about the variable name and if it’s coordinated with the result.

    Just do:

    for ($i = 1; $i <= 40; $i++)
          {
          if(!empty($_POST['link'.$i]))
          {
            $regular_variable_name = mysql_real_escape_string($_POST['link'.$i]);
            mysql_query("INSERT INTO links (link, rimageid) VALUES ('".$regular_variable_name."', '".$id."') ");
            } else { }
          }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write the code that would format the value according to the
It would seem that this would be a simple thing to do, but I
**EDIT: There are several options below that would work. Please vote/comment according to your
I've decided to use this.variableName when referring to string/int etc.. fields. Would that include
According to: http://www.php.net/manual/en/function.filectime.php In most Unix filesystems, a file is considered changed when its
According to the PHP Documentation PDO::prepare() adds quotes to all your parameters so that
I need to develop this kind of application, i'm using php and mysql first
I'm working on a PHP application. I need to validate that a string is
Something that would really reload the page or resource, ignoring whatever might be in
I would prefer that a console app would default to multithreaded debug. warning level

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.