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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:03:20+00:00 2026-05-22T01:03:20+00:00

I have an html form with 4 items. title and content are required. link

  • 0

I have an html form with 4 items.

title and content are required.

link and image are optional.

So this is what i wrote, but i cannot insert the data in my data base.
Is there a mistake in my condition statement for url and image? Thanks

if($_SERVER['REQUEST_METHOD'] == "POST") {

$ttt = strlen(htmlspecialchars(trim($_POST['title'])));
$ccc = strlen(htmlspecialchars(trim($_POST['content']))); // count title and content charters

$title = htmlspecialchars(trim($_POST['title']));
$content = htmlspecialchars(trim($_POST['content']));
$url = htmlspecialchars(trim($_POST['url']));
$image = htmlspecialchars(trim($_POST['image']));


if($url!=''){
    if ( !preg_match( '|^(ht|f)tp(s?))://|', $url ){
        echo "wrong";
        mysql_close($db);
    }
} // if $url is not empty, judge is it began as a http:// ? else close the db link 

if($image!=''){
    if ( !getimagesize($image)){
        echo "wrong";
        mysql_close($db);
    }
} // if $image is not empty, use getimagesize judge is it a real image? else close the db link

if(($ttt > 2 && $ttt < 201) && ($ccc > 29 && $ccc < 1001)) {
$sql= "INSERT INTO msg (title, content,image,link) VALUES ('".$title."','".$content."', '".$image."', '".$url."')";//if title charters between 3-200 and content charters between 30-1000, do insert into thing

if(mysql_query($sql))
{
  echo "insert done"; 
}else{
  echo "insert wrong";
}

}else{
  echo "your title or content is out of the words limit";
}


}

mysql_close($db);
  • 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-22T01:03:21+00:00Added an answer on May 22, 2026 at 1:03 am

    Change:

    if($link!=''){
        if ( !preg_match( '|^(ht|f)tp(s?))://|', $url ){
            echo "wrong";
            mysql_close($db);
        }
    }
    

    to

    if($url !=''){
        if ( !preg_match( '|^(ht|f)tp(s?))://|', $url ){
            echo "wrong";
            mysql_close($db);
        }
    } 
    

    for us to be able to help yuou better show your $sql statement;

    UPDATE:

    It’s very hard to figure the problem like that here is what you can do, to see what is the problem:

    $result = mysql_query($sql) or die (‘Error: ‘mysql_error());

    This way you can see what is the error in your query, i a pretty sure it is an escaping problem so here is what you can add;

    $title = htmlspecialchars(trim($_POST['title']));
    $content = htmlspecialchars(trim($_POST['content']));
    $url = htmlspecialchars(trim($_POST['url']));
    $image = htmlspecialchars(trim($_POST['image']));
    
    
    $title = mysql_real_escape_string($title);
    $content = mysql_real_escape_string($content);
    $url = mysql_real_escape_string($url);
    $image = mysql_real_escape_string($image);
    

    this way if there are any special characters they will be escaped

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

Sidebar

Related Questions

I have a html form with the data by this post method 'form id='form1'
I have an HTML form - with PHP, I am sending the data of
I have a HTML form, and I have a Controller Action that accepts the
I have an HTML form generated by JSF which maps an input element to
I have a html form for uploading a file, which is as follows: $uploadhtml
I have a HTML form containing checkboxes in the form of .. <input type=checkbox
I have an HTML form where the user can type in any number:5, 8,
I have a html form which have a select list box from which you
I have an HTML form where I am going to copy values from a
I have an html form. I need to send its data to flash on

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.