Forums

insert data in existing database with field check

webatwork 04 Sep, 2009
Hi there

I have a form that writes the values into an existing database. Works fine when you would like to create new rows.

But now I want the form to write the values into existing rows.
All the necessary fields are set.

In my autogenerated code I have the following
<?php 
	global $database;
	
	srand((double)microtime()*10000);
	$inum	=	"I" . substr(base64_encode(md5(rand())), 0, 16);
	
	
$database->setQuery( "INSERT INTO #__chronoforms1 VALUES
('', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '".mosGetParam($_POST,'A','')."', '".mosGetParam($_POST,'B','')."', '".mosGetParam($_POST,'C ','')."', '', '".mosGetParam($_POST,'D','')."');" );
if (!$database->query()) {
echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>
";
}
?>
I would like the form to write away A, B, C and D but D has to equal the existing field ID

What should I add?
GreyHead 05 Sep, 2009
Hi webatwork,

This looks like an old version of ChronoForms running on Joomla 1.0??

If you want to update an existign record then you need with to use the MySQL REPLACE or UPDATE syntax, INSERT will insert a new record.

Bob
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger