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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:42:14+00:00 2026-05-31T07:42:14+00:00

I currently have this: <?php $con = mysql_connect(‘localhost’, ‘root’, ‘dev’); if(!$con) { die(‘Could not

  • 0

I currently have this:

<?php
  $con = mysql_connect('localhost', 'root', 'dev');
  if(!$con) {
    die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("myDB");
  $query = "SELECT * FROM pages where id=1";
  $result = mysql_query($query);
  $row = mysql_fetch_assoc($result);
  $contents = $row['content'];
  echo $contents;
?>

See this part: SELECT * FROM pages where id=1

1 is the record id and it’s currently hardcoded. What I need to do is change it so it get’s the record id from the url…for example: mysite.com/index.php?2 would show record id 2 …

How do I go about doing this?

  • 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-31T07:42:16+00:00Added an answer on May 31, 2026 at 7:42 am

    Turn that hardcoded value into a variable.

    <?php
        //assumes you have a querystring like: http://mysite.com/index.php?id=3
        $id = $_GET['id'];
    
    
      $con = mysql_connect('localhost', 'root', 'dev');
      if(!$con) {
        die('Could not connect: ' . mysql_error());
      }
      mysql_select_db("myDB");
    
    
        //Make your variable safe for use with mysql
        $id = mysql_real_escape_string($id);
      $query = "SELECT * FROM pages where id=" . $id;
      $result = mysql_query($query);
      $row = mysql_fetch_assoc($result);
      $contents = $row['content'];
      echo $contents;
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have my PHP class variables set up like this: class someThing {
I do not currently have this issue , but you never know, and thought
Hello I currently have this PHP Script <?php if($purchase_dates != FALSE){?> <?php foreach($purchase_dates as
I am working on a Symfony project and I currently have this: <?php echo
currently I have this client code in my PHP MVC web app: try {
I have some trouble matching the contents inside php tags. Currently I have this
I currently have this piece of code: NSString *strURL = [NSString stringWithFormat:@http://www.sample.com /phpFile.php?firstname=%@,txtfirstName.text]; NSString
I currently have this array in layout.php <?php $arrLayout = array( section1 => array(
I currently have this in .htaccess: Options +FollowSymlinks RewriteEngine on RewriteRule ^page/(.*)/(.*)$ /type1/internal.php?parentFolders=$1&pageTitleID=$2 [L]
I currently have a page setup like this: PHP Variable Declarations HTML header, then

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.