Jump to content

smidgen11

Members
  • Posts

    17
  • Joined

  • Last visited

    Never

Everything posted by smidgen11

  1. my work around was to run a bash script to execute instead of generating a new connection id to mysql via php. Im using flush tables with read lock and putting mysql to sleep so that nothing can write only read. NOTE: i have this at a global level because i am not using the box for anything else. all other tables and databases will lock up as well. here is what I ended up doing. lock button: exec("bash /var/www/html/path/mysqllock.sh"); bash for mysqllock: #! /bin/bash /usr/bin/mysql -u root -pX -e "FLUSH TABLES WITH READ LOCK; SELECT SLEEP(86400)" Unlock: include("sqlconnect.php"); //Query the mysql processlist and kill all process ids found including the sleep process id $result = mysql_query("SHOW FULL PROCESSLIST"); while ($row=mysql_fetch_array($result)) { $process_id=$row["Id"]; if ($row["Time"] > 2 ) { $sql="KILL $process_id"; mysql_query($sql); } echo "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">"; } Im not saying this is the proper way to do it, but this is a very simple way to accomplish what I needed, which was to prevent users from writing to the db when i hit lock and allow when i hit unlock.
  2. Thanks that is exactly what is happening. I was hoping it just plain unlocks the table for good until unlocked. To unlock the table I was going to write a script with an html form action button to simply run the UNLOCK TABLES query. Is there anyway to do a simple lock the database/unlock the database that does not get affected but sessions? If not, Im trying to think of another way to simply stop my php mysql scripts from executing if a user attempts to run them when the lock button is pushed. Maybe changing to password variable in my sqlconnect file or something.
  3. I did see that site and have followed the correct syntax to get it to work from inside my other php sql files. I cant figure out why FLUSH TABLES WITH READ LOCK will not work on its own. Does mysql_query("FLUSH TABLES WITH READ LOCK") prevent proceeding mysql queries from running or something?
  4. Hi, Im trying write a simple command to lock my database but Im having some trouble. Im using [code=php:0] include("sqlconnect.php"); mysql_query("FLUSH TABLES WITH READ LOCK"); echo "db is locked"; [/code] This is not working however. I can run "FLUSH TABLES WITH READ LOCK" from the mysql cli directly and get it to work but not from a form action html that calls my file. Just to test my syntax I threw mysql_query("FLUSH TABLES WITH READ LOCK"); in front of one of my insert mysql queries and the database DOES lock. I cant figure out why I cant get this to work on its own from a single file. Any ideas?
  5. Hi, I am trying write the contents of a php file's output, which echos out a small output of text based on variables and calulations, to a single file. I have tried fwrite and file_get_contents. When I run my code I get the file to create but the file it creates only outputs "1". Here is a look at my code: fwrite version: $text= include '$Site-2851.php'; $file = fopen("myfile.txt","w"); echo fwrite($file, $text); fclose($file); file_get_contents version: $text= include '$Site-2851.php'; $file = 'myfile.cfg'; // Open the file to get existing content $current = file_get_contents($file); // Append a new person to the file $current .= $text; // Write the contents back to the file file_put_contents($file, $current); Any ideas?
  6. HI, I have some code that saves a zip file to a directory that contains a csv file. The code I currently have, successfully creates a zip file containing the csv file I want to create. The issue is, the only record that gets written to the csv file inside the ZIP is the last record of the array. I know this is probably something very simple but I am having some trouble with it. Ive been google'ing but to no avail. Here is my code: <?php include("sqlconnect.php");?> <?php $sql="select Username as 'ALIAS', Extension as 'DTMF_ACCESS_ID' from $tbl_entering"; $result=mysql_query($sql); $filename = 'entering.VMAIL'; $filename = $filename."_".date("Y-m-d_H-i",time()); $header="ALIAS,DTMF_ACCESS_ID\n"; while($rows=mysql_fetch_array($result)) { $data="$rows[0],$rows[1]\n"; } $csvdata= $header.$data; $zipname = 'Batch_'.date("Y-m-d_H",time()); $zip = new ZipArchive; $res = $zip->open("./batch/$zipname.zip", ZipArchive::CREATE); if ($res === TRUE) { $zip->addFromString("$filename.csv", $csvdata); $zip->close(); echo 'ok'; } else { echo 'failed'; } ?> Thanks for the help.
  7. finally...SOLVED. all i had to do was add "php" to this line. BEFORE <td><input name="Selected" type="radio" id="radio[]" value="<? echo $rows['Mac']; ?>"></td> AFTER <td><input name="Selected" type="radio" id="radio[]" value="<?php echo $rows['Mac']; ?>"></td> thanks guys
  8. just to add a more descriptive answer to what my issue is. When I try to echo $del_id on undoentering.php I get: <? echo $rows['Mac']; ?> Which is the text written in my radio button's value.
  9. Hopefully this will make sense. So a number of records are queried and output into the table: <?php echo "<td>"; echo $rows['Location']; echo "</td>"; echo "<td>"; echo $rows['FirstName']; echo "</td>"; echo "<td>"; echo $rows['LastName']; echo "</td>"; echo "<td>"; echo $rows['UserName']; echo "</td>"; echo "<td>"; echo $rows['Extension']; echo "</td>"; echo "<td>"; echo $rows['Mac']; echo "</td>"; echo "<td>"; echo $rows['Type']; echo "</td></tr>"; ?> From this table, each record has a radio button next to hit. When the radio button selects a row the Undo (submit button) is clicked and the "Mac" field of the selected record should post so that my next php file (undoentering.php) will be able to echo the value. Undoentering.php: $del_id = ( $_POST['Selected'] ); echo $del_id;
  10. Hi, I have a sql query at the top that runs and echos the result to the page. Each row in the table has a radio but to select and then a submit button at the bottom of the table which should run the form's action which is another php script. Here is what I have for the table portion: <form name="form1" method="post" action="undoentering.php"> <?php echo "<table>"; echo "<thead>"; echo "<tr>"; echo "<td>Select</td>"; echo "<td>Location</td>"; echo "<td>First Name</td>"; echo "<td>Last Name</td>"; echo "<td>User Name</td>"; echo "<td>Extension</td>"; echo "<td>Mac</td>"; echo "<td>Type</td>"; echo "</tr>"; echo "</thead>"; ?> <?php while($rows=mysql_fetch_array($result)){ ?> <?php echo "<tr>"; ?> <td><input name="Selected" type="radio" id="radio[]" value="<? echo $rows['Mac']; ?>"></td> <?php echo "<td>"; echo $rows['Location']; echo "</td>"; echo "<td>"; echo $rows['FirstName']; echo "</td>"; echo "<td>"; echo $rows['LastName']; echo "</td>"; echo "<td>"; echo $rows['UserName']; echo "</td>"; echo "<td>"; echo $rows['Extension']; echo "</td>"; echo "<td>"; echo $rows['Mac']; echo "</td>"; echo "<td>"; echo $rows['Type']; echo "</td></tr>"; ?> <?php } ?> <td colspan="8" align="center"><input name="delete" type="submit" id="delete" value="Undo"></td> My issue is that nothing POSTs to the next page. When doing it like this the record show empty boxes yet the correct number of empty rows is output: <table> <form name="form1" method="post" action="undoexiting.php"> <thead> <tr> <td>Select</td> <td>Location</td> <td>First Name</td> <td>Last Name</td> <td>User Name</td> <td>Extension</td> <td>Mac</td> <td>Type</td> </tr> </thead> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><input name="Selected" type="radio" id="radio[]" value="<? echo $rows['Mac']; ?>"></td> <td><? echo $rows['Location']; ?></td> <td><? echo $rows['FirstName']; ?></td> <td><? echo $rows['LastName']; ?></td> <td><? echo $rows['UserName']; ?></td> <td><? echo $rows['Extension']; ?></td> <td><? echo $rows['Mac']; ?></td> <td><? echo $rows['Type']; ?></td> </tr> <?php } ?> <tr> <td colspan="8" align="center"><input name="Undo" type="submit" id="undo" value="Undo"></td> </tr> </html> Can anyone lend some knowledge on what I may be doing wrong on the first script. And yes, I did and still am using google. Thanks
  11. awsome.....that did it... thanks a lot
  12. I know this is probably something very dumb but I am having trouble with my if else. I have a sql query that looks for a record and if nothing is found it echos a warning. <?php $sql7="SELECT * FROM `$tbl_name2` WHERE Mac = '$Mac' AND Type = '$Type'"; $result7=mysql_query($sql7); if($result7) { while($row=mysql_fetch_array($result7)) echo "The phone you are using with mac $row[0] $row[1] is a Cisco IP Phone! <br>" ; } else { echo "<img src=\"stop.png\"/> The phone you are trying to use with mac $row[0] $row[1] is not a correct Mac\Type. <br> Please confirm the mac and type again."; } ?> I believe my syntax is correct as my if echo works fine. However, when no records are found I do not see my last else echo. Any input?
  13. Unfortunately, due to the potential of needed more (than 2) reports from one table in the future, I think the zip option is going to be the way to go. Ive been google'ing the zip option for days but cant seem to get anywhere. Do you know of an example of this somewhere on the web?
  14. I am trying to export multiple csv files to download from 2 separate tables in my database. Some background: I have a web app that links to a phpmyadmin database. There are 2 tables in the database (entering and exiting). These tables hold the phone inventory information of employees currently entering or exiting the organization. The fields in my tables are: location, firstname, lastname, username, extension, mac, type What I am trying to do is export the data in these 2 tables to CSV (which I have working now) but I need to have multiple CSVs for each. For example, for my exiting table, I need to have one CSV export all the fields in the table and I also need another CSV to export just the location and username field. I have a simple html form with a submit button which is currently working now: <form action="exportexiting.php" method="POST" style="width: 456px; height: 157px"> <div> <fieldset> <legend style="width: 102px; height: 25px"><strong>Entering CSV:</strong></legend> <input name="Export" type="submit" id="Export" value="Export"> </fieldset><br/> </div> </form> This links to my exportexiting.php file: <?php $host = 'localhost'; $user = 'root'; $pass = 'xxxx'; $db = 'PhoneInventory'; $table = 'exiting'; // Connect to the database $link = mysql_connect($host, $user, $pass); mysql_select_db($db); require 'exportcsv.inc.php'; exportMysqlToCsv($table); ?> Then to exportcsv.inc.php: <?php function exportMysqlToCsv($table,$filename = 'export.csv') { $csv_terminated = "\n"; $csv_separator = ","; $csv_enclosed = ''; $csv_escaped = "\\"; $sql_query = "select * from $table"; // Gets the data from the database $result = mysql_query($sql_query); $fields_cnt = mysql_num_fields($result); $schema_insert = ''; for ($i = 0; $i < $fields_cnt; $i++) { $l = $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, stripslashes(mysql_field_name($result, $i))) . $csv_enclosed; $schema_insert .= $l; $schema_insert .= $csv_separator; } // end for $out = trim(substr($schema_insert, 0, -1)); $out .= $csv_terminated; // Format the data while ($row = mysql_fetch_array($result)) { $schema_insert = ''; for ($j = 0; $j < $fields_cnt; $j++) { if ($row[$j] == '0' || $row[$j] != '') { if ($csv_enclosed == '') { $schema_insert .= $row[$j]; } else { $schema_insert .= $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, $row[$j]) . $csv_enclosed; } } else { $schema_insert .= ''; } if ($j < $fields_cnt - 1) { $schema_insert .= $csv_separator; } } // end for $out .= $schema_insert; $out .= $csv_terminated; } // end while header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Length: " . strlen($out)); // Output to browser with appropriate mime type, you choose header("Content-type: text/x-csv"); //header("Content-type: text/csv"); //header("Content-type: application/csv"); header("Content-Disposition: attachment; filename=$filename"); echo $out; exit; } ?> Again, this is working perfectly for only exporting all the data from the exiting table into one CSV file. My question is, how can I make my one submit button export the 2 CSV files that I need? Thanks for the help...
  15. Hi, Im creating a simple inventory management for IP phones. I have 1 database with 4 tables (phoneinventory, entering, exiting, available) all contain the same structure. I have a very simple form in which you can search for a users phone by username. After "SELECT * FROM $tbl_name WHERE UserName='$UserName'"; runs you can select the found user (pulled from the array) with a checkbox. The first query by UserName displays the correct results just doesnt run these next command when selected: $sql1 = "DELETE FROM $tbl_name WHERE UserName='$del_id'"; $sql2 = "DELETE FROM $tbl2_name WHERE UserName='$del_id'"; $sql3 = "INSERT INTO $tbl3_name SELECT * FROM $tbl_name WHERE UserName='$del_id'"; $sql4 = "INSERT INTO $tbl4_name SELECT * FROM $tbl_name WHERE UserName='$del_id'"; My problem is that my script works fine if I do not filter results by username. It does not work when WHERE UserName='$UserName'"; is added to $sql. Here is most of my php file: <?php $host="localhost"; // Host name $username="xxxx"; // Mysql username $password="xxxx"; // Mysql password $db_name="PhoneInventory"; // Database name $tbl_name="phoneinventory"; // Table name $tbl2_name="entering"; // Table name $tbl4_name="exiting"; // Table name $tbl3_name="available"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name WHERE UserName='$UserName'"; $result=mysql_query($sql); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="form1" method="post" action=""> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> </tr> <tr> <td align="center" bgcolor="#FFFFFF" style="width: 43px">Select</td> <td align="center" bgcolor="#FFFFFF"><strong>Location</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>FirstName</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>LastName</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>UserName</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Extension</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Mac</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Type</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center" bgcolor="#FFFFFF" style="width: 43px; height: 27px;"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['UserName']; ?>"></td> <td bgcolor="#FFFFFF" style="height: 27px"><? echo $rows['Location']; ?></td> <td bgcolor="#FFFFFF" style="height: 27px"><? echo $rows['FirstName']; ?></td> <td bgcolor="#FFFFFF" style="height: 27px"><? echo $rows['LastName']; ?></td> <td bgcolor="#FFFFFF" style="height: 27px"><? echo $rows['UserName']; ?></td> <td bgcolor="#FFFFFF" style="height: 27px"><? echo $rows['Extension']; ?></td> <td bgcolor="#FFFFFF" style="height: 27px"><? echo $rows['Mac']; ?></td> <td bgcolor="#FFFFFF" style="height: 27px"><? echo $rows['Type']; ?></td> </tr> <?php } ?> <tr> <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td> </tr> <? // Check if delete button active, start this if($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql1 = "DELETE FROM $tbl_name WHERE UserName='$del_id'"; $sql2 = "DELETE FROM $tbl2_name WHERE UserName='$del_id'"; $sql3 = "INSERT INTO $tbl3_name SELECT * FROM $tbl_name WHERE UserName='$del_id'"; $sql4 = "INSERT INTO $tbl4_name SELECT * FROM $tbl_name WHERE UserName='$del_id'"; $result = mysql_query($sql1); $result = mysql_query($sql2); $result = mysql_query($sql3); $result = mysql_query($sql4); } // if successful redirect to home.html if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=home.html\">"; } } mysql_close(); ?> </table> </form> </td> </tr> </table> </html> Anyone have any ideas why it would work perfectly when using $sql="SELECT * FROM $tbl_name"; as my first query rather than being able to filter by UserName? Thanks
×
×
  • 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.