|
Posted by J.O. Aho on 02/28/07 08:18
kennthompson@gmail.com wrote:
> function fms_get_table($tableName, $label, $name, $var)
> {
> if (is_array($var))
> {
> $var = $var[$name];
> }
> fms_open_table_row();
> fms_open_table_col();
I assume thise functions do not have anything to do with the mysql, but echos
table-tags like <tr>, <td> and so on.
> echo "$label:";
> fms_close_table_col();
> fms_close_table_row();
> echo "<SELECT size=1 name=project>\n";
> $result2 = fms_mysql_query("SELECT * FROM '{$tableName}'");
You have the wrong quote type for the table name, and for debugging I would
use a string to store the query (note: ' != `):
$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
Navigation:
[Reply to this message]
|