Darkmatter5 Posted July 23, 2008 Share Posted July 23, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/116210-help-with-function-and-some-code/ Share on other sites More sharing options...
Darkmatter5 Posted July 23, 2008 Author Share Posted July 23, 2008 No replies yet, hmmm.... Does my situation make sense? If anyone needs clarification let me know. Quote Link to comment https://forums.phpfreaks.com/topic/116210-help-with-function-and-some-code/#findComment-597708 Share on other sites More sharing options...
wildteen88 Posted July 23, 2008 Share Posted July 23, 2008 Make sure you have a url variable set called client, that is what the variable $_GET['client'] refers to. Example yoursite.com/page.php?client=1234 Quote Link to comment https://forums.phpfreaks.com/topic/116210-help-with-function-and-some-code/#findComment-597731 Share on other sites More sharing options...
GingerRobot Posted July 23, 2008 Share Posted July 23, 2008 Well, you don't appear to have a form tag; you've put a method attribute in your select tag, but that should be in a form tag. I would then assume that $_GET['client'] is unset, so nothing gets passed to the function. Quote Link to comment https://forums.phpfreaks.com/topic/116210-help-with-function-and-some-code/#findComment-597734 Share on other sites More sharing options...
Darkmatter5 Posted July 23, 2008 Author Share Posted July 23, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/116210-help-with-function-and-some-code/#findComment-597875 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.