I am trying to set up a form for potential students to give their information for a language academay. When I tested the form with <input type="text" name"Nombre"> type of fields everything went fine. As soon as I tried to introduced drop down menus or typ radio elements the data base started to show blank for any new submission except for the ID (primary field, auto increment). Here's the code of the page:

<html><head><title>aciform</title>

</head><body style="color: rgb(255, 204, 0); background-color: rgb(0, 0, 136);" alink="#000099" link="#000099" vlink="#990099">
<span class="sd-abs-pos" style="position: absolute; top: 3.5cm; left: 1.08cm; width: 159px;"><img style="border: 0px solid ; width: 159px; height: 154px;" alt="logo" src="acishield.gif" name="gráficos1"></span>
<span class="sd-abs-pos" style="position: absolute; top: 3.5cm; left: 22cm; width: 159px;"><img style="border: 0px solid ; width: 159px; height: 154px;" alt="logo" src="acishield.gif" name="gráficos2"></span>
<div style="text-align: center;">
<h3>¡¡Llena ahora el formulario de pre-inscripcion sin ningun
compromiso!!
</h3>
</div>
<form action="confirmacion.php" method="post">
<div style="text-align: center;">
<h4>Nombre:&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;&nbsp; <input name="name" type="text"></h4>
</div>
<div style="text-align: center;">
<h4>Correo
electronico:&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;
&nbsp; <input name="email" type="text"></h4>
</div>
<div style="text-align: center;">
<h4>Teléfono:
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <input name="phone" type="text"></h4>
</div>
<div style="text-align: center;">
<h4>Curso
deseado:<br>
<input type="radio" name="level" value="Basicó" /> Basicó<br />
<input type="radio" name="level" value="Intermedio" /> Intermedio<br />
<input type="radio" name="level" value="Avanzado" /> Avanzado<br />
<input type="radio" name="level" value="Francés" /> Francés<br />
</h4>
</div>
<div style="text-align: center;">
<h4>Modo de
comunicación:<br>
<input type="radio" name="communication" value="Teléfono" /> Teléfono<br />
<input type="radio" name="communication" value="Correo electronico" /> Correo electronico<br />
</h4>
</div>
<div style="text-align: center;"><input type="submit">
</div>
</form>
<?php
$username="a6239874_reg";
$password="password";
$database="a6239874_reg";

$name=$_POST;
$email=$_POST;
$phone=$_POST;
$level=$_POST;
$communication=$_POST;

mysql_connect("",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO register VALUES ('','$name','$email','$phone','$level','$communication')";
mysql_query($query);

mysql_close();
?>
</body></html>

I am totaly new to programming html and php so excuse my ignorance and please explain to me like if I were a 5 years old. Thank you.

Dani AI

Generated

Brief summary: the empty rows (only the ID filled) mean the INSERT ran with empty values. is right to point at running the insert only after the form is submitted — that fixes many cases — but there are a few more things to check before and after that change.

Quick, practical debug (temporary, for your development copy)

<?php
print_r($_POST);
exit;
?>

If that shows an empty array the browser never sent the fields — check the form method is POST, the action points to the processing script, and every input/select/radio has a correct name attribute (typos or a missing = are common). Remember: unchecked checkboxes do not appear in POST; radio buttons only send a value when one is selected.

Database and server checks

  • Verify the table structure matches the number and order of values you insert. Prefer using an explicit column list in INSERT so column-order changes on the table do not break your script.
  • Turn on error reporting and check the query result and any DB error messages instead of suppressing them. That will show real causes instead of silent failures.
  • If your values contain non-ASCII characters (accents), ensure the connection and table use UTF-8/utf8mb4 or you can get corrupted/empty strings.

Security and best practice

  • Move away from the old mysql extension: use mysqli or PDO with prepared statements to avoid SQL injection and quoting issues.
  • Validate and sanitize POST data before inserting. Log or show clear error messages in development but never leave verbose errors enabled on a production site.

If print_r($_POST) shows the expected values but the database still stores blanks, inspect the exact SQL being sent and the field list in the table (use phpMyAdmin or DESCRIBE). This will quickly identify whether the problem is the incoming data, the SQL, or the table schema.

Your code has only an error but the error I'm sure was present also when you had only textbox.
Siunce your php code is in the same file of your html code it is executed when you load your page(confirmacion.php).
Then ,when your page is loaded ol your fields are blank:

$name=$_POST['name']='';
$email=$_POST['email']='';
$phone=$_POST['phone']='';
$level=$_POST['level']='';
$communication=$_POST['communication']='';

Then you execute the query: INSERT INTO register VALUES('','','','','',''); You can verify this adding for debug this line of code : echo "$query"; after: $query = "INSERT INTO register VALUES ('','$name','$email','$phone','$level','$communication')"; To prevent this you can modify your PHP code to be executed only after form submission.
To test if form as been submitted you can use this test: if(($_SERVER['REQUEST_METHOD'] == "POST") ) true if form is submitted.
Then your php code becomes :

if(($_SERVER['REQUEST_METHOD'] == "POST") ){
//your code here
}

This is your code modified:

<html><head><title>aciform</title>

</head><body style="color: rgb(255, 204, 0); background-color: rgb(0, 0, 136);" alink="#000099" link="#000099" vlink="#990099">
<span class="sd-abs-pos" style="position: absolute; top: 3.5cm; left: 1.08cm; width: 159px;"><img style="border: 0px solid ; width: 159px; height: 154px;" alt="logo" src="acishield.gif" name="gráficos1"></span>
<span class="sd-abs-pos" style="position: absolute; top: 3.5cm; left: 22cm; width: 159px;"><img style="border: 0px solid ; width: 159px; height: 154px;" alt="logo" src="acishield.gif" name="gráficos2"></span>
<div style="text-align: center;">
<h3>¡¡Llena ahora el formulario de pre-inscripcion sin ningun
compromiso!!
</h3>
</div>
<form action="confirmacion.php" method="post">
<div style="text-align: center;">
<h4>Nombre:&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;&nbsp; <input name="name" type="text"></h4>
</div>
<div style="text-align: center;">
<h4>Correo
electronico:&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;
&nbsp; <input name="email" type="text"></h4>
</div>
<div style="text-align: center;">
<h4>Teléfono:
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <input name="phone" type="text"></h4>
</div>
<div style="text-align: center;">
<h4>Curso
deseado:<br>
<input type="radio" name="level" value="Basicó" /> Basicó<br />
<input type="radio" name="level" value="Intermedio" /> Intermedio<br />
<input type="radio" name="level" value="Avanzado" /> Avanzado<br />
<input type="radio" name="level" value="Francés" /> Francés<br />
</h4>
</div>
<div style="text-align: center;">
<h4>Modo de
comunicación:<br>
<input type="radio" name="communication" value="Teléfono" /> Teléfono<br />
<input type="radio" name="communication" value="Correo electronico" /> Correo electronico<br />
</h4>
</div>
<div style="text-align: center;"><input type="submit">
</div>
</form>
<?php 
if(($_SERVER['REQUEST_METHOD'] == "POST") ){
$username="a6239874_reg";
$password="password";
$database="a6239874_reg";

$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$level=$_POST['level'];
$communication=$_POST['communication'];

mysql_connect("mysql16.000webhost.com",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO register VALUES ('','$name','$email','$phone','$level','$communication')";
mysql_query($query);

mysql_close();
}
?>
</body></html>

If after this your code don't inserts correct values in your table
post your table definition(If error occurs then it MUST be in table definition since the php code is correct)

Bye

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.