Re: Passing mysql table names to php functions?
- From: "J.O. Aho" <user@xxxxxxxxxxx>
- Date: Wed, 28 Feb 2007 09:18:14 +0100
kennthompson@xxxxxxxxx wrote:
function fms_get_table($tableName, $label, $name, $var)I assume thise functions do not have anything to do with the mysql, but echos table-tags like <tr>, <td> and so on.
{
if (is_array($var))
{
$var = $var[$name];
}
fms_open_table_row();
fms_open_table_col();
echo "$label:";You have the wrong quote type for the table name, and for debugging I would use a string to store the query (note: ' != `):
fms_close_table_col();
fms_close_table_row();
echo "<SELECT size=1 name=project>\n";
$result2 = fms_mysql_query("SELECT * FROM '{$tableName}'");
$query = "SELECT * FROM `{$tableName}`";
echo $query."<br>\n";
$result2 = fms_mysql_query($query);
echo mysql_error();
if ($result2)
{
$row2 = mysql_fetch_array($result2);
if (strlen($row2["projectName"]) > 0)
{
echo "<OPTION VALUE=" . $row2["keyid"] . ">" .
$row2["projectName"] . "\n";
}
}
else
{
echo "<option> \n";
}
$result2 = fms_mysql_query("select * from '{$tableName}' order by
keyid asc");
Wrong quite type around the table name again, use ``, not ''
for ($i = 0; $i < mysql_num_rows($result2); $i++)
{
$row2 = mysql_fetch_array($result2);
if (strlen($row2["projectName"]) > 0)
{
echo "<OPTION VALUE=" . $row2["keyid"] . ">" .
$row2["projectName"] . "\n";
}
}
echo "</SELECT>\n";
fms_close_table_col();
fms_close_table_row();
}
/* Calling script: an edit form */
$query = "select * from $tableFields where keyid = '$keyid'";
$result = mysql_query($query);
if ($result)
{
$row = mysql_fetch_array($result);
}
fms_break(1);
fms_open_center();
fms_open_form("edit", "updateField.php", "post");
fms_open_table(0, "#eeeeee", "", 2, 2);
fms_hidden("keyid", $row);
fms_get_table($tableTarget, "Project", "project", $row);
As it looks here, the $tableTarget is an empty variable, which would lead to a "SELECT * FROM ", which generates in an error message from the mysql server, you don't see it as you don't check your values and report about failure, you shouldn't assume that a function will always work.
fms_get_value("Label", "label", 60, $row);
fms_get_value("Field", "field", 60, $row);
fms_get_value("Type", "type", 60, $row);
fms_get_value("Parameters", "parameters", 60, $row);
fms_get_value("Attributes", "attributes", 60, $row);
fms_get_value("Extra", "extra", 60, $row);
fms_get_value("FMS", "fms", 60, $row);
fms_get_value("Cols", "cols", 10, $row);
fms_get_value("Rows", "rows", 10, $row);
fms_close_table();
fms_break(1);
fms_submit("UPDATE");
fms_submit("DELETE");
fms_submit("DUPLICATE");
fms_close_form();
fms_close_center();
/* mysql connection */
$host = "localhost";
$user = "";
$password = "";
$database = "";
$tableTarget = "php_generator_targets";
$tableFields = "php_generator_data_fields";
$link = mysql_pconnect( $host, $user, $password );
You may want to use mysql_connect() instead, pconnect works ok if there is a low activity and the same database is used all the time.
if(!$link)
{
echo "Did not connect.";
}
else
{
mysql_select_db($database);
if(mysql_errno())
{
echo mysql_errno() . ":" . mysql_error();
exit;
}
}
/* Main */
A shell gets the mysql connection, and manipulates the display. The
edit form tried to extract information from another table. It works
fine if I write a piece of code for each call, but I want the same
function to work for a number of database tables. But when I tried
passing the table name -- to my surprise it did not work. I've tried
numerous variations without success.
Check that the variable with the table name isn't an array.
--
//Aho
.
- References:
- Passing mysql table names to php functions?
- From: kennthompson
- Re: Passing mysql table names to php functions?
- From: Jose da Silva
- Re: Passing mysql table names to php functions?
- From: kennthompson
- Re: Passing mysql table names to php functions?
- From: J.O. Aho
- Re: Passing mysql table names to php functions?
- From: kennthompson
- Re: Passing mysql table names to php functions?
- From: J.O. Aho
- Re: Passing mysql table names to php functions?
- From: kennthompson
- Passing mysql table names to php functions?
- Prev by Date: Re: Sessions not working. Used to work fine.
- Next by Date: Re: Which php debugger do you use?
- Previous by thread: Re: Passing mysql table names to php functions?
- Next by thread: Form input data
- Index(es):
Relevant Pages
|