
elentz
Members-
Posts
228 -
Joined
-
Last visited
Everything posted by elentz
-
Hmm, Didn't work I got ?php echo $t; ? in the cell
-
I have a php page that gets data from several txt files. I want to take those variables and put them into a table. I don't quite know how to make it work. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="refresh" CONTENT="15" /> <title>Lentz Abode</title> </head> <?php //File to read $file = '/sys/bus/w1/devices/28-000004d139da/w1_slave'; //Read the file line by line $lines = file($file); //Get the temp from second line $temp = explode('=', $lines[1]); //Setup some nice formatting (i.e. 21,3) $temp = number_format($temp[1] / 1000, 2, '.', ''); $temp_f = number_format(($temp * 9.0 / 5.0 + 32.0),2,'.',''); $fahrenheit=$temp*9/5+32; $temp1=number_format($fahrenheit,1); print"<h4>The Kitchen Temp is: $temp1</h4>"; //*************BME280 code ******************** //Barometric PressureBME280 $pressure=file_get_contents("/var/www/html/BME280/pressure.txt"); $press=$pressure*0.0002952998751; $p=number_format($press,2); //Humidity BME280 $humidity=file_get_contents("/var/www/html/BME280/humidity.txt"); $hum=number_format($humidity/1000,2); //Temperature BME280 $temp2=file_get_contents("/var/www/html/BME280/temp.txt"); $t=number_format(($temp2 /1000 * 9.0 / 5.0 + 32.0),1,'.',''); print "<h4>The Barometric Pressure is: $p</h4>"; print "<h4>The Humidity is: $hum%</h4>"; print "<h4>The Temperature is: $t</h4>"; ?> <body> <style> table, th, td { border: 1px solid black; } </style> <table width="30%" <tr> <th>Temp</th> <th>Pressure</th> <th>Humidity</th> </tr> <tr> <th>$t</th> <th>$p</th> <th>%hum</th> </tr> </table> </body> </html>
-
Need example of inserting form data into a Mysql db
elentz replied to elentz's topic in PHP Coding Help
mac_gyver You are 100% correct, in what I want to do. It sounds like you have some history with this type of project. This project will reside on every machine I sell and will be on the same network as the phones. I am only familiar with using TFTP for provisioning the phones. If I use the http provisioning I can turn off the tftp server. There is an option to use HTTP but I do not know how it operates. As you say it might be the better way to do this with the page creating the information "on the fly" so to speak. I will have to look into how that works. I have a couple of weeks before the powers that be at my company will be breathing down my neck to roll this out. I did not pursue putting all the configuration elements into a DB. I thought it would be easier to create the files individually. I really appreciate your help in all this. -
Need example of inserting form data into a Mysql db
elentz replied to elentz's topic in PHP Coding Help
Mac_gyver, Thank you for your explanation. I think I am starting to get it. Although I am wondering if I have not thought this out enough and this is not the way to achieve what I ultimately need to do. Ultimately, I need to take the extension number, and the secret and insert it into a text file that is named the template name and then rename that file the mac address.cfg. There could be 5 files to be created/appended or 105 of them. It will be dynamic. I have already figured out creating the template files and how to append them. The form I posted retrieves the extension, secret, MAC and template information from three DB tables. The Mac and the Template are then on this form I have "assigned" to each other. I thought it would be easier to insert all this into a new table. Maybe you could advise me if I should pursue the help in this thread or go another way. Thanks -
Need example of inserting form data into a Mysql db
elentz replied to elentz's topic in PHP Coding Help
Here is the form code: <form action="insert.php" method="post"> <?php error_reporting(E_ALL); ini_set('display_errors','On'); $link = mysql_connect("localhost", "", "") or die ('Error connecting to mysql' . mysql_error()); mysql_select_db("cqadmin"); $sql2 = "SELECT extension, secret from extensions;"; $result2 = mysql_query($sql2) or die(mysql_error()); echo "<table border='3'> <tr> <th>Extension #</th> <th>Secret</th> <th>MAC Address</th> <th>Template</th> </tr>"; while($row = mysql_fetch_array($result2)) { $sql = "SELECT id , mac FROM phones order by mac;"; $result = mysql_query($sql) or die(mysql_error()); $sql1 = "SELECT id , templatename FROM templates order by templatename;"; $result1 = mysql_query($sql1) or die(mysql_error()); echo "<tr>"; echo "<td>" . $row['extension'] . "</td>"; echo "<td>" . $row['secret'] . "</td>"; echo "<td> <select name='phone'>"; while($rowA = mysql_fetch_array($result)) { echo '<option value="' . $rowA['id'] . '">' . $rowA['mac'] . '</option>'; } echo "</select></td>"; echo "<td><select name='template'>"; while($rowB = mysql_fetch_array($result1)) { echo '<option value="' . $rowB['id'] . '">' . $rowB['templatename'] . '</option>'; } echo "</select></td>"; echo "</tr>"; } echo "</table>"; ?> <input type="submit" value="Submit your selections"> </body> </html> Here is the insert.php file <?php echo "You got here"; //***********Get the Assignment information ************* $ext = $_POST['extension']; $password= $_POST['secret']; $macaddress = $_POST['mac']; $template = $_POST['template']; Echo "$ext"; Echo "$password"; Echo "$macaddress"; Echo "$template"; ?> When I hit the submit button I get "You got here" I know big deal... I know I need to use Mysqli instead of mysql as well. I am pretty sure I need to use a while loop but I do not know how to apply it to multiple rows. There will be an unknown number of rows each time this form is used. There are 4 strings of data to be inserted into the DB table each time. I put the other code in the insert file to see if I would get anything. -
Need example of inserting form data into a Mysql db
elentz replied to elentz's topic in PHP Coding Help
mac_gyver, The info is in a form that the user fills out. Your third comment is what I am looking for. So an example of how to do that would be great! Thanks -
I have a form with a table with columns and many rows. The form uses Post and submits to an insert.php I am looking for an example of how I can insert the table info into a mysql table. I know I should use a while loop but unsure how to step through the form info. Can someone suggest or provide and example that I can follow, or a tutorial somewhere? Thanks
-
Thanks for the direction guys!
-
I freely admit I am pretty green in alot of this stuff. I have a php page that runs arp-scan and returns information on MAC addresses for the network. It takes 10 seconds probably. I am looking for a visual indication to tell the user that the scan is in progress. I have no idea what this is even called. Can someone point me in the direction I need to go to figure this out? Thanks
-
Success The Notice I had was caused by this line: list($ip, $mac) = explode("\t", $host); Through some experimentation and googling I came up with this: list($ip, $mac) = array_pad(explode("\t", $host),2,null); The notice is a thing of the past. I now get both the IP and the MAC addresses of the devices in the network. Now to get it into the DB Thank you everyone for all your help!
-
I am getting an error of: Undefined Offset: 1 on this line list($ip, $mac) = explode("\t", $host);
-
Jacques1 That gets me pretty much what I want! Fussing with it a little I can get just the MAC address and now all I have to do is get it into my DB table.
-
Getting closer ! Using : $deviceData = preg_split('/\s+/', trim($output)); Instead of explode I am getting : Array ( [0] => 10.1.10.76 [1] => 80:82:87:03:9d:38 [2] => 10.1.10.84 [3] => 80:82:87:03:d8:58 [4] => 10.1.10.235 [5] => 80:82:87:03:19:f0 ) when I use print_r ($devices);
-
When I do a chrome inspect on the page it appears just as Jacques1 has indicated, no commas, ", ' just spaces between the IP and the MAC. I am going to try preg_split and see what happens
-
Thanks Psycho for your help. I think I uderstand what you have given me. It doesn't quite work yet. I get this error so far: Notice: Undefined offset: 1 in /var/www/html/cqadmin/macfind.php on line 11 When I set a print_r $devices I get this. To me it looks like the chunking isn't figuring out how to split the $output. Array ( [0] => Array ( [0] => 10.1.10.76 80:82:87:03:9d:38 10.1.10.84 80:82:87:03:d8:58 10.1.10.235 80:82:87:03:19:f0 ) ) Here is the code I used for the results I got <?php error_reporting(E_ALL); ini_set('display_errors', '1'); $output = shell_exec("sudo arp-scan --interface=eth0 --localnet --retry 1 --timeout 50 --numeric --plain --quiet | grep -e 80:82:87"); $deviceData = explode(' ', $output); $devices = array_chunk($deviceData,1); Print_r ($devices); foreach($devices as $device) { $deviceIP = $device[0]; $deviceMAC = $device[1]; //Validate the values and then (if valid) insert/update into DB } ?> Thanks
-
Thanks guys for the replies. The print_r is as far as I got. I needed a way to show that I was getting a result I could live with before trying to get it into a DB. I will check out the links you guys have offered. Thanks
-
I just for some reason cannot wrap my head around this. I have this PHP code $output = shell_exec("sudo arp-scan --interface=eth0 --localnet --retry 1 --timeout 50 --numeric --plain --quiet | grep -e 80:82:87"); print_r ($output) Running this I get this on the page: 10.1.10.76 80:82:87:03:9d:38 10.1.10.84 80:82:87:03:d8:58 10.1.10.235 80:82:87:03:19:f0 This shows three devices on my network. IP address and a MAC address. I need to take that information and insert it into a db table. Can someone help me with how to accomplish this? Thanks
-
Ok Jacques1 I get it, you are right. I think I will just use a txt file and write to that instead. I have done some testing this morning and it looks like I can create the file in the format I want. My concern now is being able to take that file and read it back to the html page that wrote it. The users might want to make changes, without starting over.
-
Benanamen, I was unaware that the method I was using was obsolete. I will look into PDO Jacques1, For this topic the table had only two fields. The table that I was going to work with in this instance was only going to have 16 fields at most. You must be referring to a previous post of mine. For the record I broke up those 400 fields I needed into different tables. I am looking into just writing a file at this point.
-
I am getting the following error when running an update 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 '.1.address='10.1.10',account.1.sip_server.2.address='dfgga' WHERE id=1' at line 1 This is the Query: mysql_query("UPDATE global_settings SET account.1.sip_server.1.address='$sipserver1',account.1.sip_server.2.address='$sipserver2' WHERE id=$id") or die(mysql_error()); MySql is version 5.1.73 The variables are being passed from the PHP code and the id is correct. I am at a loss as to what is going on. Thanks for any help
-
It will actually be easier than you imagine. There will be a common "template" that will create all the buttons and the common features of the phone. Each phone cfg file will be identical with the exception of the extension # and a password.. The cfg file will be named with the MAC address of the phone.
-
I am in need of a method to provision VoIP phones. The cfg file I need to create has approx 430 potential entries. I plan on using a php page to enter the info and then use a query to get the info into the DB. The fields I asked about will be static. I have complete control over the server, I am using Centos6, Apache and MySql So is there a limit to the number of fields in a table? I could break up the number of fields into different tables. When all is said and done I need to put it all together and create a file to configure the phone.
-
I have a list of approx 400 new fields I need to create in a new table. They can all be varchar 40 for the most part. I have the list in a csv. I can find all sorts of ways to upload the file as data but nothing to create fields out of the list I have. I am looking for suggestions / solutions on how to get this done. Thanks