uwictech Posted November 10, 2009 Share Posted November 10, 2009 Hi all, I'm sure this is very easy but I'm having another brain freeze! At the end of the code I have echoed 3 bits of info to screen $ip, $_POST['ssid'] and $ssid_id". I would like to put $_POST['ssid'] into a variable, is this possible? Jamie <?php //run site query require("confwifi.php") ; { $ext_site = $_POST['site']; $extract = mysql_query ("SELECT * FROM site WHERE site='$ext_site'"); $numrows = mysql_num_rows ($extract); while ($row = mysql_fetch_assoc($extract)) { $id = $row['id']; $site = $row['site']; $ip = $row['ip']; } } ?> <?php //run site query require("confwifi.php") ; { $ext_ssid = $_POST['ssid_name']; $extract = mysql_query ("SELECT * FROM ssid WHERE ssid_name='$ext_ssid'"); $numrows = mysql_num_rows ($extract); while ($row = mysql_fetch_assoc($extract)) { $ssid_id = $row['ssid_id']; $ssid_name = $row['ssid_name']; } } ?> <form name="form1" method="POST" action="wifichange.php"><div> <select name="site"> <option value="0" selected>(please select:)</option> <option name="site">Llandaf</option> <option name="site">Cyncoed</option> <option name="site">Howard Gardens</option> <option name="site">Colchester Avenue</option> </select> <select name="ssid_name"> <option value="0" selected>(please select:)</option> <option name="ssid_name">Guest</option> <option name="ssid_name">Conferences</option> </select> </form> <p><input type="text" name="ssid"></div></P> <div><input type="submit" value="submit"></div> </form> <?php echo "$ip"; ?><p></p> <?php echo $_POST['ssid'];; ?><p></p> <?php echo "$ssid_id"; ?><p></p> <?php Quote Link to comment Share on other sites More sharing options...
gevans Posted November 10, 2009 Share Posted November 10, 2009 $ssid = $_POST['ssid']; You may want to filter the contents of $_POST['ssid'] first. Quote Link to comment Share on other sites More sharing options...
uwictech Posted November 10, 2009 Author Share Posted November 10, 2009 Thanks mate, I was writing it the wrong way around drrrrr! I have another problem however, I doesn't seem to be pulling the $ip variable in the telnet program I have. Whe I echo it on screen, it come up with the correct ip? <?php //run site query require("confwifi.php") ; { $ext_site = $_POST['site']; $extract = mysql_query ("SELECT * FROM site WHERE site='$ext_site'"); $numrows = mysql_num_rows ($extract); while ($row = mysql_fetch_assoc($extract)) { $id = $row['id']; $site = $row['site']; $ip = $row['ip']; } } ?> <?php //run site query require("confwifi.php") ; { $ext_ssid = $_POST['ssid_name']; $extract = mysql_query ("SELECT * FROM ssid WHERE ssid_name='$ext_ssid'"); $numrows = mysql_num_rows ($extract); while ($row = mysql_fetch_assoc($extract)) { $ssid_id = $row['ssid_id']; $ssid_name = $row['ssid_name']; } $ssidpass = $_POST['ssidpass']; } ?> <form name="form1" method="POST" action="wifichange.php"><div> <select name="site"> <option value="0" selected>(please select:)</option> <option name="site">Llandaf</option> <option name="site">Cyncoed</option> <option name="site">Howard Gardens</option> <option name="site">Colchester Avenue</option> </select> <select name="ssid_name"> <option value="0" selected>(please select:)</option> <option name="ssid_name">Guest</option> <option name="ssid_name">Conferences</option> </select> </form> <p><input type="text" name="ssidpass"></div></P> <div><input type="submit" value="submit"></div> </form> <?php echo "$ip"; ?><p></p> <?php echo "$ssidpass"; ?><p></p> <?php echo "$ssid_id"; ?><p></p> <?php require_once "php-telnet/PHPTelnet.php"; $telnet = new PHPTelnet(); // if the first argument to Connect is blank, // PHPTelnet will connect to the local host via 127.0.0.1 $result = $telnet->Connect('$ip','admin','******'); if ($result == 0) { $telnet->DoCommand('config wlan disable '.$ssid_id.''); // NOTE: $result may contain newlines $telnet->DoCommand('config wlan security wpa1 pre-shared-key enable 1 ascii '.$ssidpass.''); $telnet->DoCommand('config wlan enable '.$ssid_id.''); // say Disconnect(0); to break the connection without explicitly logging out $telnet->Disconnect(); } ?> Quote Link to comment Share on other sites More sharing options...
uwictech Posted November 10, 2009 Author Share Posted November 10, 2009 Sorry, fixed that! The trouble is, every time I go to the site the code runs. How do I set it so that it will not run until the submit button is pressed? Jamie <?php //run site query require("confwifi.php") ; { $ext_site = $_POST['site']; $extract = mysql_query ("SELECT * FROM site WHERE site='$ext_site'"); $numrows = mysql_num_rows ($extract); while ($row = mysql_fetch_assoc($extract)) { $id = $row['id']; $site = $row['site']; $ip = $row['ip']; } } ?> <?php //run site query require("confwifi.php") ; { $ext_ssid = $_POST['ssid_name']; $extract = mysql_query ("SELECT * FROM ssid WHERE ssid_name='$ext_ssid'"); $numrows = mysql_num_rows ($extract); while ($row = mysql_fetch_assoc($extract)) { $ssid_id = $row['ssid_id']; $ssid_name = $row['ssid_name']; } $ssidpass = $_POST['ssidpass']; } ?> <form name="form1" method="POST" action="wifichange.php"><div> <select name="site"> <option value="0" selected>(please select:)</option> <option name="site">Llandaf</option> <option name="site">Cyncoed</option> <option name="site">Howard Gardens</option> <option name="site">Colchester Avenue</option> </select> <p></p> <select name="ssid_name"> <option value="0" selected>(please select:)</option> <option name="ssid_name">Guest</option> <option name="ssid_name">Conferences</option> </select> <p><input type="text" name="ssidpass"></div></P> <input type="submit" value="submit"> </form> <?php require_once "php-telnet/PHPTelnet.php"; $telnet = new PHPTelnet(); // if the first argument to Connect is blank, // PHPTelnet will connect to the local host via 127.0.0.1 $result = $telnet->Connect($ip,'admin','K1n94+'); if ($result == 0) { $telnet->DoCommand('config wlan disable '.$ssid_id.''); // NOTE: $result may contain newlines $telnet->DoCommand('config wlan security wpa1 pre-shared-key enable 1 ascii '.$ssidpass.''); $telnet->DoCommand('config wlan enable '.$ssid_id.''); // say Disconnect(0); to break the connection without explicitly logging out $telnet->Disconnect(); } ?> <?php ini_set("SMTP", "e2k3vs01.internal.uwic.ac.uk"); $to = "jhancock@uwic.ac.uk"; $subject = "WiFi Password"; $headers ="From: WiFi@uwic.ac.uk"; $body = "The WiFi password for the $ssid_id on the $ip campus, has been manually reset to: $ssidpass"; mail($to, $subject, $body, $headers); die(); ?> Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted November 10, 2009 Share Posted November 10, 2009 what is that starting { doing? <?php //run site query require("confwifi.php") ; { //<------this one $ext_site = $_POST['site']; add a name="submit" to your <input type="submit" name="submit" value="Submit" /> (name="" can be anything you want). and then, wrap the code that you don't want executed until the submit button has been pushed with this: if (isset ($_POST['submit'])) { //code here... } //close statement/condition; or, you can do a quick escape like this: <?php if (!isset ($_POST['submit'])) { header ('Location: http://www.your-site.com'); exit (0); } //rest of your code here. ?> i always opt for the first option .. i just prefer it. Quote Link to comment Share on other sites More sharing options...
uwictech Posted November 12, 2009 Author Share Posted November 12, 2009 Hi Marcus, The page is still running when I go to it without pressing the submit button, is it clear what I'm doing wrong? J. <?php //run site query require("confwifi.php") ; $ext_site = $_POST['site']; $extract = mysql_query ("SELECT * FROM site WHERE site='$ext_site'"); $numrows = mysql_num_rows ($extract); while ($row = mysql_fetch_assoc($extract)) { $id = $row['id']; $site = $row['site']; $ip = $row['ip']; } ?> <?php //run site query require("confwifi.php") ; { $ext_ssid = $_POST['ssid_name']; $extract = mysql_query ("SELECT * FROM ssid WHERE ssid_name='$ext_ssid'"); $numrows = mysql_num_rows ($extract); while ($row = mysql_fetch_assoc($extract)) { $ssid_id = $row['ssid_id']; $ssid_name = $row['ssid_name']; } $ssidpass = $_POST['ssidpass']; } ?> <div class="boxextqry"> <h3> SSID CHANGE </h3> <form name="form1" method="post" action="../index1.php?page=wifichange"> <select name="site"> <option value="0" selected>(please select:)</option> <option name="site">Llandaf</option> <option name="site">Cyncoed</option> <option name="site">Howard Gardens</option> <option name="site">Colchester Avenue</option> </select> <p></p> <select name="ssid_name"> <option value="0" selected>(please select:)</option> <option name="ssid_name">Guest</option> <option name="ssid_name">Conferences</option> </select> <p><input type="text" name="ssidpass"></P> <input name ="submit" type="submit" value="submit"> </form> </div> <?php require_once "php-telnet/PHPTelnet.php"; if ($_POST['submit']){ $telnet = new PHPTelnet(); // if the first argument to Connect is blank, // PHPTelnet will connect to the local host via 127.0.0.1 $result = $telnet->Connect($ip,'admin','*****'); if ($result == 0) { $telnet->DoCommand('config wlan disable '.$ssid_id.''); // NOTE: $result may contain newlines $telnet->DoCommand('config wlan security wpa1 pre-shared-key enable 1 ascii '.$ssidpass.''); $telnet->DoCommand('config wlan enable '.$ssid_id.''); // say Disconnect(0); to break the connection without explicitly logging out $telnet->Disconnect(); } } ?> <?php ini_set("SMTP", "e2k3vs01.internal.uwic.ac.uk"); $to = "jhancock@uwic.ac.uk"; $subject = "WiFi Password"; $headers ="From: WiFi@uwic.ac.uk"; $body = "The WiFi password for the $ssid_id on the $ip campus, has been manually reset to: $ssidpass"; mail($to, $subject, $body, $headers); die(); ?> Quote Link to comment Share on other sites More sharing options...
uwictech Posted November 13, 2009 Author Share Posted November 13, 2009 any ideas guys? Quote Link to comment Share on other sites More sharing options...
uwictech Posted November 13, 2009 Author Share Posted November 13, 2009 Sorry, fixed it. Need to wrapp the email send around the submit button! J. 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.