*** empty log message ***
[phpmyadmin/crack.git] / tbl_addfield.php3
blob7f70e7240138697959ecaa36bda51beae7bb4f5c
1 <?php
2 /* $Id$ */
5 /**
6 * Get some core libraries
7 */
8 require('./grab_globals.inc.php3');
9 require('./header.inc.php3');
12 /**
13 * The form used to define the field to add has been submitted
15 if (isset($submit)) {
16 $query = '';
18 // Builds the field creation statement and alters the table
19 for ($i = 0; $i < count($field_name); ++$i) {
20 $query .= backquote($field_name[$i]) . ' ' . $field_type[$i];
21 if ($field_length[$i] != ''
22 && !eregi('^(DATE|DATETIME|TIME|TINYBLOB|TINYTEXT|BLOB|TEXT|MEDIUMBLOB|MEDIUMTEXT|LONGBLOB|LONGTEXT)$', $field_type[$i])) {
23 if (get_magic_quotes_gpc()) {
24 $query .= '(' . stripslashes($field_length[$i]) . ')';
25 } else {
26 $query .= '(' . $field_length[$i] . ')';
29 if ($field_attribute[$i] != '') {
30 $query .= ' ' . $field_attribute[$i];
32 if ($field_default[$i] != '') {
33 if (strtoupper($field_default[$i]) == 'NULL') {
34 $query .= ' DEFAULT NULL';
35 } else if (get_magic_quotes_gpc()) {
36 $query .= ' DEFAULT \'' . sql_addslashes(stripslashes($field_default[$i])) . '\'';
37 } else {
38 $query .= ' DEFAULT \'' . sql_addslashes($field_default[$i]) . '\'';
41 if ($field_null[$i] != '') {
42 $query .= ' ' . $field_null[$i];
44 if ($field_extra[$i] != '') {
45 $query .= ' ' . $field_extra[$i];
48 if ($after_field != '--end--') {
49 // Only the first field can be added somewhere else than at the end
50 if ($i == 0) {
51 if ($after_field == '--first--') {
52 $query .= ' FIRST';
53 } else {
54 if (get_magic_quotes_gpc()) {
55 $query .= ' AFTER ' . backquote(stripslashes(urldecode($after_field)));
56 } else {
57 $query .= ' AFTER ' . backquote(urldecode($after_field));
60 } else {
61 if (get_magic_quotes_gpc()) {
62 $query .= ' AFTER ' . backquote(stripslashes($field_name[$i-1]));
63 } else {
64 $query .= ' AFTER ' . backquote($field_name[$i-1]);
68 $query .= ', ADD ';
69 } // end for
70 $query = ereg_replace(', ADD $', '', $query);
72 $sql_query = 'ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' ADD ' . $query;
73 $result = mysql_query($sql_query) or mysql_die();
75 // Builds the primary keys statements and updates the table
76 $primary = '';
77 if (isset($field_primary)) {
78 for ($i = 0; $i < count($field_primary); $i++) {
79 $j = $field_primary[$i];
80 $primary .= backquote($field_name[$j]) . ', ';
81 } // end for
82 $primary = ereg_replace(', $', '', $primary);
83 if (!empty($primary)) {
84 $sql_query .= "\n" . 'ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' ADD PRIMARY KEY (' . $primary . ')';
85 $result = mysql_query('ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' ADD PRIMARY KEY (' . $primary . ')') or mysql_die();
87 } // end if
89 // Builds the indexes statements and updates the table
90 $index = '';
91 if (isset($field_index)) {
92 for ($i = 0; $i < count($field_index); $i++) {
93 $j = $field_index[$i];
94 $index .= backquote($field_name[$j]) . ', ';
95 } // end for
96 $index = ereg_replace(', $', '', $index);
97 if (!empty($index)) {
98 $sql_query .= "\n" . 'ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' ADD INDEX (' . $index . ')';
99 $result = mysql_query('ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' ADD INDEX (' . $index . ')') or mysql_die();
101 } // end if
103 // Builds the uniques statements and updates the table
104 $unique = '';
105 if (isset($field_unique)) {
106 for ($i = 0; $i < count($field_unique); $i++) {
107 $j = $field_unique[$i];
108 $unique .= backquote($field_name[$j]) . ', ';
109 } // end for
110 $unique = ereg_replace(', $', '', $unique);
111 if (!empty($unique)) {
112 $sql_query .= "\n" . 'ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' ADD UNIQUE (' . $unique . ')';
113 $result = mysql_query('ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' ADD UNIQUE (' . $unique . ')') or mysql_die();
115 } // end if
117 // Go back to table properties
118 $message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenAltered;
119 include('./tbl_properties.php3');
120 exit();
121 } // end do alter table
124 * Displays the form used to define the new field
126 else{
127 $action = 'tbl_addfield.php3';
128 include('./tbl_properties.inc.php3');
130 // Diplays the footer
131 echo "\n";
132 include('./footer.inc.php3');