Foros del Web » Programando para Internet » PHP »

Actualizar dos tablas con un solo envio de formulario

Estas en el tema de Actualizar dos tablas con un solo envio de formulario en el foro de PHP en Foros del Web. Hola a todos. Estoy usando el programa Dreamweaver CS3 asi que para actualizar una tabla en una base de datos al enviar un formulario solo ...
  #1 (permalink)  
Antiguo 12/04/2010, 13:59
 
Fecha de Ingreso: agosto-2009
Mensajes: 12
Antigüedad: 14 años, 8 meses
Puntos: 0
Actualizar dos tablas con un solo envio de formulario

Hola a todos. Estoy usando el programa Dreamweaver CS3 asi que para actualizar una tabla en una base de datos al enviar un formulario solo tengo que hacer unos clicks y listo..

El problema que con la Opcion "Actualizar registro" me funcionaba bien cuando queria modificar una tabla. Ahora tengo dos tablas: Productos (id_producto, nombre, categoria) y Categoria (id_categoria, descripcion, categoria-seria el titulo de categoria). Cuando inserto nuevos productos tengo que seleccionar la categoria. Supongamos que inserte 100 productos de los cuales 80 tienen la categoria "Aventura". Pero si yo ahora quiero modificar la categoria "Aventura" por "Turismo y aventura"... deberia actualizar las dos tablas ya que si por un lado me actualiza el campo categoria de la tabla categoria tambien quiero que me actualize la categoria de esos 80 productos que tienen esa categoria.

Hasta ahora me actualiza la tabla categoria pero no logro que me actualize los 80 productos de la tabla productos.


Esta es la funcion GetSQLValueString que hace el dreamweaver (creo..)

Código PHP:
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$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;
}


He tratado de usar la "funcion replace" pero soy re newbie asi que no funca
Ademas aqui es donde tengo el problema ya que me sale un error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\TAREA 20\panel\ed_cat.php on line 43

Código PHP:
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
[
COLOR="Red"]/*linea 43*/[/COLOR]  $updateSQL "UPDATE productos SET categoria= REPLACE(categoria,'$row_ed_cat['categoria']','%s' 
  WHERE categoria LIKE %%s%, GetSQLValueString($_POST['categoria'], "
text"),
                       GetSQLValueString($_POST['categoria'], "
text")"


Esto si anda

Código PHP:
  mysql_select_db($database_prueba$prueba);
  
$Result1 mysql_query($updateSQL$prueba) or die(mysql_error());

  
$updateGoTo "ver_cat.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$updateGoTo .= (strpos($updateGoTo'?')) ? "&" "?";
    
$updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$updateGoTo));
}

if ((isset(
$_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  
$updateSQL sprintf("UPDATE categoria SET descripcion=%s, categoria=%s WHERE id_categoria=%s",
                       
GetSQLValueString($_POST['descripcion'], "text"),
                       
GetSQLValueString($_POST['categoria'], "text"),
                       
GetSQLValueString($_POST['id_categoria'], "int"));

  
mysql_select_db($database_prueba$prueba);
  
$Result1 mysql_query($updateSQL$prueba) or die(mysql_error());

  
$updateGoTo "ver_cat.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$updateGoTo .= (strpos($updateGoTo'?')) ? "&" "?";
    
$updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$updateGoTo));
}

$colname_ed_cat "-1";
if (isset(
$_GET['id_categoria'])) {
  
$colname_ed_cat $_GET['id_categoria'];
}
mysql_select_db($database_prueba$prueba);
$query_ed_cat sprintf("SELECT * FROM categoria WHERE id_categoria = %s"GetSQLValueString($colname_ed_cat"int"));
$ed_cat mysql_query($query_ed_cat$prueba) or die(mysql_error());
$row_ed_cat mysql_fetch_assoc($ed_cat);
$totalRows_ed_cat mysql_num_rows($ed_cat); 
Si me pueden ayudar o quiren el html por fa diganme porque me gustaria saber como solucionar esto... Gracis

Etiquetas: actualizar, registros, replace, update
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:31.