Not wanting to reinvent the wheel here, but an excersize for me. Mysql backend, wanting to perform an insert in ANY table. Files are...
index.php:
include "list_dbs.php";
hup.php:
$host = "localhost";
$user = "root";
$pass = "root";
$conn = mysql_connect ($host, $user, $pass);
list_dbs.php:
include "hup.php";
$db_list = mysql_list_dbs($conn);
echo "Choose a Database on '$host':<p>\n";
while ($db_row = mysql_fetch_object($db_list))
{
if ($db_row->Database)
{
$db = $db_row->Database;
echo "<a href = 'list_tables.php?db=$db'>";
echo $db_row->Database . "</a><br>\n";
}
}
list_tables.php:
include "hup.php";
$table_list = mysql_list_tables ($db);
echo "Back to DB List on <a href='list_dbs.php'>'$host'</a><p>\n";
echo "Choose a Table in '$db':<p>\n";
$i = 0;
while ($i < mysql_num_rows ($table_list))
{
$tb_names[$i] = mysql_tablename ($table_list, $i);
echo"<a href='action.php?db=$db&table=$tb_names[$i]'>$tb_names[$i]</a><BR>";
$i++;
}
action.php:
echo "Back to Table List on <a href='list_tables.php?db=$db'>'$db'</a><p>\n";
echo "Choose an Action for table '$table':<p>\n";
echo "<a href='select.php?db=$db&table=$table'>select</a>\n";
echo "<a href='insert_form2.php?db=$db&table=$table'>insert</a>\n";
echo "<a href='update.php'>update</a>\n";
echo "<a href='delete.php'>delete</a>\n";
NOW THE FUN PART!(excuse the comments etc, it'll get it cleaned up)
insert_form.php:
include "hup.php";
$query = "Select * from $table";
$result = mysql_db_query ($db,$query,$conn) or die ("Query failed");
echo "Back to Actions for table <a href='action.php?db=$db&table=$table'>'$table'</a><p>\n";
echo "<form method=\"POST\" action=\"insert.php?db=$db&table=$table\">\n";
echo "<input type=\"hidden\" name=\"db\" value=\"$db\">\n";
echo "<input type=\"hidden\" name=\"table\" value=\"$table\">\n";
echo "<table border='1'>\n";
$i = 0;
while ($i < mysql_num_fields ($result))
{
$meta = mysql_fetch_field ($result);
//$q1=array();
{
//$q1[$q]="$meta->name";
//echo $q1[$q], "<br>";
$var1 = $meta->name;
$var2 = "$";
$var3 = $var2 . $var1;
//echo $var3;
//echo "<input type=\"hidden\" name=\"test\" value=\"$var3\">";
$i++;
}
{
echo "<tr><td>$var1</td><td><input type=\"text\" name=\"$var1\" size=\"40\"></td></tr>\n";
}
}
mysql_free_result ($result);
echo "</table><p>\n";
echo "<br>";
echo "<input type=\"submit\" value=\"Go!\">\n";
//as you can see i'm trying all kinds of stuff
insert.php:
echo "Back to Actions for table <a href='insert_form2.php?db=$db&table=$table'>$table</a><p>\n";
echo $bd;nada
echo $title;it works
//an insert statement once i get past this
Q:
is an array with vars convered to strings needed to display the text box results, http_post_vars or what? I just want to see the results displayed, ill create the insert statement next. one step at a time for me! this shouldn't be unique. just need an idea, any help would be great. sorry for the long post.
Thanks,
Brian