Jump to content

jacko_162

Members
  • Posts

    405
  • Joined

  • Last visited

Everything posted by jacko_162

  1. i have the below code; // start of image upload $insert_id = mysql_insert_id() or die("Unable to get insert id for image name.<br>" . mysql_error()); extract($_POST); $fileArray = array(); $error=array(); $extension=array("jpeg","jpg","png","gif"); foreach($_FILES["files"]["tmp_name"] as $key=>$tmp_name) { $file_name=$_FILES["files"]["name"][$key]; $file_tmp=$_FILES["files"]["tmp_name"][$key]; $ext=pathinfo($file_name,PATHINFO_EXTENSION); if(in_array($ext,$extension)) { if(!file_exists("../images/listings/".$file_name)) { $filename=basename($file_name,$ext); $newFileName=$insert_id."_".mt_rand(1, 99999).".".$ext; move_uploaded_file($file_tmp=$_FILES["files"]["tmp_name"][$key],"../images/listings/".$newFileName); // NOW ADD NAME TO DATABASE $insertimg = "insert into $table3 (name,insert_id) values ('".$newFileName."','".$insert_id."')"; mysql_query($insertimg); array_push($fileArray, "$newFileName"); } else { $filename=basename($file_name,$ext); $newFileName=$filename.mt_rand(1, 99999).".".$ext; move_uploaded_file($file_tmp=$_FILES["files"]["tmp_name"][$key],"../images/listings/".$newFileName); // NOW ADD NAME TO DATABASE $insertimg = "insert into $table3 (name,insert_id) values ('".$newFileName."','".$insert_id."')"; mysql_query($insertimg); array_push($fileArray, "$newFileName"); } } else { $insertimg = "insert into $table3 (name,insert_id) values (' ','".$insert_id."')"; mysql_query($insertimg); array_push($error,"$file_name, "); } } // end of image upload I have managed to get this working fine, and it uploads the files and inserts data into a table. now i'm working on the edit page code and struggling to figure out how i can get this data down and display it, should i pull the data, echo the images and have some sort of IF statement to say if image exists then show a delete checkbox and if no image exists then show another file input? I'm also not sure if the add images code is the right way of doing it by adding the images to a separate line in the table or adding the array into the table for ease of use. i am not great at PHP and any help, or links to code would be great. Thanks
  2. ok so i worked out a JOIN query; SELECT c1.id AS parent, c1.view, c2.filename, c2.name, c2.id FROM category c1 INNER JOIN category c2 ON c1.id = c2.parent GROUP BY c2.name ORDER BY c1.id on my code on the page its indexing the category by subcategory but i cant get it to display the parent category name // pre-process the data and index it by category, creating an array of arrays with the main index being the category$data = array(); while($row = mysql_fetch_assoc($result)) { $data[$row['parent']][] = $row; } // produce the output from the data foreach($data as $category => $arr) { // Create a table with an id name of the category echo "<table width='100%' id='$category'>\n"; // Write the first row of the table - Category Title echo "<tr class='product-details'><td><span class='catTitle'>$category</span></td></tr></table><table width='100%' id='$category'>\n"; see image;
  3. aah that makes sense, how would i join it to itself? $query = "SELECT products.id, products.category as category, products.name, products.make, images.name as imgName FROM products JOIN images ON products.id = images.insert_id GROUP BY products.id ORDER BY products.category, products.make, products.name"; i obv wont need to query the images.name and/or join it to images.insert_id
  4. OK so i have the following code; <!--START NAVIGATION--> <?php $categories = mysql_query("SELECT * FROM $table2 WHERE parent = '0' AND view = 'Yes' ORDER BY name ASC") or die(mysql_error()); // Select all the root categories and order them alphabetically while($category = mysql_fetch_array($categories)) // Start the loop for root categories { echo '<img src="images/arrow.gif"> <a href="catagory.php?name=' . $category['name'] . '">' . $category['name'] . '</a>'; // Display category name $subcategories = mysql_query("SELECT * FROM $table2 WHERE parent = '" . $category['id'] . "' AND view = 'yes' ORDER BY name ASC") or die(mysql_error()); // Same as the query above but this time the parent is the root category that has just been echoed echo '<br>'; while($subcategory = mysql_fetch_array($subcategories)) // Start the loop for subcategories { echo ' <img src="images/bluearrow.gif"> <a href="subcatagory.php?name=' . $category['name'] . '&sub=' . $subcategory['name'] . '"><em>' . $subcategory['name'] . '</em></a><br>'; // Display subcategory name } } ?> <!--END NAVIGATION--> and it displays a nice list of my category and sub category like so; No i need to keep the category in the same place but where it lists the sub category i want each one to sit in a <div></div> and run in columns to a maximum of 8 before starting a new row, i have done this before but seen as it has 2 main query its confusing the crap out of me. i know this should be in PDO but unfortunately i just have to fix the site up in the next few days for a friend and until then i'm not going to start editing the whole site to use PDO. can anyone help me or point me in a good direction of existing code and where is best to put it. thank you
  5. as above, i am trying to do a small art project but it will mean i need to get a whole load of video thumbnails for certain youtube channels. after searching the internet i come across a lot of PHP related functions but i'm not sure where to go. basically can it be done with PHP/feeds/API etc.. i need to display a PHP web page that just echo's a certain youtubers video thumbnails from say the past 12 months in an OK size (small/medium thumbnail) and then i can manually right click and save each one? any help or even code on the matter would be lovely. or even links to web pages that can do this for me? i'm not even sure it can be done.
  6. aaah i fixed it, i must of copy+paste the wrong code and it put "catagory" again..... once changed to "category" it worked fine <Derp> <Derp> marking topic now SOLVED
  7. i changed: $data = array(); foreach($result as $row) to: $data = array(); while($row = mysql_fetch_assoc($result)) and now i'm getting some data being echo'd but its not formatting in rows of 5, however i have no idea what to change the other foreach() loops to for it to work. here is what i get on page after i changed the above while(); looks like the first chunk is displayed but its not showing the next chunk on a new line underneath??
  8. ok thats sorted my results out in phpmyadmin when i run the query, but when i run the code on my server with the code above i just get a blank page with nothing being echo'd
  9. THANK YOU FOR THE CODE, i only just realised the "catagory" mistake. its actually not catagory its "category". here are the 2x tables; relationship between the two tables are products.id and images.insert_id Images: http://clip2net.com/clip/m513573/4d3b6-clip-98kb.png?nocache=1 Products: http://clip2net.com/clip/m513573/4b6a0-clip-38kb.jpg?nocache=1 so i tried your code and nothing is getting displayed, so for the time being i edited out the PDO and converted to depreciated code, as for now i'm just trying to code the last page and a few bits, then i can edit the whole site and change/learn to PDO. here is the code i have now which i edited it slightly. $items_per_row = 5; // number of items per output row $query = "SELECT products.id, products.category as category, products.name, products.make, images.name as imgName FROM products JOIN images ON products.id = images.insert_id ORDER BY products.category, products.make, products.name"; // execute query $result = mysql_query($query); // pre-process the data and index it by category, creating an array of arrays with the main index being the category $data = array(); foreach($result as $row) { $data[$row['category']][] = $row; } // produce the output from the data foreach($data as $category => $arr) { // Create a table with an id name of the category echo "<table width='100%' id='$category'>\n"; // Write the first row of the table - Category Title echo "<tr><td><span class='catTitle'>$category</span></td></tr>\n"; // output the rows of data $chunks = array_chunk($arr, $items_per_row); foreach($chunks as $chunk) { echo "<tr>"; // start a new row foreach($chunk as $row) { // Write new <td> in table with the data of the title echo '<td width="20%" class="cellPadd"><a href="product.php?id=' . $row['id'] . '"><div class="latest"><div class="latestTop">'; echo "<img class='latestImg' src='images/listings/" . $row['imgName'] . "' border='0' width='100%' />"; echo '</div><div class="latestBottom">'; echo $row["make"]; echo $row["name"]; echo "</div></div></a></td>\n"; } // complete a partial row $count = count($chunk); if($count < $items_per_row) { echo str_repeat("<td> </td>\n", $items_per_row - $count); } echo "</tr>\n"; // end the row } echo "</table>"; // end the table } i tested the SQL query and it gave me this; so its pulling data i just need to LIMIT the 'id' to only show 1 as some products can contain upto 4 images per id. can you check whys it not echo anything?
  10. Trying to show data from a query and echo the results and grouping them by category after printing the category name. So far all is working as intended, however i'm trying to incorporate a count limit so it only echo x5 <td></td> before making a new <tr> row here is my current code; <?php $select = "SELECT * FROM `products` ORDER BY `catagory`"; $result = mysql_query($select); $current_cat = null; $last_cat = null; while ($rows = mysql_fetch_array($result)) { if ($current_cat == null) { // Create a table with an id name of the first table echo "<table width='100% id='" . $rows["catagory"] . "'>"; // Write the first row of the table - Category Title echo "<tr><td><span class='catTitle'>" . $rows["catagory"] . "</span></td></tr><tr>"; } // Set the $current_cat to current loop category value $current_cat = $rows["catagory"]; $getID = $rows['id']; if ($last_cat != null) { if ($current_cat != $last_cat) { // Close table from previous $current_cat echo "</table>"; // Create new table with id name of the category echo "<table width='100%' id='" . $rows["catagory"] . "'>"; // Write the first row of the table - Category Title echo "<tr><td><span class='catTitle'>" . $rows["catagory"] . "</span></td></tr><tr>"; } } //Fetch Image name from "IMAGES" table that corresponds to the product ID $thumbnail_query = mysql_query("SELECT name FROM $table3 WHERE insert_id = $getID LIMIT 1") or die (mysql_error()); //Fetch Results while($data = mysql_fetch_array($thumbnail_query)) { $imgName = $data['name']; } // Write new <td> in table with the data of the title echo '<td width="20%" class="cellPadd"><a href="product.php?id=' . $getID . '"><div class="latest"><div class="latestTop">'; echo "<img class='latestImg' src='images/listings/" . $imgName . "' border='0' width='100%' />"; echo '</div><div class="latestBottom">'; echo $rows["make"]; echo $rows["name"]; echo '</div></div></a></td>'; // set the $last_cat to the value of $current_cat at the end of the loop $last_cat = $current_cat; } echo "</tr>"; // Close the last table after while loop ends echo "</table>"; ?> and i am trying to incorporate; $cnt = 0; // IF COUNT IS MORE THAN 5 MAKE A NEW ROW if($cnt % 5 == 0) echo "CODE HERE FOR NEW ROW!"; $cnt++; can anyone help me as its giving me a headache now. ;( Many thanks
  11. ok so i did this; <?php $pageNr = $page; // Get Current Page Number $from = $pageNr * $num_rec_per_page - 9; // 3 * 10 = 30 $to = $from + 9; // 30 + 9 = 40 // ECHO results Statements echo "Showing Results " .$from. " to " .$to. " "; ?> which works, but the last page may not be equal to exactly 10, for example 47 total results on page 4 it will only show 7 rows, so i did an if statement to check if its the last page and assign different math to the variable. how do i work out the last number?? <?php$pageNr = $page; // Get Current Page Number $from = $pageNr * $num_rec_per_page - 9; // 3 * 10 = 30 //check if last page and change variables if (isset($_GET['page']) && $_GET['page'] == $total_pages) { $to = $count / $num_rec_per_page; } else { $to = $from + 9; } // ECHO results Statements echo "Showing Results " .$from. " to " .$to. " "; ?>
  12. i have built pages that paginate with 10 rows per page (some pages show more but for the moment i want to focus on this particular page) //Define Some Options for Pagination $num_rec_per_page=10; if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * $num_rec_per_page; $results = mysql_query("SELECT * FROM `ecmt_memberlist` WHERE toonCategory='Capital' AND oldMember = 0 ORDER BY CONCAT(MainToon, Name) LIMIT $start_from, $num_rec_per_page") or die(mysql_error()); $results_array = array(); while ($row = mysql_fetch_array($results)) { $results_array[$row['characterID']] = $row; } The above sets the variables for the pagination and below the results are echo with 10 rows per page then i show the pagination links: <?php $sql = "SELECT * FROM `ecmt_memberlist` WHERE toonCategory='Capital' AND oldMember = 0 ORDER BY CONCAT(MainToon, Name)"; $rs_result = mysql_query($sql); //run the query $total_records = mysql_num_rows($rs_result); //count number of records $total_pages = ceil($total_records / $num_rec_per_page); ?> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="center"><div style="width:100%; text-align:center;"> <ul class="pagination"> <li class="selected"> <?php echo "<a href='capitalmember.php?page=1'>".'«'."</a> ";?> </li> <? for ($i=1; $i<=$total_pages; $i++) { echo "<li><a href='capitalmember.php?page=".$i."'>".$i."</a></li> "; }; ?> <li class="selected"> <? echo "<a href='capitalmember.php?page=$total_pages'>".'»'."</a> "; // Goto last page ?></li> </ul></div> <?php $pageNr = $page; // Get Current Page Number $from = $pageNr * $rowsPerPage; // 3 * 10 = 30 // 3 * 10 = 30 $to = $from + $rowsPerPage; // 30 + 10 = 40 echo $pageNr; /* Result: From page 30 to 40 */ ?></td> </tr> </table> this works great and shows me 10 results per page, what i need to work out and work on next is: echo the number of results above the records (for example: "showing records 1 to 10" and then on page 2 "showing records 11 to 21" and page 3 "showing records 22 to 32" how can i work out the maths for this echo? i was thinking along the lines of; <?php $pageNr = $page; // Gets Current Page Number $from = $pageNr * $rowsPerPage; // 3 * 10 = 30 $to = $from + $rowsPerPage; // 30 + 10 = 40 // Now Show Results echo $from; // Echo from echo $to // Echo to ?> but i'm still working on this.. then i need to look at shortening the amount of page links on the page if for example i have 500 records it shows me links 1 to 50 and eats up the page.... Appreciate any help and light onto my problems. Many thanks
  13. I have a Login page which i want to check if the user details (username, password and activation) are valid then redirect user dependent on his/her "accessLevel" (admin, member and none) Admin will be directed to "index.php" Member will be directed to "tasks.php" and none will be redirected to "notActive.php" here is my current code which half works; <?php include ('connect.php'); if(isset($_POST['submit'])) { // Initialize a session: session_start(); // Define $username and $password $username=$_POST['username']; $password=$_POST['password']; // To protect MySQL injection $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $sql="SELECT * FROM ecmt_members WHERE username='$username' and password='$password' AND Activation IS NULL"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $username and $password, table row must be 1 row if($count==1){ // Register $username, $password and redirect to file "index.php" $role = mysql_fetch_array($result); $_SESSION['username']= $username; $_SESSION['password']= $password; //$_SESSION['role']= $role['accessLevel']; if($role['accessLevel'] == "admin"){ $_SESSION['adminuser']=$role['accessLevel']; header("location:index.php"); exit(); } elseif($role['accessLevel'] == "member"){ $_SESSION['user']=$role['accessLevel']; header("location:tasks.php"); exit(); } else { echo "Error: Username, Password or Access Level incorrect! Go Home, you're Drunk!!!"; } } } // End of the main Submit conditional. ?><!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="Content-Type" content="text/html; charset=utf-8" /> <title>Login Form</title> <!-- jQUERY --> <script src="//code.jquery.com/jquery-latest.js"></script> <!-- Add Main CSS --> <link rel="stylesheet" type="text/css" href="../tool/css/main.css"> <!-- Font-Awesome --> <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"> <style> body { background: url(../tool/images/bg1.jpg) no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; } .exactCenter { width:auto; height:auto; position: fixed; top: 50%; left: 50%; margin-top: -200px; ; } </style> </head> <body> <div class="exactCenter"> <div id="login-container"> <img src="../tool/images/bigLogo.png" /><br /> <form action="login.php" method="post" class="form"> <fieldset class="group"> <input class="input" type="text" id="username" name="username" size="25" placeholder="username"/> <img src="../tool/images/spacer.png" width="5" height="5" /> <input class="input" type="password" id="password" name="password" size="25" placeholder="password"/> <img src="../tool/images/spacer.png" width="5" height="5" /> </fieldset> <input type="hidden" name="formsubmitted" value="TRUE" /> <button type="submit" name="submit" class="btn btn-blue" ><i class="fa fa-unlock-alt"></i> Login</button> <img src="../tool/images/spacer.png" width="5" height="5" /> <a href="Register.php"><button type="button" class="btn btn-green" ><i class="fa fa-hand-o-up"></i> Register</button></a> </form> </div></div> </body> </html> When i test it with admin login credentials i get the page refresh again without error, when i login with member credentials it shows tasks.php and when i try to log in with unactivated account "acivation column is not NULL" i get a page refresh also with no error. Can someone help me make it work for each role and perhaps have some sort of error reporting depending on error. im pulling my hair out here and this is the first time i have worked with login conditions, and im VERY confused.
  14. I have collected some data from .xml api's and I need to manipulate it in a way to display something specific. not my strongest point when it comes to maths & date data. so ultimately I need it to echo something like the following: "3 Days 4 Hours Remaining" or "14 Hours Remaining" (if below 24 hours!!!) I use the following to pull my variables and to test by echo results. <?php // Calculate total Fuel blocks $itemID = $record['itemID']; $result = mysql_query("SELECT * FROM `ecmt_poslistdetails` WHERE itemID = '$itemID' AND (typeID='4051' OR typeID='4247' OR typeID='4246' OR typeID='4312')"); $row = mysql_fetch_array($result); $fuelQty = $row[quantity]; echo $fuelQty; ?> <br /> <?php // Calculate total Fuel blocks used per hour $typeID = $record['typeID']; $result = mysql_query("SELECT * FROM `ecmt_posfuel` WHERE typeID = $typeID"); $row = mysql_fetch_array($result); $fuelUse = $row['fuel']; echo $fuelUse; ?> this gives me: $fuelQty & $fuelUse so for instance if fuel quantity is: 18480 and $fuelUse is: 40 the fuel used is 40x per hour and time remaining would be 462x Hours remaining but I want it to display: 19 Days 6 Hours Remaining how can I achieve this format?
  15. forgot to add; on the 2nd .xml file I only need the data from the "fuel" rowset so typeID and quantity. so second table in database would have 3 columns "itemID (from first .xml!), typeID (from 2nd .xml) and quantity (from 2nd .xml)"
  16. At the moment I collect data from an .XML file and it gets inserted into a database and it works great however the way in which the .xml files work has changed and I need to update my script to accommodate, before everything was processed by 1x .xml file and i collected data, now its done via 2x .xml files. So here is my current script; <?php // INCLUDE DB CONNECTION FILE include("includes/connect.php"); // CHANGE THE VALUES HERE include("includes/config.php"); // URL FOR XML DATA $url = "https://api.eveonline.com/corp/StarbaseList.xml.aspx?keyID=".$keyID."&vCode=".$vCode.""; // RUN XML DATA READY FOR INSERT $xml = simplexml_load_file($url); // Loop Through Names $insertValues = array(); $modifiedTS = date('Y-m-d h:i:s'); foreach ($xml->result->rowset[0] as $value) { //Prepare the values $itemID = $value['itemID']; $typeID = mysql_real_escape_string($value['typeID']); $locationID = $value['locationID']; $moonID = $value['moonID']; $state = mysql_real_escape_string($value['state']); $stateTimestamp = mysql_real_escape_string($value['stateTimestamp']); $onlineTimestamp = $value['onlineTimestamp']; $standingOwnerID = $value['standingOwnerID']; //Create and run ONE INSERT statement (with UPDATE clause) $insert = "INSERT INTO `ecmt_poslist` (itemID,typeID,locationID,moonID,state,stateTimestamp,onlineTimestamp,standingOwnerID,last_modified) VALUES('$itemID','$typeID','$locationID','$moonID','$state','$stateTimestamp','$onlineTimestamp','$standingOwnerID','$modifiedTS') ON DUPLICATE KEY UPDATE state='$state', stateTimestamp='$stateTimestamp', onlineTimestamp='$onlineTimestamp', last_modified = '$modifiedTS'"; mysql_query($insert) or die(mysql_error()); //ERROR CHECKING OPTION ONLY! //echo $insert; //echo "<br><br>"; }; //UPDATE last time this script ran and insert timestamp into Database $timeNow = date('Y-m-d H:i:s', strtotime('-1 hour')); $insertTime = "UPDATE `ecmt_API` SET time=1, time='$timeNow'"; mysql_query($insertTime) or die(mysql_error()); //Run query to delete records that were not just inserted/updated $delete = "DELETE FROM `ecmt_poslist` WHERE last_modified < '$modifiedTS'"; mysql_query($delete) or die(mysql_error()); ?> and here is the wiki page about the .xml file and its data; http://wiki.eve-id.net/APIv2_Corp_StarbaseList_XML i now need it to collect more data from a 2nd .xml file but the url will include the $itemID of the items pulled by the above script; http://wiki.eve-id.net/APIv2_Corp_StarbaseDetail_XML now i guess i need to put the code in the above foreach loop so I can say for each $itemID gather data from the second .xml file and input into a seperate table in my database named: `ecmt_poslistdetails` but i have no idea where to start as the rowset and layout of the 2nd .xml file is different, can anyone help me.. i'm not even sure if I wrote out this post to make sense from someone looking in from outside or not. its hard to explain. but hopefully the links provided will help. Ultimately I hope to have 2 tables in my database ecmt_poslist and ecmt_poslistdetails both containing the data from the above 2x .xml files.
  17. i'm using a dropdown menu to add data to URL in order to run a separate query command depending on result. url comes in as: index.php?role=ceo i have the following form: <form action="<?php $_SERVER['PHP_SELF'] ?>" method="GET" > <select name="role"> <option value="all">ALL</option> <option value="ceo">CEO</option> <option value="coceo">Co-Ceo</option> <option value="director">Director</option> <option value="pos">POS Manager</option> <option value="member">Member</option> </select> <input type="submit" value="Filter Results" /> </form> and the following set of if commands; <?php //Check if it echo role (IT DOES!!) echo $role; // Perform the SQL query //if role is set then add WHERE clause to filter to specific role if (isset($_GET['role'])) { $results = mysql_query('SELECT * FROM `ecmt_memberlist` WHERE role = '. $_GET['role'].' ORDER BY CONCAT(MainToon, Name)'); } //if no role set in url return ALL results! else { $results = mysql_query('SELECT * FROM `ecmt_memberlist` ORDER BY CONCAT(MainToon, Name)'); } $results_array = array(); while ($row = mysql_fetch_array($results)) { $results_array[$row['characterID']] = $row; } ?> i get this error when trying to run the submit button: line 82: while ($row = mysql_fetch_array($results)) { why is it running the error? and not showing results? if i don't submit the form all the data is shown as it should be correctly.
  18. thanks cyber looks like its what i need to do.
  19. went through some old code and pulled this out. <?php echo '<table border="0" cellspacing="0" cellpadding="4">'; $i = 0; $close = 0; $req = "select * from tanks WHERE member_id=$_SESSION[SESS_MEMBER_ID] order by id DESC"; $query = mysql_query($req); while($row = mysql_fetch_array($query)) { if($i%50 == 0) { echo '<tr>'; $close += 5; } $crypto = new phpFreaksCrypto(); $id_to_be_encrypted = $row['id']; $id_encrypted = $crypto->encrypt($id_to_be_encrypted); $id_decrypted = $crypto->decrypt($id_encrypted); $dateNew = date('jS F, Y', strtotime($row['date'])); $encoded = urlencode($id_encrypted); echo '<td>'.$row['description'].'</td>'; if($i == $close) echo '</tr>'; $i++; } echo '</table>'; ?> can I work with this to limit the number of columns to 2x per row?
  20. I have the following page: <table width="80%" border="0" align="center" cellpadding="2" cellspacing="2"> <tr> <td width="40%" valign="top"> <div align="right"><a href="settings.php"><img src="img/buttons/main_settings.png" alt="" border="0" /></a><img src="img/spacer.png" alt="" width="10" height="1" /><a href="addtank.php"><img src="img/buttons/add_tank.png" alt="" border="0" /></a><img src="img/spacer.png" alt="" width="10" height="1" /></div> <div class="content-box column-left"> <div class="content-box-header"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="80%"><h3>My Tanks</h3></td> </tr> </table> </div> <div class="content-box-content"> <div> <table width="100%" border="0" cellspacing="0" cellpadding="4"> <tr> <?php // Query to pull information from the "tanks" Database $result = mysql_query("select * from tanks WHERE member_id=$_SESSION[SESS_MEMBER_ID] order by id DESC"); while ($row = mysql_fetch_object($result)) { $crypto = new phpFreaksCrypto(); $id_to_be_encrypted = $row->id; $id_encrypted = $crypto->encrypt($id_to_be_encrypted); $id_decrypted = $crypto->decrypt($id_encrypted); $dateNew = date('jS F, Y', strtotime($row->date)); $encoded = urlencode($id_encrypted) ?><td width="50%" colspan="2" valign="top"> <table border="0" cellspacing="6" cellpadding="4"> <tr> <td colspan="2"><h3><?php echo $row->description; ?></h3></td> </tr> <tr> <td width="390"><table width="100%" class="tblImage"> <tr> <td colspan="3"><img src="img/image.jpeg" alt="" border="0" /></td> </tr> <tr> <td><i class="fa fa-comment"></i>14 <i class="fa fa-heart"></i>20</td> <td>Details Go Below the image!</td> <td> </td> </tr> </table></td> <td valign="top"><table border="0" cellspacing="4" cellpadding="4" style="background:#f7f7f7; color:#444444;"> <tr> <td>Make: </td> <td><?php echo $row->make; ?></td> </tr> <tr> <td>Model: </td> <td><?php echo $row->model; ?></td> </tr> <tr> <td>Type: </td> <td><?php echo $row->type; ?></td> </tr> <tr> <td>Description:</td> <td><?php echo $row->details; ?></td> </tr> <tr> <td>Official Volume:</td> <td><?php echo $row->officialVolume; ?> litres</td> </tr> <tr> <td>Actual Volume: </td> <td><?php echo $row->actualVolume; ?> litres</td> </tr> <tr> <td>Dimensions:</td> <td><?php echo $row->d1; ?>" x <?php echo $row->d2; ?>" x <?php echo $row->d3; ?>"</td> </tr> </table><br /> <br /><?php if($row->member_id == $_SESSION['SESS_MEMBER_ID']) { ?> <a class="btn btn-default btn-sm" href="edittank.php?ID=<?php echo $encoded ?>"><i class="fa fa-pencil"></i> Edit</a> <a class="btn btn-default btn-sm" href="remove-confirm-tank.php?ID=<?php echo $encoded ?>&db=tanks&tank=<?php echo $row->description ?>"><i class="fa fa-times"></i> Delete</a> <a class="btn btn-default btn-sm" href="#"><i class="fa fa-gavel"></i> Retire</a> <?php } else { echo ""; } ?> </td> </tr> </table> <br /></td><?php } mysql_free_result($result); ?> </tr> <tr> <td></td> </tr> </table> </div> </div> <!-- End .content-box-content --> </div> </td> </tr> </table> when I echo results it loops through the data and echo the code accordingly but if user has 3 or more entries in the database the data is just echo'd in the same row and goes out of the browser view port, can I get these results and limit it to just echo them to a maximum of 2 per row then start a new row and repeat?
  21. this is my current code; $test1 = mysql_real_escape_string($_POST['test1'] === '') ? NULL : $_POST['test1']; $test2 = mysql_real_escape_string($_POST['test2'] === '') ? NULL : $_POST['test2']; $test3 = mysql_real_escape_string($_POST['test3'] === '') ? NULL : $_POST['test3']; $test4 = mysql_real_escape_string($_POST['test4'] === '') ? NULL : $_POST['test4']; $test5 = mysql_real_escape_string($_POST['test5'] === '') ? NULL : $_POST['test5']; $test6 = mysql_real_escape_string($_POST['test6'] === '') ? NULL : $_POST['test6']; $test7 = mysql_real_escape_string($_POST['test7'] === '') ? NULL : $_POST['test7']; $test8 = mysql_real_escape_string($_POST['test8'] === '') ? NULL : $_POST['test8']; $test9 = mysql_real_escape_string($_POST['test9'] === '') ? NULL : $_POST['test9']; $test10 = mysql_real_escape_string($_POST['test10'] === '') ? NULL : $_POST['test10']; $test11 = mysql_real_escape_string($_POST['test11'] === '') ? NULL : $_POST['test11']; $test12 = mysql_real_escape_string($_POST['test12'] === '') ? NULL : $_POST['test12']; $test13 = mysql_real_escape_string($_POST['test13'] === '') ? NULL : $_POST['test13']; $test14 = mysql_real_escape_string($_POST['test14'] === '') ? NULL : $_POST['test14']; $time = $_POST['time']; $date = $_POST['date']; $month = $_POST['month']; $day = $_POST['day']; $active1 = mysql_real_escape_string($_POST['active1']); $active2 = mysql_real_escape_string($_POST['active2']); $active3 = mysql_real_escape_string($_POST['active3']); $active4 = mysql_real_escape_string($_POST['active4']); $active5 = mysql_real_escape_string($_POST['active5']); $active6 = mysql_real_escape_string($_POST['active6']); $active7 = mysql_real_escape_string($_POST['active7']); $active8 = mysql_real_escape_string($_POST['active8']); $active9 = mysql_real_escape_string($_POST['active9']); $active10 = mysql_real_escape_string($_POST['active10']); $active11 = mysql_real_escape_string($_POST['active11']); $active12 = mysql_real_escape_string($_POST['active12']); $active13 = mysql_real_escape_string($_POST['active13']); $active14 = mysql_real_escape_string($_POST['active14']); $tank = mysql_real_escape_string($_POST['tank']); $insert = "INSERT INTO tests (member_id, test1, test2, test3, test4, test5, test6, test7, test8, test9, test10, test11, test12, test13, test14, time, date, month, day, active1, active2, active3, active4, active5, active6, active7, active8, active9, active10, active11, active12, active13, active14, tank_id) VALUES ($_SESSION[SESS_MEMBER_ID], '$test1', '$test2', '$test3', '$test4', '$test5', '$test6', '$test7', '$test8', '$test9', '$test10', '$test11', '$test12', '$test13', '$test14', '$time', '$date', '$month', '$day', '$active1', '$active2', '$active3', '$active4', '$active5', '$active6', '$active7', '$active8', '$active9', '$active10', '$active11', '$active12', '$active13', '$active14', '$tank') "; i can only assume its passing 'NULL' instead of just NULL, how can i get it to remove the '' around the null value?
  22. ok i managed to get it to INSERT the data, forgot to wrap my VALUES with '' around them. Next question is the data im inserting into the database is numbers with possible decimals. is there a way I can enter NULL ONLY if text field is left empty? default is null in table setup.
  23. I have the following code: <?php session_start(); include('Includes/auth.php'); require_once('header.php'); ?> <table width="80%" border="0" align="center" cellpadding="2" cellspacing="2"> <tr> <td width="40%" valign="top"> <div class="content-box column-left"> <div class="content-box-header"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="80%"><h3>Add New Test Results</h3></td> <td width="20%"></td> </tr> </table> </div> <div class="content-box-content"> <div class="block"> <form enctype="multipart/form-data" action="<? $_SERVER['PHP_SELF']; ?>" method="post"> <?php { $fetch=mysql_query("SELECT * FROM members WHERE member_id=$_SESSION[SESS_MEMBER_ID]"); $fetchrow = mysql_fetch_array($fetch); $arr = array(); $arr = explode(';',$fetchrow['settings']); $member_id = $fetchrow['member_id']; if (isset($_POST['submit'])) { $date2 = date("y-m-d"); // DATE OF TANK ADDITION $time2 = date("H:i:s", time() - 3600); // TIME OF TANK ADDITION $test1 = $_POST['test1']; $test2 = $_POST['test2']; $test3 = $_POST['test3']; $test4 = $_POST['test4']; $test5 = $_POST['test5']; $test6 = $_POST['test6']; $test7 = $_POST['test7']; $test8 = $_POST['test8']; $test9 = $_POST['test9']; $test10 = $_POST['test10']; $test11 = $_POST['test11']; $test12 = $_POST['test12']; $test13 = $_POST['test13']; $test14 = $_POST['test14']; $time = $_POST['time']; $date = $_POST['date']; $month = $_POST['month']; $day = $_POST['day']; $active1 = $_POST['active1']; $active2 = $_POST['active2']; $active3 = $_POST['active3']; $active4 = $_POST['active4']; $active5 = $_POST['active5']; $active6 = $_POST['active6']; $active7 = $_POST['active7']; $active8 = $_POST['active8']; $active9 = $_POST['active9']; $active10 = $_POST['active10']; $active11 = $_POST['active11']; $active12 = $_POST['active12']; $active13 = $_POST['active13']; $active14 = $_POST['active14']; $tank = $_POST['tank']; $insert = "INSERT INTO tests (member_id, test1, test2, test3, test4, test5, test6, test7, test8, test9, test10, test11, test12, test13, test14, time, date, month, day, active1, active2, active3, active4, active5, active6, active7, active8, active9, active10, active11, active12, active13, active14, tank) VALUES ($_SESSION[SESS_MEMBER_ID], $test1, $test2, $test3, $test4, $test5, $test6, $test7, $test8, $test9, $test10, $test11, $test12, $test13, $test14, '$time', '$date', '$month', '$day', $active1, $active2, $active3, $active4, $active5, $active6, $active7, $active8, $active9, $active10, $active11, $active12, $active13, $active14, '$tank') "; $insert2 = "INSERT INTO `logs` SET typeid='1', memberid='$_SESSION[SESS_MEMBER_ID]', info='New Test Added', tankname='-', time='$time2', date='$date2'"; if (@mysql_query($insert)) if (@mysql_query($insert2)) { ?> <script type="text/javascript"> document.location.replace('results.php'); </script> <?php } else { echo('Error in you submission:' . mysql_error() . "<br />" . $sql); }} ?> *Un-Tick the checkbox for values you dont want saving. <table width="100%" border="0" cellspacing="2" cellpadding="2"> <tr> <td> <div class="block"> <input type="hidden" name="time" value="<? //get current timestamp and subtract one <strong class="highlight">hour</strong> $dat = time() - 3600; //output time echo date("g:ia", $dat);?>" /> <br /> <table width="100%" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <td colspan="2" width="50%"> <table width="100%" border="0" align="center" cellspacing="0" cellpadding="2"> <tr> <td colspan="2" align="center"><div align="left" class="style1"></div></td> </tr> <tr> <td width="42%" align="center"><table border="0" cellspacing="0" cellpadding="2"> <tr><td><label>Select Tank:</label><br /> <select class="text2" name="tank"> <option value="All" selected="selected"> Select Tank </option> <? // Query to pull information from the "catagory" Database $result = mysql_query("select * from tanks WHERE member_id = '$_SESSION[SESS_MEMBER_ID]' order by id ASC"); while ($row = mysql_fetch_object($result)){ ?> <option value="<?php echo $row->id; ?>"> <?php echo $row->description; ?> </option> <? }?> </select></td></tr> </table> </td> <td valign="top" align="center" width="50%"> <?php $todaydate = date("Y-m-d"); $oldDate = date("Y-m-d", strtotime("6 months ago")); ?> <table border="0" cellspacing="0" cellpadding="2"> <tr><td><label>Select Date:</label><br /> <input name="date" type="text" class="date" id="datepicker" value="<?php echo $todaydate; ?>" /></td></tr> </table> </td> </tr> </table></td> </tr><tr> <div class="block"> <td valign="top" align="center" width="50%"> <table border="0" cellspacing="0" cellpadding="2"> <?php echo (in_array("test1",$arr) ? "<tr><td><Label>Salinity:</label><br><input type='checkbox' name='active1' value='1' checked='checked' /> <input class='text' name='test1' type='text' value='' /> ppt </td></tr>" : ''); ?> <?php echo (in_array("test2",$arr) ? "<tr><td><label>PH:</label><br><input type='checkbox' name='active2' value='1' checked='checked' /> <input class='text' type='text' name='test2' value='' /> ppm </td></tr>" : ''); ?> <?php echo (in_array("test3",$arr) ? "<tr><td><label>Ammonia:</label><br><input type='checkbox' name='active3' value='1' checked='checked' /> <input class='text' type='text' name='test3' value='' /> ppm </td></tr>" : ''); ?> <?php echo (in_array("test4",$arr) ? "<tr><td><label>Nitrite:</label><br><input type='checkbox' name='active4' value='1' checked='checked' /> <input class='text' type='text' name='test4' value='' /> ppm </td></tr>" : ''); ?> <?php echo (in_array("test5",$arr) ? "<tr><td><label>Nitrate:</label><br><input type='checkbox' name='active5' value='1' checked='checked' /> <input class='text' type='text' name='test5' value='' /> ppm </td></tr>" : ''); ?> <?php echo (in_array("test6",$arr) ? "<tr><td><label>Calcium:</label><br><input type='checkbox' name='active6' value='1' checked='checked' /> <input class='text' type='text' name='test6' value='' /> ppm </td></tr>" : ''); ?> <?php echo (in_array("test7",$arr) ? "<tr><td><label>Magnesium:</label><br><input type='checkbox' name='active7' value='1' checked='checked' /> <input class='text' type='text' name='test7' value='' /> ppm </td></tr>" : ''); ?> </table></td> <td valign="top" align="center" width="50%"> <table border="0" cellspacing="0" cellpadding="2"> <?php echo (in_array("test8",$arr) ? "<tr><td><label>Alkalinity:</label><br><input type='checkbox' name='active8' value='1' checked='checked' /> <input class='text' type='text' name='test8' value='' /> dKH </td></tr>" : ''); ?> <?php echo (in_array("test9",$arr) ? "<tr><td><label>Phosphate:</label><br><input type='checkbox' name='active9' value='1' checked='checked' /> <input class='text' type='text' name='test9' value='' /> ppm </td></tr>" : ''); ?> <?php echo (in_array("test10",$arr) ? "<tr><td><label>potassium:</label><br><input type='checkbox' name='active10' value='1' checked='checked' /> <input class='text' type='text' name='test10' value='' /> ppm </td></tr>" : ''); ?> <?php echo (in_array("test11",$arr) ? "<tr><td><label>Iodine:</label><br><input type='checkbox' name='active11' value='1' checked='checked' /> <input class='text' type='text' name='test11' value='' /> ppm </td></tr>" : ''); ?> <?php echo (in_array("test12",$arr) ? "<tr><td><label>Strontium:</label><br><input type='checkbox' name='active12' value='1' checked='checked' /> <input class='text' type='text' name='test12' value='' /> ppm </td></tr>" : ''); ?> <?php echo (in_array("test13",$arr) ? "<tr><td><label>Silica:</label><br><input type='checkbox' name='active13' value='1' checked='checked' /> <input class='text' type='text' name='test13' value='' /> ppm </td></tr>" : ''); ?> <?php echo (in_array("test14",$arr) ? "<tr><td><label>Temperature:</label><br><input type='checkbox' name='active14' value='1' checked='checked' /> <input class='text' type='text' name='test14' value='' /> 'c </td></tr>" : ''); ?> </table> </td> </div> </tr> </table> <div align="right"><br /> <table border="0" cellspacing="0" cellpadding="8"> <tr> <td><input class="btn btn-success btn-rad" type="submit" name="submit" value="Submit" /></td> <td><input class="btn btn-danger btn-rad" type="reset" name="reset" value="Reset" /></td> </tr> </table> </div></div> </td> </tr> </table> </form></div> <?php } ?> </div> </div> <!-- End .content-box-content --> </div> </td> </tr> </table> <?php require_once('footer.php'); ?> For some reason the code doesn't update the 'test' table and people keep telling me to change it to prepared statements for protection against injection. can anyone help me with both please.
  24. I have a page that allows a user to enable / disable multiple options (14x) for some reason the code is running but the database isn't updating and the data isn't being passed. but i don't get the mysql errors, can someone look over my code please and let me know where / what is wrong? code: <?php session_start(); include('Includes/auth.php'); require_once('header.php'); ?> <table width="80%" border="0" align="center" cellpadding="2" cellspacing="2"> <tr> <td width="40%" valign="top"> <div align="right"><a href="settings.php"><img src="img/buttons/main_settings.png" alt="" border="0" /></a><img src="img/spacer.png" alt="" width="10" height="1" /></div> <div class="content-box"> <div class="content-box-header"> <h3>My Test Settings</h3> </div> <div class="content-box-content"> <div> <table width="100%" border="0" cellspacing="0" cellpadding="4"> <tr> <td colspan="7" valign="top"> <form enctype="multipart/form-data" action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> <?php if (isset($submit)) { // UPDATE QUERY CODE WHEN SUBMIT IS ENTERED $str = implode(';',$_POST['checks']); $insert = "UPDATE 'members' SET settings='$str' WHERE member_id='$_SESSION[SESS_MEMBER_ID]'"; if (@mysql_query($insert)) { ?> <script type="text/javascript"> document.location.replace('settings-tests.php'); </script> <?php } else { echo('Error in you submission:' . mysql_error() . "<br /><br />" . $sql);} } { $result=mysql_query("SELECT * FROM members WHERE member_id=$_SESSION[SESS_MEMBER_ID]"); $row = mysql_fetch_array($result); $arr = array(); $arr = explode(';',$row['settings']); $member_id = $row['member_id']; $firstname = $row['firstname']; $lastname = $row['lastname']; $email = $row['email']; $membership = $row['membership']; $roles = $row['roles']; $login = $row['login']; ?> <table width="100%" border="0" cellspacing="0" cellpadding="4"> <tr> <td colspan="2"><h3>Test Results Settings</h3></td> <td width="25%"> </td> <td width="25%"> </td> </tr> <tr> <td colspan="4"><em>To turn off individual results gloablly across the site please use the following sliders (all results already added will also be made invisable)<br /> <br /> </em></td> </tr> <tr> <td width="25%"><div align='right'><strong><em>Salinity:</em></strong></div></td> <td width="25%"><input type="checkbox" value="test1" name="checks[]2" <?php echo (in_array("test1",$arr) ? "checked" : ''); ?>/></td> <td><div align='right'><strong><em>Phosphate:</em></strong></div></td> <td><input type="checkbox" value="test9" name="checks[]10" <?php echo (in_array("test9",$arr) ? "checked" : ''); ?>/></td> </tr> <tr> <td><div align='right'><strong><em>PH:</em></strong></div></td> <td><input type="checkbox" value="test2" name="checks[]3" <?php echo (in_array("test2",$arr) ? "checked" : ''); ?>/></td> <td><div align='right'><strong><em>potassium:</em></strong></div></td> <td><input type="checkbox" value="test10" name="checks[]11" <?php echo (in_array("test10",$arr) ? "checked" : ''); ?>/></td> </tr> <tr> <td><div align='right'><strong><em>Ammonia:</em></strong></div></td> <td><input type="checkbox" value="test3" name="checks[]4" <?php echo (in_array("test3",$arr) ? "checked" : ''); ?>/></td> <td><div align='right'><strong><em>Iodine:</em></strong></div></td> <td><input type="checkbox" value="test11" name="checks[]12" <?php echo (in_array("test11",$arr) ? "checked" : ''); ?>/></td> </tr> <tr> <td><div align='right'><strong><em>Nitrite:</em></strong></div></td> <td><input type="checkbox" value="test4" name="checks[]5" <?php echo (in_array("test4",$arr) ? "checked" : ''); ?>/></td> <td><div align='right'><strong><em>Strontium:</em></strong></div></td> <td><input type="checkbox" value="test12" name="checks[]13" <?php echo (in_array("test12",$arr) ? "checked" : ''); ?>/></td> </tr> <tr> <td><div align='right'><strong><em>Nitrate:</em></strong></div></td> <td><input type="checkbox" value="test5" name="checks[]6" <?php echo (in_array("test5",$arr) ? "checked" : ''); ?>/></td> <td><div align='right'><strong><em>Silica:</em></strong></div></td> <td><input type="checkbox" value="test13" name="checks[]14" <?php echo (in_array("test13",$arr) ? "checked" : ''); ?>/></td> </tr> <tr> <td><div align='right'><strong><em>Calcium:</em></strong></div></td> <td><input type="checkbox" value="test6" name="checks[]7" <?php echo (in_array("test6",$arr) ? "checked" : ''); ?>/></td> <td><div align='right'><strong><em>Temperature:</em></strong></div></td> <td><input type="checkbox" value="test14" name="checks[]" <?php echo (in_array("test14",$arr) ? "checked" : ''); ?>/></td> </tr> <tr> <td><div align='right'><strong><em>Magnesium:</em></strong></div></td> <td><input type="checkbox" value="test7" name="checks[]8" <?php echo (in_array("test7",$arr) ? "checked" : ''); ?>/></td> <td></td> <td></td> </tr> <tr> <td><div align='right'><strong><em>Alkalinity:</em></strong></div></td> <td><input type="checkbox" value="test8" name="checks[]9" <?php echo (in_array("test8",$arr) ? "checked" : ''); ?>/></td> <td colspan="2" align="right"></td> </tr> <tr> <td colspan="4" align="right"><table border="0" cellspacing="0" cellpadding="8"> <tr> <td><input class="btn btn-success btn-rad" type="submit" name="submit" value="Submit" /></td> <td><input class="btn btn-danger btn-rad" type="reset" name="reset" value="Reset" /></td> </tr> </table></td> </tr> </table> </form> </td> </tr> </table> </p> </div> </div> <!-- End .content-box-content --> </div> </td> </tr> </table> <?php } require_once('footer.php'); ?> </body> the array explodes, and it shows me "checked" boxes where the data is in the database, just not updating the database table.. thank you.
×
×
  • 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.