
elentz
Members-
Posts
228 -
Joined
-
Last visited
Everything posted by elentz
-
I wonder how I missed that... Anyway it works like it should. Thank you Barand!!
-
got it, no errors now.. I didn't correctly connect to Mysql either. Had to fix that. No update to the DB yet It reads the table contents. Just to show what I am working with, mostly from barand. I do get the echo connected successfully Thanks // Create connection try { $db = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); // set the PDO error mode to exception $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected successfully"; } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); }if ($_SERVER['REQUEST_METHOD']=='POST') { $updt = $db->prepare("UPDATE extensions SET reset = ? WHERE id = ? "); foreach ($_POST['extid'] as $id) { //$reset = isset($_POST['reset'][$id]) ? $_POST['reset'][$id] : 0; // if checkbox wasn't posted then it is "0" $updt->execute; } } // // GET EXTENSIONS DATA // // Check connection if ($db->connect_error) { die("Connection failed: " . $db->connect_error); } $exdata = ''; $res = $db->query("SELECT id , extension , reset FROM extensions "); foreach ($res as $r) { $chk = $r['reset']==1 ? 'checked':''; $exdata .= "<tr><td>{$r['extension']}</td> <td> <input type='hidden' name='extid[]' value='{$r['id']}'> <input type='checkbox' name='reset[{$r['id']}]' value='1' $chk> </td> </tr>\n"; } ?> <html> <head> <meta name="generator" content="PhpED 18.0 (Build 18044, 64bit)"> <title>Reboot Phones</title> </head> <body> <h1>Extensions</h1> <form method='post'> <table> <tr><th>Extension</th><th>Reset</th></tr> <?=$exdata?> </table> <input type='submit' name='btnSub' value='Submit'> </form> <button type="button"><a href="restart.php">Click to reboot the phones</a></button> </body> </html>
-
Hmm, My system is using php version 5.6 I cannot change it either. Would that be the reason that the http error log throws that error?
-
I have the script retrieving the info from the table so the connection is correct. The submit doesn't update the table. In the logs I am getting this: mysqli_stmt::execute() expects exactly 0 parameters, 1 given on line 20 $updt->execute( [ $reset, $id ] ); I also have to comment out this line in order for the page to work as above $reset = $_POST['reset'][$id] ?? 0; // if checkbox wasn't posted then it is "0"
-
Thank You Barand!
-
Sometimes I might not make my needs as clear to others as it might appear in my head. Thanks fo ryour help
-
got it. I originally envisioned a bunch or rows with a checkbox on the end. check all the boxes you want, click a submit button to update the DB and run another page to reboot the phones. If I misspoke and indicated that I wanted to use the checkbox as a submit type of operation I apologize, not what I meant. I haven't had anytime to work on this at all today, maybe tomorrow Thanks
-
I think I have the idea. Thanks
-
Ah I think I understand now
-
Instead of a submit button could a checkbox work? What about a Yes/No dropdown? I want to select the phones I want to restart, update a DB table and then use a submit button to go to another page that will run a query to reset the phones.
-
I do have a primary key assignedto the id field
-
ginerjm That sounds like the way to go, I could have any number of rows and updating as each is checked would be best. Gizmola, I think I do have a primary key on that table, can't check from home tho.
-
I think I get what you are saying. I will see what I can do. Thanks
-
I do have some code. $sql = "select * from extensions"; $result = mysqli_query($link,$sql) or die(mysql_error()); echo "<table border='3'> <tr> <th>Extension #</th> <th>Reboot</th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['extension'] . "</td>"; echo "<td>'."<input type='checkbox' class='form' value='1' name='checkbox[" . $row['reset'] . "]' />".'</td>"; echo "</tr>"; } echo "</table>"; ?> I want to a. show the current value of the row reset and b. to have the ability to check the checkbox and change the value in the mysql table. I know I need to make the whole thing a form so that it can update the DB
-
I have a need to create a form that will get info from a mysql table, show that info, two fields one of which I want to be a checkbox that will need to update the table with either a 0 or a 1. I will later use that info. I have searched all over and haven't found what I am looking for. I can find tutorials for creating checkboxes but nothing what I need / want
-
This did the trick! $sql = "select extension from extensions"; $result = mysqli_query($link,$sql) or die(mysql_error()); while($row = mysqli_fetch_array($result)) { $out = shell_exec("asterisk -rx 'sip notify CQ_Phone-Reboot " . $row['extension'] . "'"); //echo str_replace("\n", "<br/>", $out); } Thanks so much for the help !
-
Here's all I have at the moment. The table does populate with the correct info $sql = "select extension from extensions"; $result = mysqli_query($link,$sql) or die(mysql_error()); echo "<table border='3'> <tr> <th>Extension #</th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['extension'] . "</td>"; } echo "</table>"; //$phones = "SELECT extension FROM extensions where extension IN(".implode(',',$array).")"; //$phones = array(201,202,204); foreach ($result as $phone) { $out = shell_exec("asterisk -rx 'sip notify CQ_Phone-Reboot $phone'"); echo str_replace("\n", "<br/>", $out); } ?> Thanks
-
Thanks for the reply. Using your suggestion I am getting this: Undefined variable: array in /var/www/html/cqadmin/Assign/restart.php on line 23 Warning: implode(): Invalid arguments passed in /var/www/html/cqadmin/Assign/restart.php on line 23 Line 23 is the new code. Barand Point taken
-
I have put together a method to reboot my SIP phones. I can use an array to feed the foreach and it works fine. Now I need to take a step or two further. I want to use the result of a query in the array. The next step would be to instead of having all the extensions in the array , to be able to select extensions from a form. But for now getting the initial array is what I am needing help with. //*****This doesn't work ******* //$phones = "SELECT extension FROM `extensions`IN(".implode(',',$array).")"; //******This works******** $phones = array(201,202,204); foreach ($phones as $phone) { $out = shell_exec("asterisk -rx 'sip notify CQ_Phone-Reboot $phone'"); echo str_replace("\n", "<br/>", $out); } Thanks
-
I got netbeans and used it to make the page, and (After the light went on)and I realized what benanamen was saying, voila it all came together and works the way I want it to. Thanks everyone for the patience and nudging in the direction I needed to go.
-
got me on that one. I use Winsyntax for text, never trusted Notepad that much
-
Actually nothing. I will try them out. Do either one had the head slap function for bone head entries??
-
Actually nothing. I will try them out
-
I didn't include the php in the code i last posted. That is working. Suggestion for a fdee ide?
-
Here is what I have now. I think I fixed the broken tag. The table renders with 3 cols and 2 rows with borders all around. <body> <style> table, th, td { border: 1px solid black; } </style> <table> <tr> <th>Temp</th> <th>Pressure</th> <th>Humidity</th> </tr> <tr> <th>?php echo $t; ?</th> <th>?php echo $p; ?</th> <th>?php echo $hum; ?</th> </tr> </table> </body> </html> I result I get in the 1st col 2nd row ?php echo $t; ? the next ?php echo $p; ? and the last ?php echo $hum; ? The result I expect are the vaiables that print in the PHP code. I really appreciate the help