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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:39:48+00:00 2026-05-28T01:39:48+00:00

im working on a project about a web-based system. I have a form, i

  • 0

im working on a project about a web-based system. I have a form, i want to check if all the fields are filled in but when one of the fields is empty it will show a prompt and will not record the data to the database unless the form have been completed. I am able to show a prompt if the fields is empty but still, it records the data provided even if one or some of the filled is empty.

Here is my html form code:

<script type='text/javascript'>
function notEmpty(elem, helperMsg){
if(elem.value.length == 0){
    alert(helperMsg);
    elem.focus();
    return false;
}
return true;
}

<form action="insert.php" method="post">
FNAME: <input type="text" name="fname" maxlength="50" id="required"/>
MNAME: <input type="text" name="mname" maxlength="50" id="required"/>
LNAME: <input type="text" name="lname" maxlength="50" id="required"/><br/>

Male <input type="radio" name="gender" value="male" /><br/>
Female <input type="radio" name="gender" value="female" /><br/>

College: 
<select name="college">
<option value="default"> --- </option>
<option value="CEC">CEC</option>
<option value="CAD">CAD</option>
<option value="COB">COB</option>
</select>
</br>

<input type="submit" name="formSubmit"    onclick="notEmpty(document.getElementById('required'), 'Please Enter a Value')"
value='SUBMIT'/>
</form> 

my php code:

<?php

$con = mysql_connect("localhost","abs","abs");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("testdb", $con);

$sql="INSERT INTO name (fname, mname, lname, gender, college)
VALUES
('$_POST[fname]','$_POST[mname]','$_POST[lname]','$_POST[gender]','$_POST[college]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }

echo "1 record added";

mysql_close($con)
?>

I can’t get it to work. I am new at php. please help me. Thanks a lot !!

  • 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-28T01:39:48+00:00Added an answer on May 28, 2026 at 1:39 am

    Something wrong in your code. You are passing one element’s id and want to check all elements.
    Also Id of all fields is same.

    Suggesting you a link : http://www.javascriptkit.com/script/script2/formrequired.shtml

    showing a live example what you want. You can take code from here and try.

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

Sidebar

Related Questions

I have been working on a web services related project for about the last
I am about to start a web project and have been working almost exclusively
I'm working on a semantic web project and I've encountered some problems about Uri
I'm working on a web based project where we make use of the user's
Current Project Setup I've been working on a web-based chat, similar to Facebook chat.
I'm working on a web-based academical evaluation project (VS2010,C#,ASP.NET). Users can enter the web
I'm currently working on a project about social networking, where I have some problems
I'm working on an in-house project management web based application that needs to support
I'm working on a web-based project that users will access after having been authenticated
I'm working on a project about Data structures. In the first , I wrote

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.