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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:12:15+00:00 2026-06-09T20:12:15+00:00

I have a php page that connects to a mysql database. I know that

  • 0

I have a php page that connects to a mysql database. I know that the connection to the database is good because I have a php code that displays info from the database onto the webpage. When I try to insert new data into the databse, the page refreshes and the data is not inserted. I have checked to insure that the insert into command has the correct values.

      <?php 

    if (isset($_POST['User_Name'])) 
        {

            include "connect_to_mysql.php";

            $name = mysql_real_escape_string($_POST["Name"]);

            $sql = mysql_query("SELECT TestID FROM test WHERE Name='$name' LIMIT 1")or die (mysql_error());
            $productMatch = mysql_num_rows($sql); 

            if ($productMatch > 0) 
                {
                    echo 'Sorry you tried to place a duplicate "User Account" into the system, <a href="index.php">click here</a>';
                    exit();
                }
                else
                {

                    $sql = mysql_query("INSERT INTO test (TestID,Name) 
                        VALUES('', '$name')") or die (mysql_error());
                     $uid = mysql_insert_id();

                    header("location: index.php"); 
                    exit();
                }
        }
?>
<?php 

    include "connect_to_mysql.php";
    $User_list = "";
    $sql = mysql_query("SELECT * FROM test");
    $UserCount = mysql_num_rows($sql); 
    if ($UserCount > 0) 
        {
            while($row = mysql_fetch_array($sql))
                { 
                         $id = $row["TestID"];
                         $name = $row["Name"];

                         $User_list .= "Users ID: $id - <strong>$name</strong>&nbsp; &nbsp; &nbsp;<br />";
                }
        } 
        else 
        {
            $User_list = "You have no users listed in the database.";
        }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<div align="center" id="mainWrapper">
  <div id="pageContent"><br />
    <div align="right" style="margin-right:32px;"><a href="index.php#UserForm">+ Add New User</a></div>
<div align="left" style="margin-left:24px;">
      <h2>User list</h2>
      <?php echo $User_list; ?>
    </div>
    <hr />
    <a name="UserForm" id="UserForm"></a>
    <h3>
    &darr; Add New User Form &darr;
    </h3>
    <form action="index.php" enctype="multipart/form-data" name="myForm" id="myform" method="post">
    <table width="90%" border="0" cellspacing="0" cellpadding="6">
      <tr>
        <td width="20%" align="right">Name</td>
        <td width="80%"><label>
          <input name="name" type="text" id="name" size="50" />
        </label></td>
      </tr> 
      <tr>
        <td>&nbsp;</td>
        <td><label>
          <input type="submit" name="button" id="button" value="Add This Name Now" />
        </label></td>
      </tr>
    </table>
    </form>
    <br />
  <br />
  </div>
</div>
</body>
</html>
  • 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-09T20:12:17+00:00Added an answer on June 9, 2026 at 8:12 pm

    I see two problems right away (there may be more). First, PHP array keys are case sensitive. You are accessing $_POST['Name'] but your form input is name. Second, you are testing for $_POST['User_Name'] which doesn’t appear to exist anywhere:

    // Look for name in the $_POST
    if (isset($_POST['name'])) 
    {
        include "connect_to_mysql.php";
        // name is case-sensitive
        $name = mysql_real_escape_string($_POST["name"]);
    

    Later, if your table has an AUTO_INCREMENT id on TestID, you should either omit it or insert NULL in the insert statment:

    // Don't include TestID if it is AUTO_INCREMENT. That will happen automatically
    $sql = mysql_query("INSERT INTO test (Name) 
                        VALUES('$name')") or die (mysql_error());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple php page that displays data from a mysql database. I
I have a php page that pulls data from a mysql database based on
I have a site that displays data on travel products from a MySQL database.
I am retrieving json from a php file that connects to the database and
I have a PHP page that loads external content using other PHP files. I'm
i have a php page that redirects (if successful) to another php page like
I have a PHP page that returns a piece of HTML to set the
I have a PHP page that I run every minute through a CRON job.
I have a PHP page that does a couple of different things depending on
I have a php page that takes in a bunch of url parameters and

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.