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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:08:24+00:00 2026-05-27T15:08:24+00:00

Why i can’t insert on my database? This is my code <?php $name =

  • 0

Why i can’t insert on my database? This is my code

<?php

$name = $_POST['name'];
$email = $_POST['email'];
$bdate = $_POST['bdate'];
$id = $_POST['id'];

if (!empty($name) && !empty($email)){
    mysql_query("insert into customer(id,name,email,bdate) values($id,'$name','$email','$bdate')");
}
else {
    echo "Please fill <strong>name</strong> and <strong>e-mail</strong> fields!";
}

?>

My form is

<form method="post" action="new_customer.php">
    ID: <input type="text" name="id" size="5" value="<?php echo $new_id; ?>" disabled="disabled" /><br />
    Name: <input type="text" name="name" size="50" /><br />
    E-mail: <input type="text" name="email" size="30" /><br />
    Birth Date: <input type="text" name="bdate" size="10" /><br /><br />
    <input type="submit" value="Save" />
</form>

The var $new_id is filled with this query

SELECT (Max(id) + 1) as new_id FROM customer

But when I submit the form, the error i get is:

Notice: Undefined index: id in F:\UniServer\www\admin\customer.php on line 6

and then a mysql error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' '')' at line 1

i think the first error causes the secund, right?

  • 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-27T15:08:24+00:00Added an answer on May 27, 2026 at 3:08 pm

    Because disabled fields are not present in $_POST array.
    In your case make id field auto increment in the database and make a query without it:

    mysql_query("INSERT INTO customer(name, email, bdate) values('$name', '$email', '$bdate')"); 
    

    Also your code is subject to SQL injection – use mysql_real_escape_string before the query:

    $name = mysql_real_escape_string($_POST['name']);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

can any one tell me how can change this java code into objective c.is
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Can someone tell me why this code produces error? The C# code DateTime now
Can we close all known/unknown connections to database with the code? I'm using Access
Can someone maybe tell me why this is not working? I have used echo
Can anybody tell me a regular expression to use within some PHP to find
Can i get the source code for a WAMP stack installer somewhere? Any help
Can I get a list of issues with the code below, and fixes? string
Can we use the asterisk character * for a search action in SQL database?
Can anyone help me trying to find out why this doesn't work. The brushes

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.