Code: Select all
<?php
// CONEXÃO À BASE DE DADOS
$dbConnection = mysql_connect("localhost", "root", "") or die("Não foi possível estabelecer uma ligação ao MYSQL!");
$dbSelected = mysql_select_db("proj",$dbConnection) or die("Não foi possível seleccionar a Base de Dados! |Conexão ao MYSQL: ".$dbConnection);
if(isset($_POST['botao_submit'])) {
$campo1 = $_POST['campo1'];
$campo2 = $_POST['campo2'];
if(!(empty($campo1) || empty($campo2))) {
// CONSULTA
mysql_query("INSERT INTO form(campo1,campo2) VALUES('".$_POST['campo1']."','".$_POST['campo2']."')");
$id = mysql_insert_id();
}
}
if(isset($id)) {
$get = mysql_query("SELECT * FROM form WHERE id=".$id);
$record = mysql_fetch_assoc($get);
}
?>
<html>
<head>
<title>Formulario</title>
</head>
<body>
<form action="form.php" method="POST">
Campo1: <input type="text" name="campo1" />
Campo2: <input type="text" name="campo2" />
<input type="submit" name="botao_submit">
</form>
<?php if(isset($record)){ ?>
<form action="form.php" method="POST">
Campo Saida1: <input type="text" name="campo_saida1" value="<?php echo $record['campo1']; ?>" />
Campo Saida2: <input type="text" name="campo_saida2" value="<?php echo $record['campo2']; ?>" />
</form>
<?php } ?>
</body>
</html>My ultimate aim is to replace the fields campo1 and campo2 by the questions of a survey and show the answers submitted by all the users in the formulary below or in another page.
I used mysql_last_insert_id(); because like I haven't programmed in PHP for 2 years, I collected information here and there but I only realized it doesn't do all I want.
If you can help me adapting the code I'll be very grateful
