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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:26:22+00:00 2026-06-16T08:26:22+00:00

First of all: I’m new into MYSQL/PHP :). I’m working on a simple script

  • 0

First of all: I’m new into MYSQL/PHP :). I’m working on a simple script to learn php/mysql, but I’m stuck with several problems. I’m really sorry if some of these are already asked on this website, but I DID search them, but they didn’t work in combination with my intentions, so please don’t just -1 this post!

I’ve got a database with some tables. One of the tables is named ‘leerlingen’ and I want to add data into that table. I’m from the Netherlands, “leerlingen” means “students”. So, I’d like to add a student into the table. The table has 4 things: leerling_id, leerling_naam, leerling_nummer and klas_id. The last one is weird, right? Nope, because I’ve got another table with just one column: klas_id. That’s for later, though.

‘Klas’ means ‘group’ (yep, I’m learning you guys Dutch haha :D), and I’ve got several groups. But, you can just add a new group by another form.

Let’s get to business: I’ve created a HTML form:

<!-- start form -->

    <form action="insert_leerling.php" method="post">
<input type="text" name="leerling_naam" class="inp-form">
<input type="text" name="leerling_nummer" class="inp-form">

<?php

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

mysql_select_db("sms", $con);

 $query = "SELECT * FROM klas ORDER BY klas_id";
 $result = mysql_query($query);

echo "<select class='inp-form' id='klas_id'>\n";

while ($row = mysql_fetch_assoc($result)) {
  if (1 == 1) {
    echo '<option name="'.htmlspecialchars($row['klas_id']).'">'.htmlspecialchars($row['klas_id']).'</option>';
  }
}

echo "</select>";

?>
            <input type="submit" value="Voeg toe" class="form-submit" />

    </form>

<!-- end form  -->

So, there are 3 things inserted: leerling_naam (means student name), leerling_nummer (means student number = mobile phone number) and klas_id. I’m getting the klas_id from the little php script, so the user sees a html dropdown menu with all the klas (groups). When I run the form, it sends you to this piece of code (another page):

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

mysql_select_db("sms", $con);

$leerling_naam = $_POST['leerling_naam'];
$leerling_nummer = $_POST['leerling_nummer'];
$klas_id = $_POST['klas_id'];

$sql_insert = mysql_query("
                           INSERT INTO leerlingen 
                           (leerling_naam, leerling_nummer, klas_id) 
                           VALUES 
                           ('$leerling_naam', '$leerling_nummer', '$klas_id')
                         ");

?>

Now, here are the problems..

  1. The ‘klas_id’ isn’t inserted into the table, it’s just blanco.
  2. I want the first column (leerling_id, that’s the normal id from a mysql table) to be +1 the whole time, I’m not using that piece of code. When I add new data, the leerling_id IS going +1, but when I’m removing the first row (let’s say I kicked a student), the data isn’t dating itself up (haha, the word ‘updating’)

If you’ve read all the way trough here: well done. My English is not that good (if you find some dramatic grammar mistakes, you’re allowed to tell me 🙂 ). I also understand that this was quite hard to follow, sorry for that..

Thanks!

  • 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-16T08:26:23+00:00Added an answer on June 16, 2026 at 8:26 am
    echo "<select class='inp-form' id='klas_id'>\n";
    

    Should read

    echo "<select name='klas_id' class='inp-form' id='klas_id'>\n";
    

    You didn’t give your select form element a name. Id and Name are not interchangeable in this situation.

    In answer to your second question, why do you want the data to be completely sequential? There are no easy ways to make the database records always sequential, especially if this is the primary key of the row.

    Rather than delete records from the database, I would suggest that this is a good case for “soft record deletion”, that is, add a new column to your table called ‘active’ with a data type of ENUM('Y','N'). If you want to delete them, simply mark this field as 'N', and when querying for students, only look for records with a 'Y' in the active column.

    If you want to return your students with a sequential number in your query, look at a rownumber: @rownum:=@rownum+1 although this number will have absolutely no direct link to the id in the database.

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

Sidebar

Related Questions

First of all, I'm quite new to the Android and JAVA world (coming from
First of all there is probably a question like this already but i couldn't
First of all, apologize because I have seen some posts about this, but I
First of all, I'm a complete newbie when it comes to VBA, but unfortunately
First of all, I know how to build a Java application. But I have
First of all a small clarification.I did got AC in this problem,but my better
First of all, this isn't for a keylogger, it's for an input in a
first of all some details: I configured security as below in web.xml view plaincopy
first of all i would like to say i know its probably an easy
First of all I want to mention two things, One: My code isn't perfect

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.