Forums

database update

mja1356 09 Jun, 2008
Hi
I have a form to edit and update data.this form retrieve data from database and i can change the fields to new value.
in form html code i use the code to retrieve data.how can i put appropriate code to update the database.thoi trang be trai cap cap, thoi trang cho be, may hut sua, do ngu nam, bon bon, ao lot nu, paltal, ban buon quan ao, thoi trang cong so, vest cong so, ban buon quan ao, do lot[/url]
in normal coding i set the first form action to b.php and method:get.
and i retrieve data in first form and update in b.php.
how can i do this in CF?
is somwhere in CF setting to set the action address?
thanks
GreyHead 09 Jun, 2008
Hi Mja156,

You can set the Post/Get under 'Form method' on the General tab, and the Action by including an 'OnSubmit URL' in the Form URLs tab.

But why not just use the 'OnSubmit' boxes in ChronoForms to write the data back to the database?

Bob
mja1356 09 Jun, 2008
Hi
I put a code in form html to retrieve data from database and put them in a html table to edit them and use a submit button in the end of table.
Now i want to update data with new entry that filled in table.
As you said I put this code in both two submit code(before and after respectively)
<?php
//connet to MySQL server
$db = mysql_connect("localhost", "parsibet", "123456");
if(!$db)
{
     echo " Error : cannot open connection.";
     exit;
}

mysql_select_db('parsibet_parsibet');
$lineid=$_GET['cf_id'];
$query = "update jos_chronoforms_7 set category='$row[4]' where cf_id='$lineid'";
?>  

but it isn't work and after i submit the form , it create a new record and don't update the target record.
where is my mistake?
GreyHead 09 Jun, 2008
Hi mja1356,

First, you only need the code in one place.

Second, I can't see what you are doing with 'parsibet_parsibet' here. You open the database link but don't read or write anything???

Is parsibet_parsibet your Joomla db?

Is jos_chronoforms_7 a table in parsibet_parsibet, or in the Joomla db?

Bob

PS The sql query almost certainly needs '".$row[4]."' to parse correctly.
mja1356 09 Jun, 2008
Hi
I use code in one place my question is that what is right place.
and as i said i created a form that retrieve data from database with corresponding cf_id.and i put this code and a html table in form html in form code.
now suppose i open the html table and change the category to another name.
now i put this code in submit(before) to update the database to new value of category.
<?php
//connet to MySQL server
$db = mysql_connect("localhost", "parsibet", "123456");
if(!$db)
{
     echo " Error : cannot open connection.";
     exit;
}

mysql_select_db('parsibet_parsibet');
$lineid=$_GET['cf_id'];
$query = "select * from jos_chronoforms_7 where cf_id='$lineid'";

$result = mysql_query($query);
$row = mysql_fetch_row($result);
if(!mysql_affected_rows())
     echo  '<div align = "center" ><b>    there is no data</b></div>';
else
$query1 = "update jos_chronoforms_7 set category='$row[4]'"; 
    ?>

parsibet_parsibet is joomla database,jos_chronoforms_7 is table in database that stores data.
now after i change the category and press submit,the old record doesn't update and a new record with new category name will be created.
what is wrong with this code.
thanks
GreyHead 09 Jun, 2008
Hi mja1356,

If this is the joomla database then you can use the Joomla functions to access it. You have to say which record you want to update and to make sure that you set all the values in that record (I'm always a bit wary about updating records).

So your code will look more like this
<?php 

global $db;
 
$lineid = $_GET['cf_id']; 
$sql= "
  SELECT * 
    FROM #__chronoforms_7 
    WHERE cf_id = '$lineid';"; 
 
$result = $db->query($sql); 
$row    = $db->fetch_row($result); 
if ( !$db->affected_rows() ) {
  echo  '<div align="center" ><b>there is no data</b></div>'; 
} else { 
  $sql = "
    UPDATE #__chronoforms_7 
      SET category='".$row[4]."';
      WHERE XXX = 'YYY';"; 
  $result = $db->query($sql); 
} 
?>
Not tested and probably buggy!

Bob
mja1356 04 Jul, 2008
Hi after 3 weeks,
I have another question.where i put above code that you wrote?
in main html form that retrieve data from database i put that code and after i press submit button it produces another record.
GreyHead 04 Jul, 2008
Hi mja1356,

You are going to need to think carefully about where you put the code. It will probably go in one of the OnSubmit boxes but needs to work together with any AutoGenerated code.

If you are getting new entries then you probably aren't getting the WHERE clause correct.

Bob

PS In the short time I have to post replies here I can't design a whole web-form application for you.
This topic is locked and no more replies can be posted.