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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:52:43+00:00 2026-05-24T03:52:43+00:00

I want to make a 2 field input form to my MySQL database. I

  • 0

I want to make a 2 field input form to my MySQL database. I connect to the database with no problem and even can post if I want, but the form is giving an error. (I’m already connected to the database at this point and I can test that is working)

This is the form:

<form action="insert.php" method="post">
Title: <input type="text" name="title" />
Privacy: <select type="text" name="privacy" />
  <option value="public">Publico</option>
  <option value="private">Privado</option>
</select>
<input type="submit" />
</form>

This is the insert.php file:

<?  
mysql_select_db("copoetry", $con);
$sql="INSERT INTO Poems (Title, Privacy)
VALUES
('$_POST[title]','$_POST[privacy]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";
mysql_close($con)
?>

When I press submit I get this error:

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/content/02/6945202/html/copoetry/insert.php on line 2

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/content/02/6945202/html/copoetry/insert.php on line 7
Error:

What am I doing wrong? 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-24T03:52:44+00:00Added an answer on May 24, 2026 at 3:52 am

    Your $con variable should hold a connection to the database with mysql_connect();, you appear to removed this line at some point.

    EG:

    $con = mysql_connect('host', 'user', 'pass') or die(mysql_error());
    

    Once you have done this successfully all your mysql_* calls will use that connection, so you could get rid of the $con variable anyway.

    ALSO
    Don’t forget to escape your inputs so that are safe, inserting a $_POST, $_GET or $_REQUEST variable straight into mysql is very unsafe. Make at the very least you run mysql_real_escape_string(); on each and every input you get from a form or cookie.

    EG

    // Create a shortcut function somewhere early in your script
    function mes($input) { 
        return mysql_real_escape_string($input);
    }
    
    // SQL Example
    $sql = "INSERT INTO Poems (Title, Privacy) VALUES ('".mes($_POST['title'])."','".mes($_POST['privacy'])."')";
    

    Note the string concatenation (using fullstop) to separate the strings/variables.

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

Sidebar

Related Questions

I want to make an input form in Java so that the user can
I want to make a copy of an ActiveRecord object, changing a single field
I want to make an entity that has an autogenerated primary key, but also
I want to make a .NET Form as a TopMost Form for another external
I want to make sure people can't type the name of a PHP script
Is there a way to limit a form input field to be between certain
So I have an input form that I want to use to update a
I want to enable the input field when check box is checked. Also, I
I'm building an employment application form that's dynamic. I want a field that asks
I have this problem: My web application has a form where the users can

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.