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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:31:00+00:00 2026-05-22T22:31:00+00:00

I am making a dynamic web page that allows people to post their favorite

  • 0

I am making a dynamic web page that allows people to post their favorite recipes. Below each recipe is a link that allows you to make a comment on the recipe. If you make a comment, the comment will be posted in the database UNLESS the comment has any apostrophes in it. Here’s the code for the addcomment.inc.php page:

<?php


$con = mysql_connect("localhost", "test", "test") or die('Sorry, could not connect to database server');
mysql_select_db("recipe", $con) or die('Sorry, could not connect to database');
$recipeid = $_GET['id'];
$query = "select title from recipes where recipeid = $recipeid";
$result = mysql_query($query) or die('Could not retrieve file: ' . mysql_error());

echo "<form action=\"index.php\" method=\"post\">\n";

if (mysql_num_rows($result) == 0) { 
    $title = "Unknown Title";

} 
else { 
    while($row=mysql_fetch_array($result, MYSQL_ASSOC)) { 
    $title = $row['title']; 
    }
}   

echo "<h2>Enter your comment for the recipe \"$title.\" </h2>";

echo "<textarea rows=\"10\" cols=\"50\" name=\"comment\"></textarea><br>\n";

echo "Submitted by:<input type=\"text\" name=\"poster\"><br>\n";

echo "<input type=\"hidden\" name=\"recipeid\" value=\"$recipeid\">\n";

echo "<input type=\"hidden\" name=\"content\" value=\"addcomment\">\n";

echo "<br><input type=\"submit\" value=\"Submit\">\n";

echo "</form>\n";

?>

A different php file called addcomment.inc.php retrieves the information. This is the code below:

<?php

$recipeid = $_POST['recipeid'];

$poster = $_POST['poster'];

$comment = htmlspecialchars($_POST['comment']);

$date = date("Y-m-d");

$con = mysql_connect("localhost", "test", "test") or die('Could not connect to server');

mysql_select_db("recipe", $con) or die('Could not connect to database');

$query = "INSERT INTO comments (recipeid, poster, date, comment) " .

" VALUES ($recipeid, '$poster', '$date', '$comment')";

$result = mysql_query($query) or die('Could not query databse. ' . mysql_error());

if ($result)

echo "<h2>Comment posted</h2>\n";

else

echo "<h2>Sorry, there was a problem posting your comment</h2>\n";

echo "<a href=\"index.php?content=showrecipe&id=$recipeid\">Return to recipe</a>\n";

?>

How can I make this code properly handle single quotes if inputted into a comment form?

  • 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-22T22:31:01+00:00Added an answer on May 22, 2026 at 10:31 pm

    Before you glue anything into the MySql query pass it through mysql_real_escape_string()

    Before you glue anything into HTML pass it through htmlspecialchars()

    This way you can prevent SQL injections, JavaScript/HTML injections and wildfires.

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

Sidebar

Related Questions

Theres a web page I'm making which content is very dynamic and so I'm
I'm making a webpage with dynamic content that enters the view with AJAX polling.
A partner of ours is making a call to a web service that includes
I'm making a web application with Grails. I've got a list with data that
I am making a dynamic form using table. My table was like below. <table
I'm planning on making some dynamic PHP websites and I need a free Authentication
I'm totally familiar in making static and dynamic websites. However, I have never dealt
Did you used Dynamic websites before? you see its a good way for making
Making echo of a question around the web: Is the syntax for svn:ignore patterns
Making an adobe flex ui in which data that is calculated must use proprietary

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.