Jump to content

tlavelle

Members
  • Posts

    73
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

tlavelle's Achievements

Member

Member (2/5)

0

Reputation

  1. Thanks I stuck this in if(isset($_POST['wercbench1_next'])){ $_SESSION['sess_year']=$_POST['year']; echo $_SESSION['sess_year']; } Seemed to fix it Sound correct?
  2. This file has 3 forms in it. Form 1 - presents to all users. Users select a year and submit Form 2 - Is conditional. It only shows if users choose the value '2007' Form 3 - Should present to all users For whatever reason, my session variable for year seems to get lost after a user who selects 2007 in the first form submits the second form. Help? <?php //initialize session session_start(); ?> <html> <head> <basefont face="Arial"> </head> <body> <?php // set server access variables $host = "localhost"; $user = "root"; $pass = ""; $db = "wercbench"; // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // create form 1 queries $year_query = "SELECT distinct year FROM bench_data"; // execute form 1 queries $year_result = mysql_query($year_query) or die ("Error in query: $query. ".mysql_error()); // grab distinct years from db and stick them in the drop down if (mysql_num_rows($year_result) > 0){ if (!isset($_POST['wercbench1']) and !isset($_POST['year']) || !isset($_POST['wercbench2']) and !isset($_POST['year'])) { echo"<form method=\"POST\" action=\"". $_SERVER['PHP_SELF']. "\" name=\"wercbench1\">"; echo"<table style=\"width: 300;\" border=\"1\" cellpadding=\"2\" cellspacing=\"2\">"; echo"<tbody>"; echo" <tr>"; echo" <td>Select the comparison year and then click next"; echo" </td>"; echo" <td></td>"; echo" </tr>"; echo" <tr>"; echo" <td>"; echo" <select name=\"year\">"; while($row = mysql_fetch_row($year_result)) { echo"<option value=\"" .$row[0]. "\">".$row[0]."</option>"; } echo" </select>"; echo" </td>"; echo" <td></td>"; echo" </tr><tr>"; echo" <td><input type=\"Submit\" value=\"Next\" name=\"wercbench1_next\"></button></td>"; echo" </tr>"; echo" </form>"; } $_SESSION['sess_year']=$_POST['year']; echo $_SESSION['sess_year']; //if 2005 is selected just show the data if(isset($_POST['wercbench1_next']) && ($_SESSION['sess_year']!='2005')){ $industry_result = mysql_query("SELECT distinct comp_desc FROM comp_desc") or die(mysql_error()); echo" <tr>"; echo"<form method=\"POST\" action=\"". $_SERVER['PHP_SELF']. "\" name=\"wercbench2\">"; echo" <td>"; echo" <select name=\"industry\">"; while($row = mysql_fetch_row($industry_result)) { echo"<option value=\"" .$row[0]. "\">".$row[0]."</option>"; } echo" </select>"; echo"</td>"; echo" <td></td>"; echo" </tr>"; echo" <tr>"; echo" <td><input type=\"Submit\" value=\"Next\" name=\"wercbench2_next\"></button></td>"; echo" <td></td>"; echo" </tr>"; echo"</tbody>"; echo"</table>"; echo"</form>"; } $_SESSION['sess_industry']=$_POST['industry']; } else { // no // print status message echo "No rows found!"; } if( (isset($_POST['wercbench2_next']) and ($_SESSION['sess_year']=='2007')) or (isset($_POST['wercbench1_next']) and ($_SESSION['sess_year']=='2005')) ) { $useryear=$_SESSION['sess_year']; //$_SESSION['sess_year']=$_POST['year']; $userindustry=$_SESSION['sess_industry']; //$_SESSION['sess_ind']=$_POST['industry']; $metric_query = "SELECT metric_desc.met_desc, bench_data.median, bench_data.best_pract FROM metric_desc, bench_data where metric_desc.met_key=bench_data.met_key and $useryear=bench_data.year"; $metric_result = mysql_query($metric_query) or die ("Error in query: $query. ".mysql_error()); echo $_SESSION['sess_year']; echo $_SESSION['sess_industry']; echo "<form action=\"results.php\" method=\"post\" name\"wercbench3\">"; echo "<table cellpadding=10 border=1>"; echo "<tr>"; echo "<td>Metric Description</td>"; echo "<td>Average</td>"; echo "<td>Best Practice</td>"; echo "<td>Enter your value here</td>"; echo "</tr>"; while($row = mysql_fetch_row($metric_result)) { echo "<tr>"; echo "<td>".$row[0]."</td>"; echo "<td>" . $row[1]."</td>"; echo "<td>".$row[2]."</td>"; echo "<td><input type=\"text\" name=\"myvalue[]\" value=\"\" /></td>"; echo "</tr>"; } echo "<tr><td colspan=\"3\"> </td><td align=\"center\"><input type=\"submit\" name=\"wercbench3\" value=\"Compare\"></td></tr></table>"; //} // free result set memory mysql_free_result($year_result); //mysql_free_result($industry_result); mysql_free_result($metric_result); //mysql_free_result($metric_result); } // close connection mysql_close($connection); ?> </body> </html>
  3. is there a way to link to a location on a page like in the example below but instead of the link existing on the same page as the target location, the link exist on one page and points to a bookmark on another page? So for example, I want index.html to have a link that takes the user to chapter 4 of content.html (which is half way down the page) <p> <a href="#C4">See also Chapter 4.</a> </p> <h2>Chapter 1</h2> <p>This chapter explains ba bla bla</p> <h2>Chapter 2</h2> <p>This chapter explains ba bla bla</p> <h2>Chapter 3</h2> <p>This chapter explains ba bla bla</p> <h2><a name="C4">Chapter 4</a></h2> <p>This chapter explains ba bla bla</p>
  4. What is wrong with this sql? use imis; select count(id) as duescount , id from activity where activity_type='dues' and duescount>=2 group by id order by duescount asc; it is giving me this Msg 207, Level 16, State 3, Line 2 Invalid column name 'duescount'. Can you not sue an alias like this? If not, how do I make that comparison?
  5. There are 2 if statements at the beginning of this code snippet. The one that is currently commented out works while the one that is not commented out yields this error Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\bench2\index4.php on line 106 I am just not seeing why. Help please? //if((isset($_POST['wercbench2_next']) and ($_POST['year']='2007')) or $_POST['year']='2005'){ if((isset($_POST['wercbench2_next']) and ($_POST['year']='2007')) or (isset($_POST['wercbench1_next']) and ($_POST['year']='2005')) { $useryear=$_POST['year']; $_SESSION['sess_year']=$_POST['year']; $userindustry=$_POST['industry']; $_SESSION['sess_ind']=$_POST['industry']; $metric_query = "SELECT metric_desc.met_desc, bench_data.median, bench_data.best_pract FROM metric_desc, bench_data where metric_desc.met_key=bench_data.met_key and $useryear=bench_data.year"; //$metric_query = "SELECT metric_desc.met_desc, bench_data.median, bench_data.best_pract FROM metric_desc, bench_data where metric_desc.met_key=bench_data.met_key and $useryear=bench_data.year and $userindustry=bench_data.comp_key"; $metric_result = mysql_query($metric_query) or die ("Error in query: $query. ".mysql_error()); if(isset($_POST['wercbench2_next']) and (mysql_num_rows($metric_result)) > 0){ // yes // print them one after another //echo "<form action=\"results.php\" method=\"post\" name\"wercbench2\">"; echo "<form action=\"results.php\" method=\"post\" name\"wercbench3\">"; echo "<table cellpadding=10 border=1>"; echo "<tr>"; echo "<td>Metric Description</td>"; echo "<td>Average</td>"; echo "<td>Best Practice</td>"; echo "<td>Enter your value here</td>"; echo "</tr>"; while($row = mysql_fetch_row($metric_result)) { echo "<tr>"; echo "<td>".$row[0]."</td>"; echo "<td>" . $row[1]."</td>"; echo "<td>".$row[2]."</td>"; echo "<td><input type=\"text\" name=\"myvalue[]\" value=\"\" /></td>"; echo "</tr>"; } echo "<tr><td colspan=\"3\"> </td><td align=\"center\"><input type=\"submit\" name=\"wercbench3\" value=\"Compare\"></td></tr></table>"; } // free result set memory mysql_free_result($year_result); //mysql_free_result($industry_result); mysql_free_result($metric_result); //mysql_free_result($metric_result); }
  6. Session variables allow you to capture user entered values for the duration of the users session. At the top of all the pages in your app, make sure you include <?php session_start(); ?> This basically allows you to invoke the session array. So if a user posts a value from a form you can assign it to $_SESSION['dvd']; Then for the duration of the session, that variable will be available in that array.
  7. if(isset($_POST['wercbench2_next'] && isset$_POST['year']='2007') || $_POST['year']='2005') why is it giving me this? Parse error: syntax error, unexpected T_BOOLEAN_AND, expecting ',' or ')' in C:\xampp\htdocs\bench2\index4.php on line 105
  8. How do you guys do this without smashing your computer and burning all code in a huge effigy? I am ready to give up on this forever!! Curse you PHP and your endless taunting of me!!
  9. But it should always be empty when the page loads. That variable should not be populated until the user posts form 1. I guess I don't understand why that code is being triggered at all. Should the conditional if insulate that code from being triggered until the a form is posted?
  10. I am getting this error: Error in query: . You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=bench_data.year' at line 1 Related to this snippet if(isset($_POST['wercbench2']) || ($_POST['year']<>'2005')) { $useryear=$_POST['year']; $_SESSION['sess_year']=$_POST['year']; $userindustry=$_POST['industry']; $_SESSION['sess_ind']=$_POST['industry']; $metric_query = "SELECT metric_desc.met_desc, bench_data.median, bench_data.best_pract FROM metric_desc, bench_data where metric_desc.met_key=bench_data.met_key and $useryear=bench_data.year"; $metric_result = mysql_query($metric_query) or die ("Error in query: $query. ".mysql_error()); In this file <?php //initialize session session_start(); ?> <html> <head> <basefont face="Arial"> </head> <body> <?php // set server access variables $host = "localhost"; $user = "root"; $pass = ""; $db = "wercbench"; // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // create form 1 queries $year_query = "SELECT distinct year FROM bench_data"; // execute form 1 queries $year_result = mysql_query($year_query) or die ("Error in query: $query. ".mysql_error()); //$industry_result = mysql_query($industry_query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($year_result) > 0){ // yes // print them one after another if (!isset($_POST['wercbench1']) and !isset($_POST['year'])) { /*" name=\"wercbench1\">";*/ echo"<form method=\"POST\" action=\"". $_SERVER['PHP_SELF']. "\" name=\"wercbench1\">"; echo"<table style=\"width: 100%;\" border=\"1\" cellpadding=\"2\" cellspacing=\"2\">"; echo"<tbody>"; echo" <tr>"; echo" <td>Select the comparison year and group then click next"; echo" </td>"; echo" <td></td>"; echo" </tr>"; echo" <tr>"; echo" <td>"; echo" <select name=\"year\">"; while($row = mysql_fetch_row($year_result)) { echo"<option value=\"" .$row[0]. "\">".$row[0]."</option>"; } echo" </select>"; echo" </td>"; echo" <td></td>"; echo" </tr><tr>"; echo" <td><input type=\"Submit\" value=\"Next\" name=\"wercbench1_next\"></button></td>"; echo" </tr>"; echo" </form>"; } if(isset($_POST['wercbench1_next']) && !empty($_POST['year'])){ if ($_POST['year']<>'2005'){ $industry_result = mysql_query("SELECT distinct comp_desc FROM comp_desc") or die(mysql_error()); echo" <tr>"; echo"<form method=\"POST\" action=\"". $_SERVER['PHP_SELF']. "\" name=\"wercbench2\">"; echo" <td>"; echo" <select name=\"industry\">"; while($row = mysql_fetch_row($industry_result)) { echo"<option value=\"" .$row[0]. "\">".$row[0]."</option>"; } echo" </select>"; echo"</td>"; echo" <td></td>"; echo" </tr>"; echo" <tr>"; echo" <td><input type=\"Submit\" value=\"Next\" name=\"wercbench2_next\"></button></td>"; echo" <td></td>"; echo" </tr>"; echo"</tbody>"; echo"</table>"; echo"</form>"; } } } else { // no // print status message echo "No rows found!"; } //Calcualtor variables if(isset($_POST['wercbench2']) || ($_POST['year']<>'2005')) { $useryear=$_POST['year']; $_SESSION['sess_year']=$_POST['year']; $userindustry=$_POST['industry']; $_SESSION['sess_ind']=$_POST['industry']; $metric_query = "SELECT metric_desc.met_desc, bench_data.median, bench_data.best_pract FROM metric_desc, bench_data where metric_desc.met_key=bench_data.met_key and $useryear=bench_data.year"; $metric_result = mysql_query($metric_query) or die ("Error in query: $query. ".mysql_error()); if(isset($_POST['wercbench2_next']) and (mysql_num_rows($metric_result)) > 0){ // yes // print them one after another //echo "<form action=\"results.php\" method=\"post\" name\"wercbench2\">"; echo "<form action=\"results.php\" method=\"post\" name\"wercbench3\">"; echo "<table cellpadding=10 border=1>"; echo "<tr>"; echo "<td>Metric Description</td>"; echo "<td>Average</td>"; echo "<td>Best Practice</td>"; echo "<td>Enter your value here</td>"; echo "</tr>"; while($row = mysql_fetch_row($metric_result)) { echo "<tr>"; echo "<td>".$row[0]."</td>"; echo "<td>" . $row[1]."</td>"; echo "<td>".$row[2]."</td>"; echo "<td><input type=\"text\" name=\"myvalue[]\" value=\"\" /></td>"; echo "</tr>"; } echo "<tr><td colspan=\"3\"> </td><td align=\"center\"><input type=\"submit\" name=\"wercbench3\" value=\"Compare\"></td></tr></table>"; } // free result set memory mysql_free_result($year_result); mysql_free_result($industry_result); mysql_free_result($metric_result); //mysql_free_result($metric_result); } // close connection mysql_close($connection); ?> </body> </html> I dont see how the query is even being triggered upon initial load of this page to cause the error.
  11. Instead of saying the main form, I should say teh third form in the code. Basically the logic is 1. Select a year 2. If the year is 2007, select an industry 3. IF the year is 2005 or the year is 2007 and an industry is selected, show form 3 it is step 3 above that is not working
  12. Can you site the specific non-sensical line? is this it? if(!isset($_POST['wercbench2_next']) and (mysql_num_rows($metric_result)) > 0)
  13. OK. So I am attempting to create a list box that is dynamically populated based on the selection of another list box. I am in way over my head..only way to learn I guess. The code below has a year listbox and then based on the year selection, the page should either show another listbox (show industry selection when year <> 2005) or it should render the main form (when year=2005). I cannot get the main form to appear. Help please? <?php //initialize session session_start(); ?> <html> <head> <basefont face="Arial"> </head> <body> <?php // set server access variables $host = "localhost"; $user = "root"; $pass = ""; $db = "wercbench"; // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // create form 1 queries $year_query = "SELECT distinct year FROM bench_data"; // execute form 1 queries $year_result = mysql_query($year_query) or die ("Error in query: $query. ".mysql_error()); //$industry_result = mysql_query($industry_query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($year_result) > 0){ // yes // print them one after another if (!isset($_POST['wercbench1']) and !isset($_POST['year'])) { /*" name=\"wercbench1\">";*/ echo"<form method=\"POST\" action=\"". $_SERVER['PHP_SELF']. "\" name=\"wercbench1\">"; echo"<table style=\"width: 100%;\" border=\"1\" cellpadding=\"2\" cellspacing=\"2\">"; echo"<tbody>"; echo" <tr>"; echo" <td>Select the comparison year and group then click next"; echo" </td>"; echo" <td></td>"; echo" </tr>"; echo" <tr>"; echo" <td>"; echo" <select name=\"year\">"; while($row = mysql_fetch_row($year_result)) { echo"<option value=\"" .$row[0]. "\">".$row[0]."</option>"; } echo" </select>"; echo" </td>"; echo" <td></td>"; echo" </tr><tr>"; echo" <td><input type=\"Submit\" value=\"Next\" name=\"wercbench1_next\"></button></td>"; echo" </tr>"; echo" </form>"; } if(isset($_POST['wercbench1_next']) && !empty($_POST['year'])){ if ($_POST['year']<>'2005'){ $industry_result = mysql_query("SELECT distinct comp_desc FROM comp_desc") or die(mysql_error()); echo" <tr>"; echo"<form method=\"POST\" action=\"". $_SERVER['PHP_SELF']. "\" name=\"wercbench2_next\">"; echo" <td>"; echo" <select name=\"industry\">"; while($row = mysql_fetch_row($industry_result)) { echo"<option value=\"" .$row[0]. "\">".$row[0]."</option>"; } echo" </select>"; echo"</td>"; echo" <td></td>"; echo" </tr>"; echo" <tr>"; echo" <td><input type=\"Submit\" value=\"Next\" name=\"wercbench2_next\"></button></td>"; echo" <td></td>"; echo" </tr>"; echo"</tbody>"; echo"</table>"; echo"</form>"; } } } else { // no // print status message echo "No rows found!"; } //Calcualtor variables if(isset($_POST['wercbench2_next'])) { $useryear=$_POST['year']; $_SESSION['sess_year']=$_POST['year']; $userindustry=$_POST['industry']; $_SESSION['sess_ind']=$_POST['industry']; $metric_query = "SELECT metric_desc.met_desc, bench_data.median, bench_data.best_pract FROM metric_desc, bench_data where metric_desc.met_key=bench_data.met_key and $useryear=bench_data.year"; $metric_result = mysql_query($metric_query) or die ("Error in query: $query. ".mysql_error()); if(!isset($_POST['wercbench2_next']) and (mysql_num_rows($metric_result)) > 0){ // yes // print them one after another //echo "<form action=\"results.php\" method=\"post\" name\"wercbench2\">"; echo "<form action=\"results.php\" method=\"post\" name\"wercbench2\">"; echo "<table cellpadding=10 border=1>"; echo "<tr>"; echo "<td>Metric Description</td>"; echo "<td>Average</td>"; echo "<td>Best Practice</td>"; echo "<td>Enter your value here</td>"; echo "</tr>"; while($row = mysql_fetch_row($metric_result)) { echo "<tr>"; echo "<td>".$row[0]."</td>"; echo "<td>" . $row[1]."</td>"; echo "<td>".$row[2]."</td>"; echo "<td><input type=\"text\" name=\"myvalue[]\" value=\"\" /></td>"; echo "</tr>"; } echo "<tr><td colspan=\"3\"> </td><td align=\"center\"><input type=\"submit\" name=\"wercbench_next2\" value=\"Compare\"></td></tr></table>"; } // free result set memory mysql_free_result($year_result); mysql_free_result($industry_result); mysql_free_result($metric_result); //mysql_free_result($metric_result); } // close connection mysql_close($connection); ?> </body> </html>
  14. How do I populate the second listbox in this form based on the selection of the first listbox? The first listbox is populated by this query: $year_query = "SELECT distinct year FROM bench_data"; The second listbox should essentially be populated by this: $industry_query = "SELECT distinct comp_desc FROM comp_desc, benc_data where $_POST['year']=bench_data.year and bench_data.comp_key=comp_desc.comp_key"; I know this is alot to ask, but please EXPLAIN the code. I am new and need the explanation elucidated and not just supplied code that will accomplish the goal. Thanks <?php //initialize session session_start(); ?> <html> <head> <basefont face="Arial"> </head> <body> <?php // set server access variables $host = "localhost"; $user = "root"; $pass = ""; $db = "wercbench"; // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // create form 1 queries $year_query = "SELECT distinct year FROM bench_data"; $industry_query = "SELECT distinct comp_desc FROM comp_desc"; // execute form 1 queries $year_result = mysql_query($year_query) or die ("Error in query: $query. ".mysql_error()); $industry_result = mysql_query($industry_query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($year_result) > 0){ // yes // print them one after another if (!isset($_POST['wercbench1']) and !isset($_POST['year'])) { /*" name=\"wercbench1\">";*/ echo"<form method=\"POST\" action=\"". $_SERVER['PHP_SELF']. "\" name=\"wercbench1\">"; echo"<table style=\"width: 100%;\" border=\"1\" cellpadding=\"2\" cellspacing=\"2\">"; echo"<tbody>"; echo" <tr>"; echo" <td>Select the comparison year and group then click next"; echo" </td>"; echo" <td></td>"; echo" </tr>"; echo" <tr>"; echo" <td>"; echo" <select name=\"year\">"; while($row = mysql_fetch_row($year_result)) { echo"<option value=\"" .$row[0]. "\">".$row[0]."</option>"; } echo" </select>"; echo" </td>"; echo" <td></td>"; echo" </tr>"; echo" <tr>"; echo" <td>"; echo" <select name=\"industry\">"; while($row = mysql_fetch_row($industry_result)) { echo"<option value=\"" .$row[0]. "\">".$row[0]."</option>"; } echo" </select>"; echo"</td>"; echo" <td></td>"; echo" </tr>"; echo" <tr>"; echo" <td><input type=\"Submit\" value=\"Next\" name=\"wercbench1_next\"></button></td>"; echo" <td></td>"; echo" </tr>"; echo"</tbody>"; echo"</table>"; echo"</form>"; } } else { // no // print status message echo "No rows found!"; } //Calcualtor variables if(isset($_POST['wercbench1_next'])) { $useryear=$_POST['year']; $_SESSION['sess_year']=$_POST['year']; $userindustry=$_POST['industry']; $_SESSION['sess_ind']=$_POST['industry']; $metric_query = "SELECT metric_desc.met_desc, bench_data.median, bench_data.best_pract FROM metric_desc, bench_data where metric_desc.met_key=bench_data.met_key and $useryear=bench_data.year"; $metric_result = mysql_query($metric_query) or die ("Error in query: $query. ".mysql_error()); if(!isset($_POST['wercbench2']) and (mysql_num_rows($metric_result)) > 0){ // yes // print them one after another //echo "<form action=\"results.php\" method=\"post\" name\"wercbench2\">"; echo "<form action=\"results.php\" method=\"post\" name\"wercbench2\">"; echo "<table cellpadding=10 border=1>"; echo "<tr>"; echo "<td>Metric Description</td>"; echo "<td>Average</td>"; echo "<td>Best Practice</td>"; echo "<td>Enter your value here</td>"; echo "</tr>"; while($row = mysql_fetch_row($metric_result)) { echo "<tr>"; echo "<td>".$row[0]."</td>"; echo "<td>" . $row[1]."</td>"; echo "<td>".$row[2]."</td>"; echo "<td><input type=\"text\" name=\"myvalue[]\" value=\"\" /></td>"; echo "</tr>"; } echo "<tr><td colspan=\"3\"> </td><td align=\"center\"><input type=\"submit\" name=\"wercbench_next2\" value=\"Compare\"></td></tr></table>"; } // free result set memory mysql_free_result($year_result); mysql_free_result($industry_result); mysql_free_result($metric_result); //mysql_free_result($metric_result); } // close connection mysql_close($connection); ?> </body> </html>
×
×
  • 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.