Ir para conteúdo
Fórum Script Brasil
  • 0

Ajuda com relação de tabelas


Azzurra.com

Pergunta

Olá,

Eu tenho o seguinte problema:

Tenho 2 tabelas num sistema de cadastro de clientes e seus respectivos eventos, como cada cliente pode ter mais de 1 evento eu gostaria de obter uma ajuda pois fiz as tabelas da seguinte maneira:

clientes (Com os campos id_cliente e cliente)

clientes_eventos (Com os campos de id_cliente, id_evento e outos do evento)

O cadastramento do cliente e feito anteriormente ao cadastro do evento e no cadastro do evento eu inclui um list menu com os nomes de todos os clientes para selecão na hora de cadastrar o evento, eu gostaria de alimentar o campo id_cliente na tabela clientes_eventos com o id_cliente q é selecionado no list menu q vem dá tabela clientes, só q tenho encontrado diversos meios mas nenhum efetivo gostaria de uma ajuda se possivel para a resolução desse problema, segue aki meu codigo:

<?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"] == "form2")) {
  $insertSQL = sprintf("INSERT INTO clientes_eventos (tel_fixo, cel_noivo, cel_noiva, email, mot_evento, `local`, local_igreja, hora, orca_dj, orca_som_festa, orca_som_igreja, luz_pista, luz_decor_festa, valor_luz_festa, luz_decor_igreja, valor_luz_igreja, tela_tipo, vj, taxa_via, outros, dj, iluminador, indicacao, cerimonial, tel_cerimonial, num_convidados, obs, data_1_contato, data_proposta, data_confirma, data_reuniao, hora_reuniao, resp_reuniao, ligar_data) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['tel_fixo'], "text"),
                       GetSQLValueString($_POST['cel_noivo'], "text"),
                       GetSQLValueString($_POST['cel_noiva'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['mot_evento'], "text"),
                       GetSQLValueString($_POST['local'], "text"),
                       GetSQLValueString($_POST['local_igreja'], "text"),
                       GetSQLValueString($_POST['hora'], "date"),
                       GetSQLValueString($_POST['orca_dj'], "text"),
                       GetSQLValueString($_POST['orca_som_festa'], "text"),
                       GetSQLValueString($_POST['orca_som_igreja'], "text"),
                       GetSQLValueString($_POST['luz_pista'], "text"),
                       GetSQLValueString($_POST['luz_decor_festa'], "text"),
                       GetSQLValueString($_POST['valor_luz_festa'], "text"),
                       GetSQLValueString($_POST['luz_decor_igreja'], "text"),
                       GetSQLValueString($_POST['valor_luz_igreja'], "text"),
                       GetSQLValueString($_POST['tela_tipo'], "text"),
                       GetSQLValueString($_POST['vj'], "text"),
                       GetSQLValueString($_POST['taxa_via'], "text"),
                       GetSQLValueString($_POST['outros'], "text"),
                       GetSQLValueString($_POST['dj'], "text"),
                       GetSQLValueString($_POST['iluminador'], "text"),
                       GetSQLValueString($_POST['indicacao'], "text"),
                       GetSQLValueString($_POST['cerimonial'], "text"),
                       GetSQLValueString($_POST['tel_cerimonial'], "text"),
                       GetSQLValueString($_POST['num_convidados'], "int"),
                       GetSQLValueString($_POST['obs'], "text"),
                       GetSQLValueString($_POST['data_1_contato'], "date"),
                       GetSQLValueString($_POST['data_proposta'], "date"),
                       GetSQLValueString($_POST['data_confirma'], "date"),
                       GetSQLValueString($_POST['data_reuniao'], "date"),
                       GetSQLValueString($_POST['hora_reuniao'], "date"),
                       GetSQLValueString($_POST['resp_reuniao'], "text"),
                       GetSQLValueString($_POST['ligar_data'], "date"));

  mysql_select_db($database_conexao, $conexao);
  $Result1 = mysql_query($insertSQL, $conexao) or die(mysql_error());

  $insertGoTo = "../enviado.html";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}


mysql_select_db($database_conexao, $conexao);
$query_lista_clientes = "SELECT * FROM clientes";
$lista_clientes = mysql_query($query_lista_clientes, $conexao) or die(mysql_error());
$row_lista_clientes = mysql_fetch_assoc($lista_clientes);
$totalRows_lista_clientes = mysql_num_rows($lista_clientes);

mysql_select_db($database_conexao, $conexao);
$query_insert_evento = "SELECT id_cliente, tel_fixo, cel_noivo, cel_noiva, email, mot_evento, `local`, local_igreja, `data`, hora, orca_dj, orca_som_festa, orca_som_igreja, luz_pista, luz_decor_festa, valor_luz_festa, luz_decor_igreja, valor_luz_igreja, tela_tipo, vj, taxa_via, outros, dj, iluminador, indicacao, cerimonial, tel_cerimonial, num_convidados, obs, data_1_contato, data_proposta, data_confirma, data_reuniao, hora_reuniao, resp_reuniao, ligar_data, confirmado, n_confirmado, cerimonia_local, cortesia FROM clientes_eventos";
$insert_evento = mysql_query($query_insert_evento, $conexao) or die(mysql_error());
$row_insert_evento = mysql_fetch_assoc($insert_evento);
$totalRows_insert_evento = mysql_num_rows($insert_evento); 
?>

Ps.: sou iniciante em php/mysql aprendi(ou estou tentando) na marra entaum qualquer ajuda para modificações novas ideias serão bem aceitas!!!

Obrigado

Link para o comentário
Compartilhar em outros sites

0 respostass a esta questão

Posts Recomendados

Até agora não há respostas para essa pergunta

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      652k
×
×
  • Criar Novo...