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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:38:38+00:00 2026-05-28T06:38:38+00:00

I have a simple form that’s supposed to enter submissions in a MySQL database

  • 0

I have a simple form that’s supposed to enter submissions in a MySQL database but whenever the form is submitted I get a server 500 error. I’m new to the PHP/MySQL so i’m not seeing the problem. Any ideas?

HTML Form Excerpt:

<form method="post" action="submit.php">
  <label for="fname">First Name *:</label>
    <input type="text" id="fname" name="fname" /><br />
  <label for="lname">Last Name *:</label>
    <input type="text" id="lname" name="lname" /><br />
  <label for="email">Email *:</label>
    <input type="email" id="email" name="email" /><br />
  <label for="phone">Phone Number:</label>
    <input type="tel" id="phone" name="phone" /><br />
  <input type="checkbox" id="ageverify" />
    <label for="ageverify">I am at least 18 years of age *</label><br />
  <input type="checkbox" id="terms" />
    <label for="terms">I agree to the Terms &amp; Conditions *</label><br />
  <input type="submit" value="Submit" />
</form>

Entirety of submit.php

<?
mysql_connect("localhost","USERNAME","PASSWORD");
mysql_select_db("DB_NAME");

$sql = "INSERT into entries (fname,lname,email,phone,ageverify,terms) "; 
$sql .= "VALUES ("; 
$sql .= $_POST['fname'] . ',' . $_POST['lname'] . ',' . $_POST['email'] . ','; 
$sql .= $_POST['phone'];

if (isset($_POST['ageverify']) // if checked will exist, otherwise it won't 
$sql .= 'yes' . ','; 
else 
$sql .= 'no' . ','; 

if (isset($_POST['terms']) 
$sql .= 'yes' . ','; 
else 
$sql .= 'no' . ','; 

$sql .= ')'; 

$result = mysql_query($sql); 

if($result){
    echo("Thanks");
} else{
    echo("Something went wrong");
}
?> 

UPDATE: WORKING CODE (As rudimentary as it may be)

<?php 
mysql_connect("localhost","USERNAME","PASSWORD");
mysql_select_db("DB_NAME");

$sql = "INSERT into entries (fname,lname,email,phone,ageverify,terms) "; 
$sql .= "VALUES ("; 
$sql .= '"' . $_POST['fname'] . '"' . ',' . '"' . $_POST['lname'] . '"' . ',' . '"' . $_POST['email'] . '"' . ','; 
$sql .= '"' . $_POST['phone'] . '"'; 

if (isset($_POST['ageverify'])) // if checked will exist, otherwise it won't 
$sql .= ',' . '"yes"' ; 
else 
$sql .= ',' . '"no"'; 

if (isset($_POST['terms'])) 
$sql .= ',' . '"yes"'; 
else 
$sql .= ',' . '"no"'; 

$sql .= ')'; 

echo $sql; 

$result = mysql_query($sql); 

if($result){ 
echo("Thanks"); 
} else{ 
echo("Something went wrong"); 
} 
?> 
  • 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-28T06:38:39+00:00Added an answer on May 28, 2026 at 6:38 am

    First of all: Read up on SQL injection! You are definitely vulnerable!

    Second, you should enable error reporting while developing – this would have told what was wrong.

    The status 500 appears because something serverside went wrong. You can check your error logs, when this occurs.

    Though, if you enable error reporting, you get the errors on screen. This would have told you that you have syntax errors.
    You are missing ending parentheses on line 11 and 16:

    if (isset($_POST['ageverify'])
    

    should be

    if (isset($_POST['ageverify']))
    

    And the same goes for line 16.

    Thirdly, always start PHP tags with <?php and NOT just <?. Try avoiding short tags.

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

Sidebar

Related Questions

I have a simple form that behaves as expected when method=GET , but when
I have a simple form that I wish to postback to the server in
I have a simple form that I am currently posting back to the server
I have a simple html form that submits information with POST function. But when
I have a simple form that inserts data in a table on my server.
I have a simple form that I don't want accidentally submitted multiple times. I
I have a simple form that uploads an image to a database. Using a
I have a simple two-field form that stores its data in the database. For
I have a simple form that looks like so <% remote_form_for post, :url =>
I have a simple form that searches through the 2000+ issues of a 3rd

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.