Jump to content

cjkeane

Members
  • Posts

    63
  • Joined

  • Last visited

Everything posted by cjkeane

  1. Thanks for all the responses. I am close. I want to retain the check marks before the form is submitted. I have this so far. It retains the check marks, but it selects all check boxes right away. <p>Select the categories:<br /> <?php if (isset($_POST['categories'])) {$checked = 'checked'; } else { $checked = '';} while ($category = mysqli_fetch_array($categories)) { $categoryid = $category['id']; $categoryname = htmlspecialchars($category['category']); echo '<input type="checkbox" checked="'.$checked.'" name="categories[]" value="'.$categoryid.'" > '.$categoryname.' <br/>'; } ?> </p>
  2. Here is the full script. The error reporting didn't help. <?php error_reporting(E_ALL); ini_set('display_errors', '1'); ob_start(); require_once('db.php'); require_once('auth.php'); require_once('functions.php'); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <title>Bookings</title> <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <link rel="stylesheet" href="https:///resources/demos/style.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <script> // This is a jquery datepicker function. The dateFormat specifies that the date selected from the calendar will be in the yyyy-mm-dd format. $( function() { $('#date').datepicker({dateFormat: 'yy-mm-dd'}); } ); </script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <link href="assets/css/styles.css" rel="stylesheet" > </head> <body> <div class="container"> <div id="header"> <figure><img src="logo.png"></figure> <?php $logged_on_name = "<span class='red-highlight'>" . ($_SESSION["SESS_NAME"]) . " </span>"; $usergroup = "<span class='red-highlight'>" . ($_SESSION["SESS_USERGROUP"]) . " </span>"; echo "<p>Welcome " . $logged_on_name . "</p>"; ?> </div> <div style="clear:both"></div> <ul> <li><a href="admin_index.php">HOME</a></li> <li><a href="admin_customers.php">CUSTOMERS</a></li> <li><a class="active" href="admin_bookings.php">BOOKINGS</a></li> <li><a href="admin_categories.php">CATEGORIES</a></li> <li style="float:right"><a href="logout.php">LOGOUT</a></li> <li style="float:right"><a href="admin_users.php">USERS</a></li> </ul> <div id="main" class="row"> <?php // If the Add New User button is clicked, redirect to the admin_add_user.php page. if(isset($_POST['AddNew'])){ $page ="admin_add_user.php"; header("Refresh: 0; url=$page"); } ?> <h2>Bookings:</h2> <?php $customerid = $_POST['customerid']; $description = $_POST['description']; $categories= $_POST['categories']; $date= $_POST['date']; if(isset($_POST['Save']) && !empty($_POST['Save'])) { // Begin form validation $error = false; if (empty($customerid)) { $error = true; $customeridError = "Please select a customer name."; } if (empty($description)) { $error = true; $descriptionError = "Please type a booking description."; } if (empty($date)) { $error = true; $dateError = "Please select a date."; } // end form validation and if there are no errors, insert new record with a hashed password if (!$error) { $sql = "INSERT INTO booking SET description='$description', date='$date', customerid='$customerid'"; if (mysqli_query($db,$sql)) { echo '<p>New booking added</p>'; } else { exit('<p>Error adding new booking</p>'); } $bookingid = mysqli_insert_id($db); if (isset($_POST['categories'])) { $categories = $_POST['categories']; } else { $categories = array(); } $numcategories = 0; foreach ($categories as $catID) { $sql = "INSERT IGNORE INTO bookingcategory SET bookingid=$bookingid, categoryid=$catID"; $ok = mysqli_query($db,$sql); if ($ok) { $numcategories = $numcategories + 1; } else { echo "<p>Error inserting booking into category $catID: " . '</p>'; } } echo "<p>Booking was added to " . $numcategories . " categories.</p>"; } else { echo '<div style="color: red; text-align: center;" >Save Failed. <i class="fa fa-thumbs-o-down" aria-hidden="true"></i> There are validation errors. Try again. </div>'; } } ?> <?php $customer = mysqli_query($db,'SELECT id, name FROM customer'); if (!$customer) { exit('<p>Unable to obtain customer list from the database.</p>'); } $categories = mysqli_query($db,'SELECT id, category FROM category'); if (!$categories) { exit('<p>Unable to obtain category list from the database.</p>'); } ?> <form method="post" action=""> <input type="submit" class="btn" name="Save" type="submit" id="Save" value="Save"> <p>Enter the new booking:<br /> <textarea name="description" rows="5" cols="45" placeholder="Enter a booking description"><?php echo $description; ?></textarea></p> <span class="text-danger" style="color:red; font-size:14px;"><?php echo $descriptionError; ?></span> <p>Date<input type="text" id="date" name="date" value="<?php echo $date; ?>"></p> <span class="text-danger" style="color:red; font-size:14px;"><?php echo $dateError; ?></span> <p>Select customer name:</p> <?php // Create a query to retrieve the category list. $result = mysqli_query($db,'SELECT id, name FROM customer'); $options = ''; while ($row = mysqli_fetch_array($result)) { // $selected makes sure that the selected value is retreived and set as selected. $selected = ($row['id']==$customerid) ? ' selected="selected"' : ''; $options .= "<option value=\"{$row['id']}\"{$selected}>{$row['name']}</option>\n"; } ?> <select name="customerid" id="customerid" > <option value="" selected disabled hidden>Select one <?php echo $options ?></option> </select> <span class="text-danger" style="color:red; font-size:14px;"><?php echo $customeridError; ?></span> <p>Place in categories:<br /> <?php while ($category = mysqli_fetch_array($categories)) { $categoryid = $category['id']; $categoryname = htmlspecialchars($category['category']); $checked= ($category['id']==$categories) ? ' checked="checked"' : ''; echo '<input type="checkbox" name="categories[]" value="'.$categoryid.'" '.$checked.' > '.$categoryname.' <br/>'; } ?> </p> <span class="text-danger" style="color:red; font-size:14px;"><?php echo $categoriesError; ?></span> </form> </div> <div id="copyright" class="row"> <p><?php copyright(); ?></p> </div> </div> </body> </html> <?php ob_end_flush(); ?>
  3. Hi everyone, I need to retain the checkbox selections after the form is submitted, but I'm stuck and wondering if anyone can offer some assistance? Thank you. <?php $categories = mysqli_query($db,'SELECT id, category FROM category'); if (!$categories) { exit('<p>Unable to obtain category list from the database.</p>'); } // Check if there are any categories and if so, list them. if (mysqli_num_rows($categories) != 0){ echo '<p>Select the related categories:<br />'; while ($category = mysqli_fetch_array($categories)) { $categoryid = $category['id']; $categoryname = htmlspecialchars($category['category']); $checked= ($category['id']==$categories) ? ' checked="checked"' : ''; echo '<input type="checkbox" name="categories[]" value="'.$categoryid.'" '.$checked.' > '.$categoryname.' <br/>'; } } ?>
  4. I can't do that. The data has already been imported by someone else and merged with live data. I cannot do another import using LOAD DATA INFILE, if that's what you are asking.
  5. the db collation is: utf8_unicode_ci on each php page I have the following: <?php mysql_query("SET NAMES 'utf-8'"); ?> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> As I said, any new data saved via php into the mysql db retains the accented characters. It's just retrieving data (for e.g. first_name) which was imported from a csv into the mysql db which isn't displaying the accented characters correctly.
  6. Hi everyone, I'm sure you all have come across this issue before, and I have read a lot of posts regarding it, but I have only been able to partially resolve my issue. I have a mysql database and I'm using php to retrieve the data. I imported data from a csv into mysql and all entries which have accented characters have been mangled and appear as: �. When text is entered with accented characters and saved using php into the mysql db, the characters retain the accented characters. I'm wondering if anyone would know how to write code to check if a string e.g. (first_name) is utf-8, if not then utf-8 decode it? I believe that would solve my issue. Or if anyone else has any suggestions which might help, I'd appreciate it. Also, sometimes I notice a � will appear between lines of text when it should have been a line break. If anyone could suggest a solution to those issues, I'd appreaciate it. Thanks.
  7. i resolved it by using: preg_replace('/(\d\d)\/(\d\d)\/(\d\d\d\d)/', '<br>$0', $row['History']) thanks for the tip!
  8. it's getting closer, but now it displays as: 01/08/2007 this is the first line of text 01/04/2007 this is the second line of text 01/04/2007 this is the third line of text
  9. I have tried your suggestion and it still comes out as: 01/08/2007 this is the first line of text 01/04/2007 this is the second line of text 01/04/2007 this is the third line of text
  10. Yes, that's exactly what the field contains. It was actually imported from another db into mysql in that fashion, so the entire field contains that entire string. I know it would have been better to have the date in a completely separate field, but there was nothing I could do about how the data was previosly imported. All I want to do is line up the data so that each date is underneath each other. I hope that makes sense.
  11. I'm sure there aren't any line breaks. If I display the data, it comes out word wrapped, like so: 01/08/2007 this is the first line of text 01/04/2007 this is the second line of text 01/04/2007 this is the third line of text I need to some how insert a CR before each date so it lines up.
  12. Hi everyone, i am retrieving data from mysql and displaying it in a table using the below coding. In the field string of $row['History'] there is a date followed by a description. This is how the data was inserted by the client previously. What I'd like to do is insert a CR just before the dd/mm/yyyy of each entry within the string. <?php $ID = $_GET['ID']; $result = mysql_query("SELECT ID, History FROM historytable WHERE ID='$ID'") or die(mysql_error()); echo "<table border='0' cellpadding='1'>"; echo "<tr>"; while($row = mysql_fetch_array( $result )) { echo "<tr>"; echo '<td>' . preg_replace('/\d\d\//', '<br>$0', $row['History']). '</td>'; echo "</tr>"; } echo "</table>"; ?> currently it's being displayed like so: 01/ 08/2007 this is the first line of text 01/ 04/2007 this is the second line of text 01/ 04/2007 this is the third line of text but i need it to be displayed like this. 01/08/2007 this is the first line of text 01/04/2007 this is the second line of text 01/04/2007 this is the third line of text Any assistance would be appreciated. Thanks.
  13. i see the problem. thanks for the hint. i got the date sorting properly now. i do have another issue though. when data for the sender is imported, it goes in the db as john smith <johns@home.ca> when the data is displayed on the page it just displays as john smith with no email address. the datatype for the sender is varchar(200) latin1_swedish_ci. do i need to use php to convert the 'sender' field to include htmlspecial chars? i'm not quite sure which php function to use to display the entire contents of 'sender'. any ideas?
  14. i duplicated the message by mistake instead of editing it.
  15. hi everyone. i have a database storing emails with the following fields: date, subject. sender, format, toaddress. the date field is a varchar datatype which takes dates in as 'dd mmm, time'. i'd like to convert that to dd-mmm using php when i display the data on a page. I'm not sure which function can convert varchar data to a date so any helpful hints you can provide would be appreciated. i'm using the following code to display the results of the query to the page: whether i sort date ASC or date DESC, the order of the date column doesn't sort properly <?php $string = "SELECT id, date, substr(subject,1,20) as subject, sender, format, toaddress FROM email ORDER BY date ASC"; $query = mysql_query($string) or die (mysql_error()); $num_rows = mysql_num_rows($query); if($num_rows>0) { $pages = new Paginator; $pages->items_total = $num_rows; $pages->paginate(); echo $pages->display_pages(); echo $pages->display_items_per_page(); echo '<hr>'; } else { echo "<div id='titles_smaller'>No data available.</div><br />"; } echo "<table class='sortable' width='100%' border='0' cellpadding='1'>"; echo "<tr> <th nowrap>Date</th> <th nowrap>Subject (partial)</th><th nowrap>Sender</th><th nowrap>Format</th><th nowrap>To Address</th></tr>"; $string = $string."$pages->limit"; $query = mysql_query($string) or die (mysql_error()); $result = mysql_fetch_array($query); if($result==true) { do { echo "<tr>"; echo '<td nowrap>' . $result['date'] . '</td>'; echo '<td nowrap>' . $result['subject'] . '</td>'; echo '<td nowrap>' . $result['sender'] . '</td>'; echo '<td nowrap>' . $result['format'] . '</td>'; echo '<td nowrap>' . $result['toaddress'] . '</td>'; echo "</tr>"; } while($result = mysql_fetch_array($query)); } // close table> echo "</table><hr>"; if($num_rows>0) { echo $pages->display_pages().$pages->display_items_per_page(); } // end pagination ?>
  16. hi everyone. i need to figure out how to display one tr or another based on if N/A appears in one of the TR's. if i use: 'if ($result['NoChargeFile'] = 'N/A')' it repeats N/A for all rows. if i use: 'if ($result['NoChargeFile'] = N/A)' only the TotalFees TR is displays. What i need to do is display the TOTALFEES if the NOCHARGEFILE is not N/A. If NOCHARGEFILE is N/A, display N/A instead of the TOTALFEES. Any ideas how to fix this issue? thanks. <?php echo "<table width='100%' border='0' cellpadding='1'>"; $string = $string."$pages->limit"; $query = mysql_query($string) or die (mysql_error()); $result = mysql_fetch_array($query); if($result==true) { do { echo "<tr>"; echo '<td nowrap>' . $result['CompanyName'] . '</td>'; echo '<td nowrap>' . $result['CompanyReferenceNumber'] . '</td>'; if ($result['NoChargeFile'] = 'N/A') { echo '<td nowrap>' . $result['NoChargeFile'] . '</td>'; } else { echo '<td nowrap>' . $result['TotalFees'] . '</td>'; } echo '<td nowrap>' . $result['DateRecorded'] . '</td>'; echo '<td nowrap>' . $result['DateClosed'] . '</td>'; echo "</tr>"; } while($result = mysql_fetch_array($query)); } // close table> echo "</table><hr>"; ?> I figured it out. i need == not =.
  17. already tried that, plus many different variations of javascript refreshes of the parent window. i just tried <?php session_start(); $_SESSION['ID'] = $_GET['ID']; $ID = session_id(); ?> in the main page and in the iframe <?php $ID = $_REQUEST['ID'] ; if(session_id() == "") { session_id($ID); session_start(); echo "<br> sessId: " . $ID . "<br>" ; } ?> The id is displayed in the iframe, but as soon as the iframe is updated through a submit button, then i lose the session ID. the only way to get the ID back is for the whole page to be refreshed, but then when files are deleted from inside the iframe, the data sometimes doesnt delete. which is why i wanted to try using sessions.
  18. I was attempting to use session variables because hopefully that way i wouldn't lose the ID number passed from the main page to the iframe. you see, in the iframe, there is a submit form with a list of files that can be deleted, and when the file is deleted, the link between the main page and the iframe is broken. i need a way to maintain the link between the main page and the iframe after the data is updated in the iframe. i hope that makes sense. ADDED NOT: The way it functions now, the page needs to be refreshed manually so that the iframe data is refreshed. i'd like not to have to keep refreshing the page manually.
  19. i'm pretty new to sessions. how do i grab the session in the iframe? i mean, do i need to start the session as well?
  20. ok. the id is echoed to the screen, but not passed to the iframe.
  21. sorry. i forgot to add the php tags. but yes thats what i had inside php tags. the id just isn't displayed so i'm wondering if the session code is correct.
  22. hi everyone. i'm wondering what the best way is to create a session variable and pass it to an iframe. i need to do something along these lines, but it doesn't seem to pass the ID. Any hints on how i should accomplish this? session_start(); $_SESSION['ID']=$_GET['ID']; // id from previous page $ID=session_id(); <iframe src="iframepage.php?ID=<?php echo $ID; ?>" style="width:680px; height:200px;" noresize="noresize" frameborder="0" border="0" scrolling="Yes" allowtransparency="true" /> </iframe>
  23. hi everyone. i have content in an iframe. when a delete link in a form, is clicked. i need the parent window to be refreshed. i currently have the code below. it seems to refresh the page but not the content. for example, if i manually refresh the page, the data will display, but an automatic refresh through javascript doesn't refresh the content in the iframe. i'd appreaciate the assistance. thanks. <!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>Untitled Document</title> <link href="styles.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> function refresh_parent(){ parent.location.reload(); } </script> </head> <body> <form method="post" enctype="multipart/form-data"> <table width="350" border="0" cellpadding="1" cellspacing="1" class="box"> <tr> <td width="246"> <input type="hidden" name="MAX_FILE_SIZE" value="20000000"> <input name="userfile" type="file" id="userfile"> </td> <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload " onclick="refresh_parent()"></td> </tr> </table> </form> <table> <tr> <th align="left" width="300px">Filename: </th> <th align="left" width="200px">Type: </th> <th align="left" width="60px">Size: </th> </tr> <?php if (mysql_num_rows($filelist) > 0) { while ($f = mysql_fetch_array($filelist)) { //GET FILE SIZE $fileSize = $f['size']; if ($fileSize>999999){ //IF GREATER THAN 999KB, DISPLAY AS MB $theDiv = $fileSize / 1000000; $fileSize = round($theDiv, 1)." MB"; //round($WhatToRound, $DecimalPlaces) } else { //OTHERWISE DISPLAY AS KB $theDiv = $fileSize / 1000; $fileSize = round($theDiv, 1)." KB"; //round($WhatToRound, $DecimalPlaces) } ?> <tr valign="top"> <td width="300px"><?php echo $f['name']; ?> </td> <td width="200px"><?php echo $f['type']; ?> </td> <td width="60px"><?php echo $fileSize; ?> </td> <td> [<a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=view&id=<?php echo $f['id']; ?>">DNLD</a> | <a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=delete&id=<?php echo $f['id']; ?>" onclick="refresh_parent()">Delete</a>] </td> </tr> <?php } } else { ?> <tr><td colspan="3">No Files!</td></tr> <?php } ?> </table> </body> </html> </script>
  24. thanks everyone. i resolved the issue by putting: ob_start(); at the top of the page.
  25. hi everyone. i have been working on a site on a local windows server then moved everything to a unix server. now my refresh doesn't redirect anymore. any ideas why? <?php if(isset($_POST['GO'])){ $page ="go.php?IDNumber=" . $IDNumber; header("Refresh: 1; url=$page"); echo " "; } ?> <form action="" method="post" name="redirect" id="redirect"> <input type="submit" name="GO" id="GO" value="GO" /> </form>
×
×
  • 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.