Jump to content

Help with function and some code.


Darkmatter5

Recommended Posts

I have the following functions in my code:

 

function client_list($tabindex) {
  include 'library/dbconfig.php';
  include 'library/opendb.php';
  $query="SELECT client_id, first_name, last_name, company_name
    FROM byrnjobdb.clients
    ORDER BY last_name ASC, first_name ASC, company_name ASC";
  $result=mysql_query($query);
  echo "<select name='client' method='get' tabindex='" .$tabindex. "'>";
  echo "<option>---Select---</option>";
  while ($row=mysql_fetch_array($result)) {
    $r1=$row['client_id'];
    if(empty($row['company_name'])) {
      $r2=$row['last_name']. ", " .$row['first_name']. "(" .$r1. ")";
    } else {
      $r2=$row['last_name']. ", " .$row['first_name']. " of " .$row['company_name']. "(" .$r1. ")";
    }
    echo "<option value='$r1'>$r2</option>";
  }
  echo "</select>";
  include 'library/closedb.php';
}

function current_client($client_id, $field) {
  include 'library/dbconfig.php';
  include 'library/opendb.php';
  $query="SELECT $field
    FROM byrnjobdb.clients
    WHERE client_id =" .$client_id;
  $result=mysql_query($query);
//$value=mysql_fetch_array($result);
/*if(!isset($client_id) || !isset($field)) {
    echo " ";
  } else {
    echo $value[$field];
  }*/
  echo $query;
  include 'library/closedb.php';
}

 

Now on my page I have the following code

 

<?php $byrndb->client_list(2); ?> <form><input type="button" onclick="history.go(0)" value="Load record" /></form>
<?php $byrndb->current_client($_GET['client'],first_name); ?>

 

As you can see currently the code outputs the $query variable so I can troubleshoot, the current output I'm getting is "SELECT first_name FROM byrnjobdb.clients WHERE client_id =". Why is the $client_id variable not being populated?

 

Thanks!

 

 

Link to comment
https://forums.phpfreaks.com/topic/116210-help-with-function-and-some-code/
Share on other sites

Interesting. Okay here's some more code, that might explain more. The two lines of code

 

<?php $byrndb->client_list(2); ?> <form><input type="button" onclick="history.go(0)" value="Load record" /></form>
<?php $byrndb->current_client($_GET['client'],first_name); ?>

 

actually are contained in a form tag, I didn't think to include all of that code in my example. The code they are contained in is.

 

<form method=post"></form>

 

So if the client_list() function creates a select list with a get method while the function is run inside a form with a post method would I use $_POST['client'] or $_GET['client']? Should I remove the get method from the client_list() function as the select list will be inside a post form anyways? What should I do?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.