Hello all -

I'm having some trouble UPDATING my mysql using php. I'm working on a event planning system; the user can click on the company to see a small report that has some areas which must be editable (payment status, etc.). I get these values into a form to display them, making them also editable, however, when I pass the values through to the next step I can't actually get my get my database to update.

I've checked to make sure that the values are passing through (using echo on the receiving page), so that's not a problem. I'm really stumped. Would be appreciative if anyone could help. Thanks!

the entry point

<!--  -->
<form action="admineconomics.php" method="post" name="admineconomics">

<table style="margin-top:1em;">
	<tbody>
	<tr>
		<td class="title" width="36%">Estado</td>
		<td style="background-color:red;color:white;font-weight:bold;"><input type="text" name="estadopago" value="<?php echo $row['estadopago'];?>"  id="estadopago" /></td>
	</tr>
	</tbody>
</table>
	<!--  -->
<table style="margin-top:1em;">
	<tbody>
	<tr>
		<td class="title">SENCE</td>
		<td style=";font-weight:bold;"><?php echo $row['sence'];?></td>
		<td></td>
	</tr>
	<tr><td></td><td></td><td></td></tr>
	<tr>
		<td></td>
		<td width="32%" class="title" style="text-align:center;"><b>Empresa</b></td>
		<td width="32%" class="title" style="text-align:center;"><b>OTIC</b></td>
	</tr>
	<tr>
		<td class="title">Nº Factura</td>
		<td><input type="text" name="nfacturaempresa" value="<?php echo $row['nfacturaempresa'];?>"  id="nfacturaempresa" /></td>
		<td><input type="text" name="nfacturaotic" value="<?php echo $row['nfacturaotic'];?>"  id="nfacturaotic" /></td>
	</tr>
	<tr>
		<td class="title">Orden Compra</td>
		<td><input type="text" name="ocempresa" value="<?php echo $row['ocempresa'];?>"  id="nfacturaotic" /></td>
		<td><input type="text" name="ocotic" value="<?php echo $row['ocotic'];?>"  id="ocotic" /></td>
	</tr>
	<tr>
		<td class="title">Monto</td>
		<td><input type="text" name="montoempresa" value="<?php echo $row['montoempresa'];?>"  id="montoempresa" /></td>
		<td><input type="text" name="montootic" value="<?php echo $row['montootic'];?>"  id="montootic" /></td>
	</tr>
	<tr>
		<td class="title">Fecha</td>
		<td><input type="text" name="fechapagoempresa" value="<?php echo $row['fechapagoempresa'];?>"  id="fechapagoempresa" /></td>
		<td><input type="text" name="fechapagootic" value="<?php echo $row['fechapagootic'];?>"  id="fechapagootic" /></td>
	</tr>

	</tbody>
</table>
<div style="display:none;"><input type="text" name="razonsocial" value="<?php echo $row['razonsocial'];?>"  id="razonsocial" /></div>
<input type="submit" value="submit" class="submit" />
</form>

the receiving end

// Start Session
	session_name('online');
	session_start();
	// Variables
	$razonsocial					=	$_POST['razonsocial'];
	
	$estadopago					= $_POST['estadopago'];
	$nfacturaempresa			= $_POST['nfacturaempresa'];
	$nfacturaotic				= $_POST['nfacturaotic'];
	$ocempresa					=	$_POST['ocempresa'];
	$ocotic							= $_POST['ocotic'];
	$montoempresa			= $_POST['montoempresa'];
	$montootic					= $_POST['montootic'];
	$fechapagoempresa		= $_POST['fechapagoempresa'];
	$fechapagootic				= $_POST['fechapagootic'];

// General Info
	$host="localhost";
	$adminname="";
	$adminpassword="";
	$db_name="";

	mysql_connect("$host", "$adminname", "$adminpassword")or die("cannot connect");
	mysql_select_db("$db_name")or die("cannot select DB");
	$query="UPDATE participantes_seminarios SET 
		id 								=		'',
		seminario					=		'',
		nombreregistrante	=		'',
		apellidopaternoregistrante	=	'',
		apellidomaternoregistrante	=	'',
		rutregistrante			=		'',
		organizacion							=		'',
		cargoregistrante			=		'',
		movilregistrante 				=		'',
		fijoregistrante 				=		'',
		correoregistrante 	sence 				=		'',
		razonsocial 				=		'',
		rutorganizacion 				=		'',
		giroorganizacion 				=		'',
		direccionorganizacion 				=		'',
		comunaorganizacion 				=		'',
		encargadofacturacion 				=		'',
		fijoencargadofacturacion 				=		'',
		correoencargadofacturacion			=		'',
		participante_1_primernombre			=		'',
		participante_1_apellidopaterno			=		'',
		participante_1_rut			=		'',
		participante_1_organizacion			=		'',
		participante_1_cargo			=		'',
		participante_1_fijo			=		'',
		participante_1_email			=		'',
		participante_2_primernombre			=		'',
		participante_2_apellidopaterno			=		'',
		participante_2_rut			=		'',
		participante_2_organizacion			=		'',
		participante_2_cargo			=		'',
		participante_2_movil			=		'',
		participante_2_fijo			=		'',
		participante_2_email			=		'',
		participante_3_primernombre			=		'',
		participante_3_apellidopaterno			=		'',
		participante_3_rut			=		'',
		participante_3_organizacion			=		'',
		participante_3_cargo			=		'',
		participante_3_movil			=		'',
		participante_3_fijo			=		'',
		participante_3_email			=		'',
		estadopago				=		'$estadopago', 
		nfacturaempresa		=		'$nfacturaempresa', 
		nfacturaotic				=		'$nfacturaotic' 
		ocempresa				=		'$ocempresa',
		ocotic						=		'$ocotic',
		montoempresa			=		'$montoempresa',
		montootic					=		'$montootic',
		fechapagoempresa	=		'$fechapagoempresa',
		fechapagootic			=		'$fechapagootic' ,
		cur_timestamp			=		''		
		WHERE razonsocial ='$razonsocial'";

	mysql_query($query);

Recommended Answers

All 2 Replies

1. make sure your variables contain quotes from both sides..for example $razonsocial="somevalue".
2. try writing like this..for example

"where razonsocial=".$razonsocial;

and if those two steps don't work, simply replace this code

mysql_query($query);

with this one

$result=mysql_query($query);
if(!$result){die("Error: ".mysql_error());}

to see what error you have

Hi kracko and thanks!

That error trick really worked (I've put it on delicious for the future!).

In the end:
- I had a few missplaced / missing commas
- I also discovered that I didn't need to include *all* of the fields, just the fields I wanted to update! (I ended actually erasing the contents of the row...!).

Thanks again!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.