0

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("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>

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.

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by antonioatt
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.