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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:13:40+00:00 2026-05-25T00:13:40+00:00

Before reading, please note that I am very new to both PHP and MYSQL.

  • 0

Before reading, please note that I am very new to both PHP and MYSQL. I have created a table in my MYSQL database. I would now like to ‘spit out’ this table onto a page through PHP. This part I seem to be okay with. After outputting the tables data into an HTML table, I would like to output an HTML form onto my page. So, I now have a table followed by a form. This form will contain a few text boxes that, when submitted, will post the data used to insert a new row into the preexisting table noted above.

All of the above code is currently in a PHP file named ‘display.php’.

My Issue:

If the form described above is posting back to my ‘display.php’ file, after inserting a new row and displaying the new table information, what is stopping my code from inserting another new row full of NULL data? I’m sure I did a less than decent job of explaining this scenario so I will post some code.

HTML / PHP

<html>
<head> 
    <title>Html and PHP</title>
</head>

<body>

<!-- Form -->
<form action="insertdata.php" method="post">
Username: <input type="text" name="username" >
Hardware ID: <input type="text" name="hardwareid" >
<input type="submit" >
</form>

<?php

// Connect to MYSQL
$con = mysql_connect("localhost","blah","private");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// Select database
mysql_select_db("dbname", $con);

// Insert posted data into table
$sql="INSERT INTO tablename(
Username,
HardwareID)

VALUES
('$_POST[username]','$_POST[hardwareid]')";

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

mysql_close($con)
?>

</body>
</html>

Again, I am a complete beginner – and I understand this. I want to know, must the different parts of the above code be placed into multiple files? I don’t want to have to go to a new address, which is why this is causing me so much confusion I’d say.

  • 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-25T00:13:41+00:00Added an answer on May 25, 2026 at 12:13 am

    try some thing like this,

    connection.php file

        // Connect to MYSQL
    $con = mysql_connect("localhost","blah","private");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    // Select database
    mysql_select_db("dbname", $con);
    

    display.php file

        <html>
    <head> 
        <title>Html and PHP</title>
    </head>
    
    <body>
    
    <!-- Form -->
    <form action="process.php" method="post">
    Username: <input type="text" name="username" >
    Hardware ID: <input type="text" name="hardwareid" >
    <input type="submit" >
    </form>
    
    </body>
    </html>
    

    process.php file

        include_once("ur_file_dir/connection.php");
    
        if ((isset($_POST['username']) && isset($_POST['hardwareid'])) {
    
          $sql="INSERT INTO tablename(
             Username,
             HardwareID)
    
             VALUES
                ($_POST['username'],$_POST['hardwareid'])";
          if (!mysql_query($sql,$con))
          {
              die('Error: ' . mysql_error());
          }
          echo "1 record successfully added...";
    
          mysql_close($con)
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Before you answer this I have never developed anything popular enough to attain high
Before I do this I figured I would ask if it was the best
Before I jump headlong into C#... I've always felt that C, or maybe C++,
Before, I have found the Cost in the execution plan to be a good
Before anyone suggests scrapping the table tags altogether, I'm just modifying this part of
I have a set of elements/keys which I'm reading from two different config files.
Before I start, I know there is this post and it doesn't answer my
Before moving on to use SVN, I used to manage my project by simply
Before I upgraded to Firefox 3 I used to constantly use the View Source
Before you start firing at me, I'm NOT looking to do this, but someone

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.