justintoo1 Posted December 21, 2009 Share Posted December 21, 2009 Hello, I have a web app using php that helps create a schedule. Where I click the submit button, nothing happens. I would atleast expect a 404 error since xxxprocessform.php does not exisit. Do I have my form and select set up correct? index.php <?php /* Requires the header and the header requires config.php */ require("header.php"); if($_POST['submit']) { $db = mysql_connect($dbhost, $dbuser, $dbpassword); mysql_select_db($dbdatabase, $db); } echo mysql_error(); ?> <br/> <br/> <div id="main"> <h3>Employee Search</h3> <form action="XXXprocessform.php" method="post"> <?php echo "<br>"; $fieldavail = mysql_list_fields("sch", "avail", $db); $colavail = mysql_num_fields($fieldavail); echo "<p>What day ?</p>"; echo "<form action=xxxprocess.php method=POST><select name='$avail'>"; for ($i = 1; $i < $colavail; $i++) { echo "<option value=$i>"; echo mysql_field_name($fieldavail, $i); } echo "</select></form>"; echo "<br>"; $fieldarea = mysql_list_fields("sch", "area", $db); $colarea = mysql_num_fields($fieldarea); echo "<p>What area ?</p>"; echo "<form action=xxxprocess.php method=POST><select name='$area'>"; for ($i = 1; $i < $colarea; $i++) { echo "<option value =$i>"; echo mysql_field_name($fieldarea, $i); } echo "</select></form>"; ?> <br><br> <input type="submit" name="submit" value="Search employees"> </select> </form> </div> </body> </html> and this is my header header.php <?php require("config.php"); $db = mysql_connect($dbhost, $dbuser, $dbpassword) or die(mysql_error()); mysql_select_db($dbdatabase, $db); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title><?php echo $config_sitename; ?></title> <link href="stylesheet.css" rel="stylesheet"> <div id="header"> <h1><?php echo $config_sitename; ?></h1> </div> </head> <body> ...again when i clikc submit - nothing, not even an error. all help would be apperciated. -justin Quote Link to comment Share on other sites More sharing options...
Deoctor Posted December 21, 2009 Share Posted December 21, 2009 hi u are using as if the submit button is pressed u are selecting the connection and selecting the db after that u closed it and started running commands, obviously it will not show u any error as it has connected to the mysql and selected the db after that it cannot understand ur query $fieldavail = mysql_list_fields("sch", "avail", $db); so check ur code again Quote Link to comment Share on other sites More sharing options...
justintoo1 Posted December 21, 2009 Author Share Posted December 21, 2009 so i should keep my tags open is what your are saying ? the first part sees if it has been submitted, then i close it. should i get rid of this thne..? if($_POST['submit']) { $db = mysql_connect($dbhost, $dbuser, $dbpassword); mysql_select_db($dbdatabase, $db); } echo mysql_error(); ?> thanks for helping. Quote Link to comment Share on other sites More sharing options...
justintoo1 Posted December 23, 2009 Author Share Posted December 23, 2009 Hello, I have fixed it. All goes well, acts like I would expect it. Except during the execution of process.php the results from gettype() is null; What I am trying to do is get the selected [avail] from the avail drop down and pass it through to process.php and simply display it. I don't know how to get variables from my options. can you help ? test2.php <? // Open <html> tag. echo "<html>"; // Open <header> and <title> tags, close </title>. echo "<head><title>PHP Info - test2.php</title>"; require("header.php"); //echo "</head>"; - Uneccessary, closed in [header.php] //echo "<body>"; - Uneccessary, opened in the end of [header.php] // Close php tag, straight into <html>, <body> was opened in [header.php] ?> <!--HTML--> <br><br> <!-- Open main div --> <div id="main"> <h3>Employee Search</h3> <br> <form action="process.php" method="post"> <!-- Create drop down for [avail] --> <?php $fieldavail = mysql_list_fields("sch", "avail", $db); $colavail = mysql_num_fields($fieldavail); echo "<p>What day ?</p>"; echo "<form action=process.php method=POST name='avail'>"; echo "<select name='AVAIL'>"; echo "<option value='deef'> Select an avail </option>"; for ($i = 1; $i < $colavail; $i++) { echo "<option value=$i>"; echo mysql_field_name($fieldavail, $i); } echo "</select>"; echo "</form>"; echo "<br>"; ?> <!-- Create drop down for [area] --> <? $fieldarea = mysql_list_fields("sch", "area", $db); $colarea = mysql_num_fields($fieldarea); echo "<p>What area ?</p>"; echo "<form action=test2.php method=POST name='area'>"; echo "<select name='$area_option'>"; echo "<option value='deeg'> Select an area </option>"; for ($i = 1; $i < $colarea; $i++) { echo "<option value =$i>"; echo mysql_field_name($fieldarea, $i); } echo "</select>"; echo "</form>"; echo "<br><br>"; echo "<form id='goat' name='goat' action=process.php method=POST>"; echo "<input type='submit' name='submit' value='Search employees'>"; echo "<br><br>"; //echo "</div>"; ?> <!-- Close main div--> </div> <? // Close </body> tag. echo "</body>"; // Close <html> tag. echo "</html>"; // End. ?> and here is my process.php file <? // Open <html> tag. echo "<html>"; // Open <header> and <title> tags, close </title>. echo "<head><title>PHP Info - [schedule Assistant] - process.php</title>"; require("process_header.php"); //echo "</head>"; - Uneccessary, closed in [process_header.php] //echo "<body>"; - Uneccessary, opened in the end of [process_header.php] // Close php tag, straight into <html>, <body> was opened in [process_header.php] ?> <!--HTML--> <br><br> <!-- Open main div --> <div id="main"> <h3>Hello, results.</h3> <br> <? $avail = ($_POST['AVAIL']); echo $avail . ' '; echo $AVAIL; echo gettype($avail); echo "<br>"; echo "<br>"; $area = ($_POST[$area_option]); echo $area . ' '; echo gettype($area); echo "<br>"; ?> <!-- Close main div--> </div> <? // Close </body> tag. echo "</body>"; // Close <html> tag. echo "</html>"; // End. ?> thank you for helping - justin Quote Link to comment Share on other sites More sharing options...
justintoo1 Posted December 26, 2009 Author Share Posted December 26, 2009 hello, i am making some progress, but something is still wrong. I used gettype to tell me what my POST vari are ending up to be set. I take the selected options and send them through to POST using avail_option and area_option. When I process it - I assign the post variables to my variables ($area,$avail) but when I gettype them they are returned as numbers but strings. I would like them to be assigned one of the options names, (availmon, availtue, availwed, etc..) So I have created a way arond for the mean time...can anyone help me simplfy my processing ? My code is a bit messy, pardon me. test2.php <? // Open <html> tag. echo "<html>"; // Open <header> and <title> tags, close </title>. echo "<head><title>PHP Info - test2.php</title>"; require("header.php"); //echo "</head>"; - Uneccessary, closed in [header.php] //echo "<body>"; - Uneccessary, opened in the end of [header.php] // Close php tag, straight into <html>, <body> was opened in [header.php] ?> <!--HTML--> <br><br> <!-- Open main div --> <div id="main"> <h3>Employee Search</h3> <br> <!--<form method="post" action="process.php">--> <!-- Create drop down for [avail] --> <?php $fieldavail = mysql_list_fields("sch", "avail", $db); $colavail = mysql_num_fields($fieldavail); echo "<p>What day ?</p>"; echo "<form action=process.php method=POST>"; echo "<select name='avail_option'>"; for ($i = 1; $i < $colavail; $i++) { echo "<option value=$i>"; echo mysql_field_name($fieldavail, $i); echo "</option>"; } echo "</select>"; // $avail = $_POST['avail_option']; // echo "</form>"; echo "<br>"; ?> <!-- Create drop down for [area] --> <? $fieldarea = mysql_list_fields("sch", "area", $db); $colarea = mysql_num_fields($fieldarea); echo "<p>What area ?</p>"; echo "<form action=process.php method=POST>"; echo "<select name='area_option'>"; for ($i = 1; $i < $colarea; $i++) { echo "<option value =$i>"; echo mysql_field_name($fieldarea, $i); echo "</option>"; } echo "</select>"; // $area = $_POST['area_option']; // echo "</form>"; echo "<br>"; ?> <form action=process.php method=POST> <!-- echo "<input type='submit' name='submit' value='Search employees'>"; echo "<br><br>"; //echo "</div>"; ?>--> <input type='submit' name ='submit' value='Search'> <!-- Close main div--> </div> <!--<? // Close </body> tag. echo "</body>"; // Close <html> tag. echo "</html>"; // End. ?>--> </body> </html> and this is what my process.php looks like.. process.php <? // Open <html> tag. echo "<html>"; // Open <header> and <title> tags, close </title>. echo "<head><title>PHP Info - [schedule Assistant] - process.php</title>"; require("process_header.php"); //echo "</head>"; - Uneccessary, closed in [process_header.php] //echo "<body>"; - Uneccessary, opened in the end of [process_header.php] // Close php tag, straight into <html>, <body> was opened in [process_header.php] ?> <!--HTML--> <br><br> <!-- Open main div --> <div id="main"> <h3>Hello, results.</h3> <br> <? $avail = $_POST[avail_option]; $area = $_POST[area_option]; echo "<h2> Avail </h2>"; echo "<br>"; switch ($avail) { case '1': $sel_av = 'Monday'; break; case '2': $sel_av = 'Tuesday'; break; case '3': $sel_av = 'Wednesday'; break; case '4': $sel_av = 'Thursday'; break; case '5': $sel_av = 'Friday'; break; case '6': $sel_av = 'Saturday'; break; case '7': $sel_av = 'Sunday'; break; } echo $sel_av; echo "<br><br>"; echo $avail; echo gettype($avail); echo "<br>"; echo "<h2> Area </h2>"; echo "<br>"; switch ($area) { case '1': $sel_ar = 'Bakery'; break; case '2': $sel_ar = 'Dining Room'; break; case '3': $sel_ar = 'Dishes'; break; case '4': $sel_ar = 'Line'; break; case '5': $sel_ar = 'Register'; break; } echo $sel_ar; echo $area; echo gettype($area); echo "<br>"; //echo "$fieldavail"; //echo $colavail; //echo $fieldarea; //echo $colarea; echo 'right here....<br>'; var_dump($_POST); ?> <!-- Close main div--> </div> <? // Close </body> tag. echo "</body>"; // Close <html> tag. echo "</html>"; // End. ?> ...thanks for help and input. - justin Quote Link to comment Share on other sites More sharing options...
justintoo1 Posted December 27, 2009 Author Share Posted December 27, 2009 hello friends, I have finally come to a solution. here is my code if anyone might find it useful. I thanks for all the help I have recieved from the forums. <? echo "<html>"; echo "<head><title>PHP Info - [schedule Assistant] - process.php</title>"; require("process_header.php"); ?> <!--HTML--> <br><br> <!-- Open main div --> <div id="main"> <br><br> <h3>Hello, results.</h3> <!-- Open PHP --> <? // Assign POST varis to my varis. $avail = $_POST[avail_option]; $area = $_POST[area_option]; echo "<h1> Avail </h1>" . "<br>" . "<h2>" . $avail . "</h2>" . "<br>"; echo "<h1> Area </h1>" . "<br>" . "<h2>" . $area . "</h2>" . "<br><br>"; $query = "select empname from emp join area a using (areaid) join avail b using (availid) where a.$area = 'y' and b.$avail = 'y'"; $result = mysql_query($query) or die ('Query error in : $query ' . mysql_error()); if (mysql_num_rows($result) > 0) { while($row = mysql_fetch_row($result)) { echo $row[0]; echo "<br>---<br>"; echo $row[1]; } } else { echo 'No rows found!!'; } //<!-- Close main div--> echo "</div></body></html>"; ?> good day - justin Quote Link to comment 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.