-1

I am creating a registration form for my school's event, but being very new to PHP and database makes it a hard work for me.

The problem is that the form submits blank data to the table. I can see that there is a new row created upon every submission, but the data is blank.

Here is the code:

Part of form in index.html

<form action="input.php" method="post">
<p>
   <input name="prefix" type="radio" id="male"/>
   <label for="male">นาย/เด็กชาย</label>
</p>
<p>
   <input name="prefix" type="radio" id="female"/>
   <label for="female">นางสาว/เด็กหญิง</label>
</p>
<div class="row">
    <div class="col s12">
        <div class="input-field col s12 m6">
            <input id="firstname" type="text" class="validate"/>
            <label for="firstname">ชื่อ</label>
        </div>
        <div class="input-field col s12 m6">
            <input id="lastname" type="text" class="validate"/>
            <label for="lastname">นามสกุล</label>
        </div>
           .
           .
           .
           .
<button class="btn btn-large waves-effect waves-light red accent-4" type="submit" name="submit">ส่ง</button>
</form>

input.php

<?php
mysql_connect("localhost", "acsp", "passwordhidden");
mysql_select_db("logicgames");
$order = "INSERT INTO data_logicgames (prefix, firstname, lastname, phone, school, teammate1, teammate2, games, division) VALUES ('$prefix', '$firstname', '$lastname', '$phone', '$school', '$teammate1', '$teammate2', '$games', '$division')";
$result = mysql_query($order);
if ($result) {
    echo "<p>Success</p>";
} else {
    echo "<p>Failed</p>";
}
?>
Nathan
  • 1,074
  • 9
  • 14

4 Answers4

1

First give your every input field some name as in database field.

You have to receive your POST value in variables. If you don't want to do this every time. You can use a foreach loop.

<?php
mysql_connect("localhost", "acsp", "passwordhidden");
mysql_select_db("logicgames");
foreach($_POST as $key => $val)
{
    ${$key} = $val;
}
$order = "INSERT INTO data_logicgames (prefix, firstname, lastname, phone, school, teammate1, teammate2, games, division) VALUES ('$prefix', '$firstname', '$lastname', '$phone', '$school', '$teammate1', '$teammate2', '$games', '$division')";
$result = mysql_query($order);
if ($result) {
    echo "<p>Success</p>";
} else {
    echo "<p>Failed</p>";
}
?>
Al Amin Chayan
  • 2,460
  • 4
  • 23
  • 41
1

Better way to do is..

<?php

if( isset($_POST['submit']) )
{
    $prefix     =   $_POST['prefix'];
    $firstname  =   $_POST['firstname'];
    $lastname   =   $_POST['lastname'];
    $phone      =   $_POST['phone'];
    $school     =   $_POST['school'];
    $teammate1  =   $_POST['teammate1'];
    $teammate2  =   $_POST['teammate2'];
    $games      =   $_POST['games'];
    $division   =   $_POST['division'];

    mysql_connect("localhost", "acsp", "passwordhidden");
    mysql_select_db("logicgames");
    $order = "INSERT INTO data_logicgames (prefix, firstname, lastname, phone, school, teammate1, teammate2, games, division) VALUES ('$prefix', '$firstname', '$lastname', '$phone', '$school', '$teammate1', '$teammate2', '$games', '$division')";
    $result = mysql_query($order);
    if ($result) {
        echo "<p>Success</p>";
    } else {
        echo "<p>Failed</p>";
    }
}
else
{
    echo "<p>Failed</p>";
}
?>
syed suleman
  • 542
  • 2
  • 6
0

in your input.php you not define

'$prefix', '$firstname', '$lastname', '$phone', '$school', '$teammate1', '$teammate2', '$games', '$division'

like this $prefix = $_POST['prefix']; etc

0

Your form have 2 inputs without name tag ! You need to give a name tag to every field that you send to the server and be able to retrieve it with $_POST["lastname"]; in php . Where are you declaring your values ? ($prefix,$lastaname etc ..) the id is only used when you work with JavaScript.

Carlos Delgado
  • 2,930
  • 4
  • 23
  • 49