Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/01/2011, 13:32
Tirant95
 
Fecha de Ingreso: enero-2011
Mensajes: 2
Antigüedad: 13 años, 3 meses
Puntos: 0
Pregunta Formulario con problemas

Buenas!

Soy novato en la programación en php y llevo unos cuantos dias documentandome sobre este lenguaje y he conseguido crear un pequeño formulario para mi página de ajedrez para que sea más facil los partidos entre equipos de la liga.

El problema viene en que dada mi poca experiencia debo de haber cometido algún error al modificar los códigos sobre los que me he apoyado ya que al subirlos al servidor no me crean un post como deseo, ya que para la página sería bastante más cómódo que recibir un email aunque si que me lee todos los apartados.

Os agradecería muchíssimo si alguno de vosotros pudiera ayudarme a solucionar este problema que me tiene algo mareado.

Aquí os dejo el código que he empleado para el formulario:


Código PHP:
<?php 

$servidor
"localhost";

$usuario"tu_usuario";

$password"tu_password";

$date gmdate("Y-m-d");

$conexion=mysql_connect($servidor$usuario$password) or die ("no se puede conectar con el servidor");

mysql_select_db("tu_basedatos",$conexion) or die ("no se puede selecionar la base de datos");

//colocamos un condicional if para que la consulta solo de ejecute cuando hagamos clic en el boton de enviar

if($_POST['Enviar']==true){

$guardar_mensaje="INSERT INTO el_nombre_de_tu_tabla (id, nombre, email, mensaje, fecha) VALUES ('', '".$_post['player1']."', '".$_post['cat1']."', '".$_post['player2'].'".$_post['cat2'].'".$_post['player3'].'".$_post['cat3'].'".$_post['player4']'".$_post['cat4'].'".$_post['player5'].'".$_post['cat5'].'".$_post['player5'].'".$_post['cat6']."', '$date')";

$consulta_guardar=mysql_query($guardar_mensaje$conexion) or die ("no se pueden insertar los datos en la base de datos");

//esta variable la colocamos para que cuando se termine la ejecucion de la consulta guardar se mande esta variable para ejecutar un script que esta dentro de las estiquetas head para que muestre un mensaje de alerta en javascript indicando que se guardo con exito 

$mensaje_de_alerta="1";

}


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Documento sin t&iacute;tulo</title>

<?php

if($mensaje_de_alerta=="1"){ echo "<script type=\"text/javascript\">

alert('su mensaje fue enviado con exito');

</script>

"
;}

?>

</head>

<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Lineups


<form id="form1" name="form1" method="post" action=codigo.php"">

<table width="350" height="145" border="0" cellpadding="0" cellspacing="0">



  <tr>

    <td width="136" height="28">Player 1:</td>

    <td width="214">

      <label>

        <input type="text" name="Player 1" id="player1" style="width:200px; background-color:#FFFFB0;" />

<td width="30" height="28">Cat :</td>

    <td width="30">

      <label>

        <input type="text" name="Cat" id="cat1" style="width:30px; background-color:#FFFFB0;" />

        </label>    </td>

  </label></td></tr>

  <tr>

    <td height="19">Player 2:</td>

    <td><input type="text" name="Player 2" id="player2" style="width:200px; background-color:#FFFFB0;" /></td>

<td width="30" height="28">Cat:</td>

    <td width="30">

      <label>

        <input type="text" name="Cat" id="cat2" style="width:30px; background-color:#FFFFB0;" />

  </label></td></tr>

  <tr>

<td height="19">Player 3:</td>

    <td><input type="text" name="Player 3" id="player3" style="width:200px; background-color:#FFFFB0;" /></td>

<td width="30" height="28">Cat:</td>

    <td width="30">

      <label>

        <input type="text" name="Cat" id="cat3" style="width:30px; background-color:#FFFFB0;" />

  </label></td></tr>

  <tr>

<td height="19">Player 4:</td>

    <td><input type="text" name="Player 4" id="player4" style="width:200px; background-color:#FFFFB0;" /></td>

<td width="30" height="28">Cat:</td>

    <td width="30">

      <label>

        <input type="text" name="Cat" id="cat4" style="width:30px; background-color:#FFFFB0;" />

  </label></td></tr>

  <tr>

<td height="19">Player 5:</td>

    <td><input type="text" name="Player 5" id="player5" style="width:200px; background-color:#FFFFB0;" /></td>

<td width="30" height="28">Cat:</td>

    <td width="30">

      <label>

        <input type="text" name="Cat" id="cat5" style="width:30px; background-color:#FFFFB0;" />

  </label></td></tr>

  <tr>

<td height="19">Player 6:</td>

    <td><input type="text" name="Player 6" id="player6" style="width:200px; background-color:#FFFFB0;" /></td>

<td width="30" height="28">Cat:</td>

    <td width="30">

      <label>

        <input type="text" name="Cat" id="cat6" style="width:30px; background-color:#FFFFB0;" />

  </label></td></tr>

  <tr>


    <input type="submit" name="Enviar" id="Enviar" value="Enviar" style="width:100px; height:30px;" />


  </tr>

</table>

</form>


$consulta_mostrar="SELECT * FROM el_nombre_de_tu_tabla ORDER BY id DESC";

$consulta_mostrar=mysql_query($consulta_mostrar,$conexion) or die ("no se puede realizar la consulta");



?>

<table width="350" border="0" cellspacing="0" cellpadding="0">

  <tr>

      <td height="18" colspan="2">Team Lineup</td>

  </tr>

  <? do{ ?>

  <tr>

    <td width="232" height="18">Player 1: <? echo $datos_mostrar['player1']; ?></?></td>

<td width="232" height="18"> Cat : <? echo $datos_mostrar['cat1']; ?></?></td>

 </tr>

  <tr>

<td width="232" height="18">Player 2: <? echo $datos_mostrar['player2']; ?></?></td>

<td width="232" height="18"> Cat: <? echo $datos_mostrar['cat2']; ?></?></td>

 </tr>

  <tr>

<td width="232" height="18">Player 3: <? echo $datos_mostrar['player3']; ?></?></td>

<td width="232" height="18"> Cat: <? echo $datos_mostrar['cat3']; ?></?></td>

 </tr>

  <tr>

<td width="232" height="18">Player 4: <? echo $datos_mostrar['player4']; ?></?></td>

<td width="232" height="18"> Cat: <? echo $datos_mostrar['cat4']; ?></?></td>

 </tr>

  <tr>

<td width="232" height="18">Player 5: <? echo $datos_mostrar['player5']; ?></?></td>

<td width="232" height="18"> Cat: <? echo $datos_mostrar['cat5']; ?></?></td>

 </tr>

  <tr>

<td width="232" height="18">Player 6: <? echo $datos_mostrar['player6']; ?></?></td>

<td width="232" height="18"> Cat: <? echo $datos_mostrar['cat6']; ?></?></td>

 </tr>

  <tr>

    <td width="118">fecha: <? echo $datos_mostrar['fecha']; ?></?></td>

  </tr>

  <tr>

    

  </tr>

  <?php } while($datos_mostrar=mysql_fetch_assoc($consulta_mostrar)); ?>

  <tr>

    <td height="36" colspan="2">&nbsp;</td>

  </tr>

</?php></?></table>

 



</!doctype></?php>