note 54061 deleted from function.mysql-list-fields by betz

From: Date: Thu, 23 Jun 2005 06:45:53 +0000
Subject: note 54061 deleted from function.mysql-list-fields by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-90814@lists.php.net to get a copy of this message
Note Submitter: G_UNIT_RULES_U at hotmail dot com Reason: bad code ---- This is this "connect.php" file that makes the connection to your mysql database. DO NOT change the variables or the filename ONLY the values": <? $db_name = "babesquad_db"; $connection = mysql_connect("localhost","root"); mysql_select_db($db_name,$connection)or die(mysql_error()); ?> This is this *.php file that makes the values out of the database visible and gives you the ability change your records: <HEAD> <LINK href=basic/style.css type=text/css rel=stylesheet> </HEAD> <TABLE class=thinline cellSpacing=0 cellPadding=1 rules=none> <TBODY> <TR> <TD align=middle colSpan=100% background=basic/topic.gif><B>Control Center</B></TD></TR> <TR><TD bgColor=black colSpan=100% height=2></TD></TR> <TR><TD><CENTER> <FORM> <TR><TD>choose:</TD> <TD><SELECT name=table> <? //makes a connection with mysql include("connect.php"); If($db_name) { //puts all tables from the selected database a result variable called tables $tables = mysql_list_tables($db_name); //marks the selected tabel in your choice list If($table){ echo "<OPTION value=$table>:::$table:::</FONT>";} //prints all available tables out of the tables variable in a choice list for ($table_nr = 0; $table_nr < mysql_num_rows($tables ); $table_nr++) printf ("<OPTION>".mysql_tablename($tables,$table_nr)); //Makes a submit button to send the given variables echo "</TD><TD><INPUT type=submit name=submit value=Send></TD></TR>"; } If($db_name && $table) { //changes selected records with your given variables mysql_query("UPDATE $table SET $column='$value' WHERE $col='$val'"); //makes the 1st choice list for the columns out of the table echo "<TR><TD>where column:</TD>"; echo "<TD><SELECT name=col>"; //All columns out of the selected table will be put in the colums variable $columns = mysql_query("SELECT * FROM $table")or die(mysql_error()); //The nr of columns is counted en then saved in a variabel called nr_of_columns $nr_of_columns = mysql_num_fields($columns ); //All columns out of the selected table are pinted in a choice list for ($column_nr = 0; $column_nr < $nr_of_columns; ++$column_nr){ printf("<OPTION>". mysql_field_name($columns, $column_nr)); } //makes a 2nd choice list for the columns out of the table echo "</TD>"; echo "<TD>change column:</TD>"; echo "<TD><SELECT name=column>"; //All columns out of the selected are pinted in a 2nd choice list for ($column_nr = 0; $column_nr < $nr_of_columns; ++$column_nr){ printf("<OPTION>". mysql_field_name($columns, $column_nr)); } //end the choice list and creates a new row for textboxes echo "</TD></TR><TR>"; //makes de 1st textbox for kolomnr 1 echo "<TD>value:</TD><TD><INPUT type=text name=val></TD>"; //makes de 1st textbox for kolomnr 2 echo "<TD>value:</TD><TD><INPUT type=text name=value></TD></TR>"; //ends the choice list and the form echo "</FORM>"; echo "</CENTER></TD></TR></TBODY></TABLE>"; //einde van If(table) voor control centre gedeelte } If($db_name && $table) { //Puts the names of all the columns in the visible table echo "<TABLE border=1>"; for ($column_nr = 0; $column_nr < $nr_of_columns; ++$column_nr){ echo "<TH>". mysql_field_name($columns, $column_nr)."</TH>"; } echo"</TR><TR>"; //Puts the names of all the values in the visible table while($column_values = mysql_fetch_array($columns)) { for ($column_nr = 0; $column_nr< $nr_of_columns; ++$column_nr){ echo "<TD>".$column_values[mysql_field_name($columns, $column_nr)]."</TD>"; } echo "</TR><TR>"; } } //closes the mysql connection mysql_close(); ?>

« previous php.notes (#90814) next »