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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:01:03+00:00 2026-06-12T08:01:03+00:00

This is my php code: //Code for fetching content (view-me.php) <?php include(‘connect.php’); $head_title=$_GET[‘title’]; //echo

  • 0

This is my php code:

//Code for fetching content (view-me.php)
<?php
include('connect.php');
$head_title=$_GET['title'];
//echo $head_title;
$head_title=$mysqli->real_escape_string($head_title);
//echo $head_title;
$query="select title,content,pub_date from news where title='$head_title'";
$result=$mysqli->query($query);
if($result){
    while(list($title,$content,$date)=$result->fetch_row())
    {
        echo '<div id="post_my_head">';
        echo "<h1>".$title."</h1></div><br />";
        echo '<div id="posted_date_time">'.$date.'</div>';
        echo '<div id="post_my_content"><p>'.$content.'</p></div>';

    }


    $mysqli->close();
}
else
    {
        echo "Query failed";
    }

?>

//Code for printing content:(news.php)
function print_content()
{
    include('connect.php');
    $query="select title,content,url,pub_date from news order by pub_date desc";
    $result=$mysqli->query($query);
    while(list($title,$content,$url,$date)=$result->fetch_row())
    {
        echo '<div id="post_my_head">';
        echo "<h1><a href='view-me.php?title=".addslashes($title)."' id='my_post_link'>".$title."</a></h1></div><br />";
        //$new_title=str_replace(" ","-",$title);
        //echo "localhost/".$new_title."/";
        echo '<div id="posted_date_time">Published:'.$date.'</div><br /><br />';
        echo '<div id="post_my_content"><p>'.$content.'</p></div>';
    }
    $mysqli->close();
}
print_content();

It works perfect for most of the queries.It fails when the $head_title has a single or double quotes.I tried using addslashes in news.php but it doesn’t work.

The code fails when the $head_title is something like “America’s Freedom”.In this case $title becomes “America” and the rest of the string gets truncated automatically.So the url becomes something like “localhost/?title=America” instead of “localhost?title=America’s Freedom”.The data type used in mysql is text.The code works perfect for all queries without single or double quotes.

  • 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-12T08:01:04+00:00Added an answer on June 12, 2026 at 8:01 am

    For the URL, URL-encode the value. For putting that encoded URL into HTML, HTML escape it on top:

    printf('<h1><a href="view-me.php?title=%s" id="my_post_link">%s</a></h1>',
           htmlspecialchars(urlencode($title)),
           htmlspecialchars($title));
    

    See The Great Escapism (Or: What You Need To Know To Work With Text Within Text).

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

Sidebar

Related Questions

I got this PHP code: // connect to mysql require_once('includes/connect.php'); // include config include('includes/config.php');
I am using this PHP code: if (isset($_GET['c'])) { $pages = array(home, upload, signup);
This is a code in PHP which is fetching a record from a database:
This is my php code which is only fetching the first image out of
I have this PHP code to highlight the Query on search results. if (isset($_REQUEST['k'])){
I've got this php code to send the users information from the contact form
I found this PHP code in an app I have to modify... $links =
I have this php code $jsonArray = array(); $sql = SELECT ID,CLIENT FROM PLD_SERVERS;
I have this PHP code in a loop for every post on the admin
i have this php code and keep on getting errors upon fixing each error.

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.