Php > Databases sample source codes
Tired to edit forms this simple script will edit or update ANY MySQL database
Tired to edit forms this simple script will edit or update ANY MySQL database /* USE : generik.php3?db=BASE&table=TABLE&kn=USED_INDEX_NAME&key=ID_OF_INDEX */ echo " " ; $mysql_link = mysql_connect("localhost", $db, "PUT YOUR PASSWORD HERE "); mysql_select_db($db, $mysql_link); function BZ_ShowSet ( $row_table_def , $data ) { $field = $row_table_def["Field"]; $set = str_replace("set(", "", $row_table_def["Type"]); $set = ereg_replace("\)$", "", $set); $set = explode (",", $set ) ; for ($vals = explode(",", $data); list($t, $k) = each($vals);) { $vset[$k] = 1; } $size = min(4, count($set)); for ($j=0; $j
".htmlspecialchars(substr($set[$j], 1, -1))."
\n"; } } function BZ_ShowEnum ( $row_table_def , $data ) { $field = $row_table_def["Field"]; $set = str_replace("enum(", "", $row_table_def["Type"]); $set = ereg_replace("\)$", "", $set); $set = explode (",", $set ) ; echo "
\n"; echo "
\n"; for ($j=0; $j
".htmlspecialchars(substr($set[$j], 1, -1))."\n"; } echo "
"; } function BZ_CalcSet ($setName ) { $out = 0 ; $bitVal = 1 ; for ( $bit = 0 ; $bit < 64 ; ++$bit ) { $theGlobalName = $setName.$bit ; eval ( "global $"."$theGlobalName ; " ) ; $theString = "$"."thevalue = $".$theGlobalName.";" ; eval ( $theString ); if ( $thevalue ) { $out |= $bitVal ; } ; $bitVal<<= 1; } return $out ; } /* START */ $table_def = mysql_db_query($db , "SHOW FIELDS FROM $table") ; if (isset($action)) { if ( $table_def ) { if( $action =="update" ) $query =" UPDATE $table SET " ; if( $action =="write" ) $query =" INSERT into $table VALUES ( " ; $virgule = "" ; for ($i=0;$i
Success " ; } else { echo "
Wrong query
" ; } echo $query ; exit ; } if (isset($kn)) { $result = mysql_db_query($db, "SELECT * FROM $table WHERE $kn = '$key' "); $row = mysql_fetch_array($result); } else { $result = mysql_db_query($db, "SELECT * FROM $table LIMIT 1"); } if (!$table_def) { exit(); } else { echo "
"; echo "
Edit a ". $table ." record on database ".$db."
"; echo "
"; ?>
' ; echo '
' ; echo '
' ; } else { echo '
' ; } echo "\n" ; echo "
" ; echo "\n" ; for ($i=0;$i
". ereg_replace ("_"," ", $field ). "
\n"; } switch (ereg_replace("\\(.*", "", $row_table_def['Type'])) { case "set": $type = "set"; break; case "enum": $type = "enum"; break; default: $type = $row_table_def['Type']; break; } if (isset($row) && isset($row[$field])) { $special_chars = htmlspecialchars($row[$field]); $data = $row[$field]; } /******** HERE you have to check for some condition to HIDE some fields *****/ if( ! ereg ("ID" , $field ) ) { echo "
" ; if (strstr($row_table_def["Type"], "text")) { echo "
$special_chars\n"; } elseif (strstr($row_table_def["Type"], "enum")) { BZ_ShowEnum ( $row_table_def , $data ) ; } elseif (strstr($row_table_def["Type"], "set")) { BZ_ShowSet ( $row_table_def , $data ) ; } else { $len = ($len>40)? 40 : $len ; echo "
"; } echo "
\n"; } else { echo "
"; } } echo "
\n"; } echo "
\n
\n
\n \n" ; ?>
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage