HELP php form to fill up Database

Hi all , I’m quite new to PHP and this forum I met with some problems with my programming and have no idea how to solve it will any experts mind to help?

What do you expect your code to do? What is going wrong? Are you getting errors? Help us help you, instead of asking us to do it entirely for you.


Also, I know it’s off topic from your question, but because someone will say it eventually anyway, I feel obliged to note that mysql_ functions are deprecated and should probably not be used in new code. You should use MySQLi or PDO instead. Here’s an article on switching to PDO, if you choose to do so.


Everytime I see magic_quotes I get the hibby gibbies :open_mouth: :smile:

Either you have gotten the script from an outdated book or from a website that hasn’t updated their tutorials.

1 Like

Can you have a column name in MySQL that contains a space? Your query uses “Serial Number” as a column name, also you have two commas together in the query, which doesn’t seem correct either.

Also you have

$con = mysql_connect(...

but then

$retval = mysql_query( $sql, $conn );

(now there is double n in $conn)

I’m trying to fill up my database through a form.

Have no idea how the codes work and kinda just copied from the tutorial


this is how my database is. Let me know if I did something wrong :slight_smile: Thanks so much guys

I would modify your table a little bit, I would have all lowercase and serial number should be either serial_number or serialNumber (it’s called camel Case).

I took it upon myself to spruce up you html form a litlte:

<!DOCTYPE html>
<html>
    <head>
        <title>Register Switch Gear</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <style>
            * {
                box-sizing: border-box;
                -moz-box-sizing: border-box;
                -webkit-box-sizing: border-box;
            }
            form#register {
                display: block;
                width: 100%;
                max-width: 600px;
                height: 400px;
                padding: 10px;
                margin: 10px auto;
            }
            form#register fieldset {
                text-transform: capitalize;
                padding: 20px;
            }
            form#register legend {
                font-size: 1.6rem;
                padding: 0 6px;
            }
            form#register label {
                float: left;
                display: block;
                width: 100%;
                max-width: 340px;
                height: 25px;
                font-family: Arial, Helvetica, sans-serif;
                font-size: 1.0rem;
                line-height: 25px;
                text-transform: capitalize;
                text-align: right;
                padding: 0 10px;
            }
            form#register input {
                outline: none;
                border: none;
                border-bottom: 1px dashed #000;
                clear: right;
                display: block;
                width: 100%;
                max-width: 180px;
                height: 25px;
                font-family: Arial, Helvetica, sans-serif;
                font-size: 1.0rem;
                padding: 0 5px;
            }
            form#register input[type=submit] {
                cursor: pointer;
                float: right;
                border: none;
                outline: none;
                width: 100%;
                max-width: 80px;
                height: 25px;
                font-size: 1.0rem;
                background-color: #2e2e2e;
                color: #fff;
                text-transform: capitalize;
                margin: 10px;
            }
            form#register input[type=submit]:hover {
                background-color: orange;
            }
        </style>
    </head>
    <body>
        <form id="register" action="registerswitchgear.php" method="post">
            <fieldset>
                <legend>data entry</legend>
                <label>serial number</label>
                <input type="text" name="serialnumber" tabindex="1" autofocus>
                <label>brand</label> 
                <input type="text" name="brand" tabindex="2">
                <label>temperature</label>
                <input type="text" name="temperature" tabindex="3">
                <label>age</label>
                <input type="text" name="age" tabindex="3">
                <label>loading in %</label>
                <input type="text" name="loading" tabindex="4">
                <label>number of maintenance per year</label>
                <input type="text" name="maintenance" tabindex="5">
                <label>number of switching operations per year</label>
                <input type="text" name="switching" tabindex="6">
                <input type="submit" name="submitted" value="enter" tabindex="7">
            </fieldset>
        </form>
    </body>
</html>

I like fooling around in HTML/CSS and if I get the time I’ll help you out with the php portion of the form; however, I’m sure others here will also be glad to help you out or steer you in the right direction.

What tutorial are you using?

i used this

Really really appreciate what you’ve done. It’s awesome.
Thanks so much!

That will not work if the form is submitted by pressing the enter key on the keyboard.

editted into this but still kinda don’t work have no idea why

<?php error_reporting(0); if(isset($_POST['submitted'])){ $connect_error = 'Sorry, we\'re experiencing connection problems.'; $con = mysql_connect('localhost','root','') or die($connect_error); mysql_select_db("switchgear",$con); $serial = $_POST['serialnumber']; $brand = $_POST['brand']; $temp = $_POST['temperature']; $age = $_POST['age']; $loading = $_POST['loading']; $maintenance = $_POST['maintenance']; $switching = $_POST['switching']; $sql = "INSERT INTO registerswitchgear(serialnumber,brand,temperature,age,loading,maintenance,switching) VALUES('$serial','$brand','$temp','$age','$loading','$maintenance','$switching')"; echo "

Data Inserted successfully...!!"; } else{ echo "

Insertion Failed
Some Fields are Blank....!!

"; } mysql_close($connection); ?>

Hard to tell where to look - what happens (or doesn’t happen)? Do you get error messages? How far does it get before you get a message or it stops working? What are the variable values at that point?

Have you changed the field names in your database so they are all lowercase without spaces?

yup it has been changed. Currently my after filling up the form and keying in the data my database doesn’t get updated

after submitting the form the database doesn’t get updated has an error message like not submitted successfully

It is difficult to follow your code as some of it is enclosed between 3 ticks and some isn’t. However, presumably the error message gives a line number in your script where it has failed - it would be helpful if you gave the exact message you get. Also, you set the SQL code in $sql = “INSERT …” but I can’t see where you actually run the query.

there isn’t really an exact error message but just that after I click submit nothing really happens and the database doesn’t get updated.

As I say, you’re missing the command to update the database. In your original you had a mysql_query() command but it appears to have gone AWOL.

you’re a life saver bro… OMG can’t thank you enough

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.