Creating Database Table

Hi together, I’m tryin’ to create tables in my database.

    <section class="left">
<h2>Anmeldung <?php echo $page->parent()->title(); ?></h2>
<?php
	// abschicken und best&auml;tigungs erstellung
if (($inhalt_name) && ($inhalt_vorname) && ($inhalt_mail) && ($inhalt_ort) && ($sende_button)){

	$db = new Database(array(
	  'type'     => 'mysql',
	  'host'     => 'localhost',
	  'database' => 'xxx',
	  'user'     => 'xxx',
	  'password' => 'gVg$xxx'
	)); 
	
	$table = str_replace ($search, '_' , ($page->parent()->title()));
	
	database::createTable($table, $columns = array(ID , Nachname , Vorname , Ort , Bootsklasse , Verein , Vorschoter));
																			
	$users = $db->table(str_replace ($search, '_' , ($page->parent()->title())));
	
	if($id = $users->insert(array(
	  'Nachname' => $inhalt_name,
	  'Vorname' => $inhalt_vorname,
	  'Ort' => $inhalt_ort,
	  'Bootsklasse' => $inhalt_bootsklasse,
	  'Verein' => $inhalt_verein,
	  'Vorschoter' => $inhalt_vorschoter 
	))) {
	  echo '<p>Eintragung in die Datenbank erfolgreich. Sie sind der ' . $id .'. Teilnehmer.</p>';
	}
	
	$email = new Email(array(
	  'to'      => 'tommy@nasse-design.de',
	  'from'    => 'tommy@nasse-design.de',
	  'subject' => 'Anmeldung '.$page->parent()->title(),
	  'body'    => 'Folgende Anmeldung wurde abgegeben und in die Datenbank' . $page->parent()->title().'eingetragen: ' . $alle_Inhalte
	));
	
	if($email->send()) {
	  echo '<p>Die Email wurde erfolgreich versendet.</p>';
	} else {
	  echo $email->error()->message();
	}
	
	unset($inhalt_name, $inhalt_vorname, $inhalt_mail, $inhalt_remail, $inhalt_str, $inhalt_plz, $inhalt_ort, $inhalt_fon, $inhalt_geb, $inhalt_text, $inhalt_jahrgang, $inhalt_land, $inhalt_vorschoter, $inhalt_segelnummer, $inhalt_bootsklasse, $inhalt_verein, $inhalt_teilnehmer, $inhalt_wohnmobil, $sende_button);
} else {
?>

Anyone an Idea whatI did wrong? Is it the columns array?

Or just how to get “database::createTable('test', $columns = array('ID', 'Nachname'));” working… tested 10 different ways :confused:

The correct way to do this would be:


  $db->createTable($table, array(
    'id' => array(
      'type' => 'id',
    ),
    'nachname' => array(
      'type' => 'text',
    ),
    'vorname' => array(
      'type' => 'text',
    ),
    'ort' => array(
      'type' => 'text',
    ),
    'bootsklasse' => array(
      'type' => 'text',
    ),
    'verein' => array(
      'type' => 'text',
    ),
    'vorschoter' => array(
      'type' => 'text',
    ),
  ));

1 Like

Thanks alot! Works great, didnt want to write it in normal PHP, glad it works now :slight_smile: