Quantcast
Channel: Tópicos
Viewing all articles
Browse latest Browse all 14700

Dados tabela MYSQL em tabela HTML

$
0
0
Boas pessoal,

Criei um formulário de registo em php onde os clientes fazem o registo, criei a respectiva tabela na BD MYSQL. Tudo ok...o cliente regista-se e aparecem os dados na tabela.

A minha questão é a seguinte. Eu queria que os dados fossem também actualizados numa tabela em HTML. Ou seja, um cliente faz um registo e em vez de estar sempre a ir ao phpmyadmin vejo os updates na tabela em html.

Como faço isso?

Deixo aqui o código do formulário:

Código :
<?php require_once('Connections/conexao.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  switch ($theType) {
    case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;  
    case "long":
    case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
    case "double":
          $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
          break;
    case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
    case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
  }
  return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO clientes (cliente_nome, cliente_apelido, cliente_localidade, cliente_email, cliente_telefone, cliente_nif, cliente_data) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                                           GetSQLValueString($_POST['cliente_nome'], "text"),
                                           GetSQLValueString($_POST['cliente_apelido'], "text"),
                                           GetSQLValueString($_POST['cliente_localidade'], "text"),
                                           GetSQLValueString($_POST['cliente_email'], "text"),
                                           GetSQLValueString($_POST['cliente_telefone'], "text"),
                                           GetSQLValueString($_POST['cliente_nif'], "text"),
                                           GetSQLValueString($_POST['cliente_data'], "date"));
  mysql_select_db($database_conexao, $conexao);
  $Result1 = mysql_query($insertSQL, $conexao) or die(mysql_error());
  $insertGoTo = "sucesso.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<!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>Formulário de Registo</title>
</head>
<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  <table align="center">
    <tr valign="baseline">
          <td nowrap="nowrap" align="right">Nome:</td>
          <td><input type="text" name="cliente_nome" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
          <td nowrap="nowrap" align="right">Apelido:</td>
          <td><input type="text" name="cliente_apelido" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
          <td nowrap="nowrap" align="right">Localidade:</td>
          <td><input type="text" name="cliente_localidade" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
          <td nowrap="nowrap" align="right">Email:</td>
          <td><input type="text" name="cliente_email" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
          <td nowrap="nowrap" align="right">Telefone:</td>
          <td><input type="text" name="cliente_telefone" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
          <td nowrap="nowrap" align="right">NIF:</td>
          <td><input type="text" name="cliente_nif" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
          <td nowrap="nowrap" align="right"> </td>
          <td><input type="submit" value="Submeter" /></td>
    </tr>
  </table>
  <input type="hidden" name="cliente_data" value="" />
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p>
</body>
</html>

E da conexão à tabela:

Código :
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_conexao = "localhost";
$database_conexao = "cartaocliente";
$username_conexao = "root";
$password_conexao = "";
$conexao = mysql_pconnect($hostname_conexao, $username_conexao, $password_conexao) or trigger_error(mysql_error(),E_USER_ERROR);
?>

Viewing all articles
Browse latest Browse all 14700

Trending Articles