Forums

Change data table afterwards? (add more fields)

moontear 05 Jan, 2008
Hello there,

great product you have! How is it possible to change the data table after already connecting the form to a table?

Can I simply delete some columns via phpMyAdmin? How do I not loose data but edit the form e.g. delete a form field or change which fields get entered in the database table?

Sincerely,
moon
GreyHead 05 Jan, 2008
Hi moon,

You can edit both the table and the form. But at present you have to do it by hand and take some care! (Back up first!)

The important thing is to keep the form structure in MySQL and the Autogenerated code in ChronoForms lined up.

The default structure for Autogenerated code is like this:
<?php 
lobal $database;
	
$database->setQuery( "INSERT INTO #__chronoforms_2 VALUES  (
'' , '". date('Y-m-d')." - ".date("H:i:«»s"«»)."', '".$_SERVER['REMOTE_ADDR']."' , '".$_POST['name']."' , '".$_POST['email']."');" );
if (!$database->query()) {
echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>
";
}
?>
It will probably help to re-write the query into a SET format like:
<?php 
global $database;
$sql = "
  INSERT 
    INTO #__chronoforms_2 
    SET recordtime ='". date('Y-m-d')." - ".date("H:i:«»s"«»)."',
        ipaddress = '".$_SERVER['REMOTE_ADDR']."' ,
        name = '".$_POST['name']."' ,
        email = '".$_POST['email']."');";
$database->setQuery( $sql );
if (!$database->query()) {
echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>
";
}
?>
This makes it easier to add fields and be clear which form values are being assigned to them.

Bob
moontear 05 Jan, 2008
Thank you very much, I thought it would be more hard.

So all I have to do is delete column XXX via phpMyAdmin and delete " XXX = '".$_POST['XXX']."' from the autogenerated code.

Very quick reply!
GreyHead 05 Jan, 2008
Hi moon,

Yes, but you won't find XXX = '".$_POST['XXX']."' in the default autogenerated code - just '".$_POST['XXX']."'. Take a backup copy and check that you've deleted the correct value.

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