Jump to content

cjkeane

Members
  • Posts

    63
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

cjkeane's Achievements

Member

Member (2/5)

0

Reputation

  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 ?>
×
×
  • 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.