All pastes #383121 Raw Edit

Something

public text v1 · immutable
·published 2007-03-06 03:29 UTC
rendered paste body
<?
//********** PHP Area **********
//add_records.php
include ("inc/login.inc");

//the database you want to use
$db_name =$_POST["db_name"];

//the table you want to use
$tb_name = $_POST["table_name"];


//connect to database
$connection = @mysql_connect("localhost",$uname,$pw) or die(mysql_error());

$db = @mysql_select_db($db_name,$connection) or die(mysql_error());

//create the SQL query

$sql ="SELECT * FROM $tb_name";

//execute the query

$result = mysql_query ($sql,$connection) or die (mysql_error());

//==========begin creating fields form for data entry ==========

$form_block ="
<form name=\"frmFields\" method=\"post\" action=\"addRecordProcess.php\">
<table cellspacing=5 cellpadding=5>
<tr bgcolor=lightblue>
<th>Field Name</th>
<th>Data Type</th>
<th>Length</th>
<th>Field Flag</th>
<th>Format</th>
<th>Enter Value</th>
</tr>
";

$field_count = mysql_num_fields ($result);

for ($i =0;$i < $field_count;$i++)
{
	$field_name = mysql_field_name ($result, $i);  //capture field name
	$field_type = mysql_field_type ($result, $i);  //capture field data type
	$field_type = strtoupper ($field_type);
	$field_flags = mysql_field_flags($result, $i);  //capture other field info
	$field_flags = strtoupper ($field_flags);
	$field_len = mysql_field_len ($result, $i);

	if (strstr($field_flags, "AUTO_INCREMENT"))
		$format = "Auto Incr. Field";
	elseif (strstr($field_type, "DATE"))
		$format = "yyyy-mm-dd";
	else
		$format = "";

	if (strstr($field_flags, "PRIMARY_KEY"))
		$field_flags = "PRIMARY KEY";


	//add to the form,one row for each field
	$form_block .="
	<tr>
	<td align=center bgcolor=tan><input type=\"text\" value =\"$field_name\" size=\"15\" readonly></td>
	<td align=center><input type=\"text\" value =\"$field_type\" size=\"5\" readonly></td>
	<td align=center><input type=\"text\" value =\"$field_len\" size=\"5\" readonly></td>
	<td align=center><input type=\"text\" value =\"$field_flags\" size=\"15\" readonly></td>
	<td align=center><input type=\"text\" value =\"$format\" size=\"15\" readonly></td>
	<td align=center bgcolor=tan><input type=\"text\" size=\"20\" name=\"field_value\" ></td>
<!-- capture and transfer names of DB and Table for the next step -->
	<td align=center><input type=\"hidden\" value =\"db_name\" size=\"15\" readonly></td> 
	<td align=center><input type=\"hidden\" value =\"table_name\" size=\"15\" readonly></td>
	<td align=center><input type=\"hidden\" value =\"$db_name\" size=\"15\" readonly></td>
	<td align=center><input type=\"hidden\" value =\"$tb_name\" size=\"15\" readonly></td>

	</tr>
	";

}


//finish up the form
$form_block .="
<tr>
<td align=center colspan=6 bgcolor=yellow> After inserting this record, do you want to insert another record?
<input type=\"radio\" name=\"another\" value=\"y\">YES
<input type=\"radio\" name=\"another\" value=\"n\" checked>NO
</td>
</tr>
<tr>
<td align=center colspan=6>
		<input type=\"button\" value=\"Return to Main Menu\" onclick=\"window.location='mainmenu.htm';\">
		<input type=\"reset\" value=\"Reset\">
		<input type=\"submit\" value=\"Add Record\">
</td>
</tr>
</table>
</form>
";

?>

<!---------- HTML Area ---------->
<html>
<head>
<title>Add Records: step 2</title>


</head>
<body>
	<h1>Step 2: Add Records</h1>
	<h3> Table Name: <? echo "\"$tb_name\""; ?> <br>
	    Database Name: <? echo "\"$db_name\""; ?>
	</h3>
	<? echo "$form_block"; ?>

</body>
</html>