-
Posts
254 -
Joined
-
Last visited
-
Days Won
1
Everything posted by Moorcam
-
Hi mate That is fine but the issue is, if an end user, such as a non-techy type person, was to create a booking from the backend, selecting an ID will make no sense to them. They will need to see the name of the job they are booking onto.
-
Hi guys, I am trying to get data from the table "jobs" and insert its id and name into table "bookings" I can get the job "name" from "jobs", which is fine, using the following: <select class="form-control" id="tour_name" name="tour_name"> <option value="Select">== Select Tour or Charter ==</option> <?php $sql = "SELECT name FROM jobs"; $result = $con->query($sql); while(list($name) = mysqli_fetch_row($result)){ ?> <option value="<?php echo $name ?>"><?php echo $name;?></option> <?php } ?> </select> However, when I click submit to insert into "bookings" everything goes in except "booking_id" which is "id" in "jobs". Hope this makes sense. I am using the following to insert: if(isset($_POST['new']) && $_POST['new']==1){ $sql = "SELECT id FROM jobs"; $result = $con->query($sql); while(list($id) = mysqli_fetch_row($result)){ } $tour_id = isset($_GET['id']) ? $_GET['id'] : ''; $tour_name = mysqli_real_escape_string($con, $_POST['tour_name']); $customer_name = mysqli_real_escape_string($con, $_POST['customer_name']); $customer_address = mysqli_real_escape_string($con, $_POST['customer_address']); $customer_email = mysqli_real_escape_string($con, $_POST['customer_email']); $customer_phone = mysqli_real_escape_string($con, $_POST['customer_phone']); $total_pax = mysqli_real_escape_string($con, $_POST['total_pax']); $status = mysqli_real_escape_string($con, $_POST['status']); $order_at = mysqli_real_escape_string($con, date("Y-m-d H:i:s")); $total_amount = mysqli_real_escape_string($con, $_POST['total_amount']); $query="insert into bookings (`tour_id`, `tour_name`, `customer_name`, `customer_address`, `customer_email`, `customer_phone`, `total_pax`, `status`, `order_at`, `total_amount`)values ('$tour_id', '$tour_name', '$customer_name', '$customer_address', '$customer_email', '$customer_phone', '$total_pax', '$status', '$order_at', '$total_amount')"; mysqli_query($con,$query) or die(mysqli_error($con)); if(mysqli_affected_rows($con)== 1 ){ $message = '<p class="text-success"><i class="fa fa-check"></i> - Record Inserted Successfully</p>'; } } Can anyone please lend a hand with this? 2 Days at it now and ready to hit the Guinness. Cheers, Dan
-
Hey kicken, Thanks for the reply. I did that and now get this: PHP Parse error: syntax error, unexpected 'if' (T_IF), expecting function (T_FUNCTION) or const (T_CONST) Thanks for your help.
-
Hi guys, I am trying to calculate hours a person works by calculating the values of text fields in a form. However, when I load the page I get "Class 'times_counter' not found. Here is the calculation code" if(isset($_POST['calculate']) != ""){ class times_counter { private $hou = 0; private $min = 0; private $sec = 0; private $totaltime = '00:00:00'; public function __construct($times){ if(is_array($times)){ $length = sizeof($times); for($x=0; $x <= $length; $x++){ $split = explode(":", @$times[$x]); $this->hou += @$split[0]; $this->min += @$split[1]; $this->sec += @$split[2]; } $seconds = $this->sec % 60; $minutes = $this->sec / 60; $minutes = (integer)$minutes; $minutes += $this->min; $hours = $minutes / 60; $minutes = $minutes % 60; $hours = (integer)$hours; $hours += $this->hou % 24; $this->totaltime = $hours.":".$minutes; } } public function get_total_time(){ return $this->totaltime; } } $times = array( $mondiff->format('%H:%I'), $tudiff->format('%H:%I'), $weddiff->format('%H:%I'), $thdiff->format('%H:%I'), $fridiff->format('%H:%I'), $satdiff->format('%H:%I'), $sundiff->format('%H:%I'), ); $counter = new times_counter($times); I had this on an old project, which I no longer have but it worked then. Any ideas?
-
Got is working <?php require_once "config.php"; $json = array(); $sqlQuery = "SELECT id, name AS title, dep_date AS start, ret_date AS end FROM jobs ORDER BY id"; $result = mysqli_query($con, $sqlQuery); $eventArray = array(); while ($row = mysqli_fetch_assoc($result)) { array_push($eventArray, $row); } mysqli_free_result($result); mysqli_close($con); echo json_encode($eventArray); ?> Thank you both so much for your help. Love your work.
- 8 replies
-
- fullcalendar
- javascrip
-
(and 2 more)
Tagged with:
-
Hi mate, Did a Var dump (I think) and this is what it showed: object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(1) ["lengths"]=> array(1) { [0]=> int(1) } ["num_rows"]=> int(1) ["type"]=> int(0) }
- 8 replies
-
- fullcalendar
- javascrip
-
(and 2 more)
Tagged with:
-
Hi mate, Nothing in console. Just a few things with datatables, which I am aware of. Is there an alternative calendar script that I can use that you would recommend? Thanks for your help.
- 8 replies
-
- fullcalendar
- javascrip
-
(and 2 more)
Tagged with:
-
I have changed that now. All I want to do is display the name, start date and finish date in the calendar. $data = array(); $query = "SELECT * FROM tours ORDER BY id"; $statement = $con->prepare($query); $statement->execute(); $result = $statement->fetchAll(); foreach ($result as $row) { $data[] = array( 'id' => $row["id"], 'title' => $row["name"], 'start' => $row["dep_date"], 'end' => $row['ret_date'] ); } echo json_encode($data); I have never used calendars before and am clueless with Javascript etc so any help with this would be appreciated.
- 8 replies
-
- fullcalendar
- javascrip
-
(and 2 more)
Tagged with:
-
Hi guys, I am trying to display tour information in fullcalendar but nothing is happening and no errors. Here is the php code from fetch-tours.php <?php require_once "config.php"; $json = array(); $sqlQuery = "SELECT * FROM jobs ORDER BY id"; $result = mysqli_query($con, $sqlQuery); $eventArray = array(); while ($row = mysqli_fetch_assoc($result)) { $title = isset($row['name']); $start = isset($row['dep_date']); $end = isset($row['ret_date']); $eventsArray['title'] = $title; $eventsArray['start'] = $start; $eventsArray['end'] = $end; array_push($eventArray, $row); } mysqli_free_result($result); mysqli_close($con); echo json_encode($eventArray); ?> And here is the Javascript that displays the calendar: <script type="text/javascript"> $(document).ready(function() { var date = new Date(); var d = date.getDate(); var m = date.getMonth(); var y = date.getFullYear(); $('#calendar').fullCalendar( { header: { left: 'prev,next today', center: 'title', right: 'month,basicWeek,basicDay' }, editable :true, events: "includes/fetch-tours.php", }); }) </script> The calendar displays fine but just no data. Any help is greatly appreciated. Cheers, Dan
- 8 replies
-
- fullcalendar
- javascrip
-
(and 2 more)
Tagged with:
-
Updating Textbox2 based on Textbox1 Autocomplete
Moorcam replied to Moorcam's topic in Javascript Help
Hello guys, Been a while. Between travelling half the bloody country, being sick and travelling again (work), I finally got time to sit down and look into this issue. Got it to work by using the following array in my php code: $res[] = array("value"=>$row['location_phone'],"label"=>$row['location_name']); My next goal is to make you guys so proud. 😂 Yes, I am going to use my upcoming leave from work to change all my code to prepared. Thanks so much for all your help and advice thus far. I had to reread what you said about using the ajax plugin to set the phone number to a text box upon selection of location name. Thanks so much for this. Dan -
You are very welcome.
-
Updating Textbox2 based on Textbox1 Autocomplete
Moorcam replied to Moorcam's topic in Javascript Help
LOL I know right. I will, I promise. Some day you will be proud. lol I will look into the other stuff. Thanks mate. -
Hi guys, Back to annoy you again. Sorry I am getting information from the Database to textbox1 (location_name), which uses an autocomplete. This works lovely. Now, what I want to do is, in textbox2 (location_phone) is have the phone number associated with the value of textbox1 to show in textbox2 automagically. Here is the HTML of both fields: <div class="row form-group"> <div class="col-6"> <div class="form-group"><label for="location" class=" form-control-label">location</label> <input type="text" id="location" name="location" value="<?php echo $row['location']; ?>" class="form-control"> </div> </div> <div class="col-6"> <div class="form-group"><label for="price" class=" form-control-label">Location Phone</label><input type="text" id="location_phone" name="location_phone" value="<?php echo $row['location_phone']; ?>" class="form-control"></div> </div> </div> Here is the php in autocomplete.php: <?php include('config.php'); if (isset($_GET['term'])) { $query = "SELECT * FROM locations WHERE location_name LIKE '{$_GET['term']}%' LIMIT 25"; $result = mysqli_query($con, $query); if (mysqli_num_rows($result) > 0) { while ($row = mysqli_fetch_array($result)) { $res[] = $row['location_name']; } } else { $res = array(); } //return json res echo json_encode($res); } And, finally, the Austocomplete script, which helps to populate textbox1: $(function() { $( "#location" ).autocomplete({ source: 'includes/autocomplete.php', }); }); If anyone can help put this one to bed I would be so grateful and will buy you a Guinness sometime Cheers.
-
<input type="text" class="searchTerm" placeholder="What are you looking for?"> <button type="submit" class="searchButton"> <i class="fa fa-search"></i> </button> You need Font Awesome. If you have it, try the above. https://fontawesome.com/icons?d=gallery&p=2
-
Thanks mate. Still wasn't working for me. So, gave in and reverted back to good old text boxes.
-
Adding Google recaptcha 3 to working PHP form
Moorcam replied to sn0wman23's topic in PHP Coding Help
Cross-Origin Read Blocking (CORB), an algorithm by which dubious cross-origin resource loads may be identified and blocked by web browsers before they reach the web page..It is designed to prevent the browser from delivering certain cross-origin network responses to a web page. -
Hi requinix, Thanks for the reply. When I add location_id to the query I only get the id number in the dropdown. <?php $sql = "SELECT DISTINCT location_id, location_name, location_phone FROM locations"; $result = $con->query($sql); ?> <select name="location" id="location" onchange="myFunction()" class="form-control"> <?php while($r = mysqli_fetch_row($result)) { echo "<option data-location_name='$r[1]' data-location_phone='$r[2]' value='$r[0]' selected> $r[0] </option>"; } ?> Sorry mate. Struggling with this one.
-
Adding Google recaptcha 3 to working PHP form
Moorcam replied to sn0wman23's topic in PHP Coding Help
What errors are you getting? By saying it just doesn't work could mean anything. Any errors you get can make it easier for you to get help. Turn on error reporting if you have not done so. ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); -
Hi guys, Before we go further, yes, I know I should use prepared statements. This is just a project that will probably never go live. If I do decide to go live, I will change to prepared statements. Anyways, I am populating a text box from the selection of an options dropdown and updating MySQL. This all works fine. However, what I want to do is have the newly inserted option display by default in the dropdown. Hope this makes sense. Here is the dropdown code with the select statement... <div class="row form-group"> <div class="col-6"> <div class="form-group"><label for="location" class=" form-control-label">location</label> <?php $sql = "SELECT location_name, location_phone FROM locations"; $result = $con->query($sql); ?> <select name="location" id="location" onchange="myFunction()" class="form-control"> <?php while($r = mysqli_fetch_row($result)) { echo "<option data-location_name='$r[1]' data-location_phone='$r[2]' value='$r[0]'> $r[0] </option>"; } ?> </select> <label>Phone</label><input type="text" class="form-control" name="location_phone" id="location_name" value = "<?php echo $row['location_phone']; ?>"/> I am grabbing the location name and phone number from locations. Then inserting them into tours. So after the form is submitted, I want the location name to stay in the dropdown. This is in the table "tours". How do I implement that in here? Thanks heaps.
-
Thanks both. Sorry it took so long to respond. Been working on the road. This seems to work: // add a page $pdf->AddPage(); $html4 = '<h2>Contacts</h2> <table width="600px" border="1px">'; //data iteration $sql = "SELECT * FROM tours"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { { $location=$row['location']; // concatenate a string, instead of calling $pdf->writeHTML() $html4 .= '<tr><td>'.$location.'</td></tr>'; } } } $html4 .= '</table>'; // output the HTML content $pdf->writeHTML($html4, true, false, true, false, ''); Hope this is what you guys meant?
-
Hi all, I am trying to get data from MySQL to display in a html table in TCPDF but it is only displaying the ID. $accom = '<h3>Accommodation:</h3> <table cellpadding="1" cellspacing="1" border="1" style="text-align:center;"> <tr> <th><strong>Organisation</strong></th> <th><strong>Contact</strong></th> <th><strong>Phone</strong></th> </tr> <tbody> <tr>'. $id = $_GET['id']; $location = $row['location']; $sql = "SELECT * FROM tours WHERE id = $id"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { '<td>'.$location.'</td> <td>David</td> <td>0412345678</td> </tbody>'; } } '</tr> </table>'; Anyone got any ideas?
-
Hi guys, I really hope this will make sense. I am creating a dynamic field on a button click for Pickup Location. That works fine and submitting the form to the database works fine. However, instead of one entry, each time I submit the form with multiple Pickup Locations, it creates multiple separate database entries. Here is the PHP for submitting: if(isset($_POST['new']) && $_POST['new']==1){ $pickups = ''; foreach($_POST['pickups'] as $cnt => $pickups) $pickups .= ',' .$pickups; $locations = count($_POST["pickups"]); if ($locations > 0) { for ($i=0; $i < $locations; $i++) { if (trim($_POST['pickups'] != '')) { $name = mysqli_real_escape_string($con, $_POST['name']); $price = mysqli_real_escape_string($con, $_POST['price']); //$origin = $_POST['origin']; $pickups = $_POST["pickups"][$i]; $destination = mysqli_real_escape_string($con, $_POST['destination']); $dep_date = mysqli_real_escape_string($con, $_POST['dep_date']); $ret_date = mysqli_real_escape_string($con, $_POST['ret_date']); $fleet_number = mysqli_real_escape_string($con, $_POST['fleet_number']); $driver = mysqli_real_escape_string($con, $_POST['driver']); $itinerary = mysqli_real_escape_string($con, $_POST['itinerary']); $submittedby = mysqli_real_escape_string($con, $_SESSION["username"]); $trn_date = mysqli_real_escape_string($con, date("Y-m-d H:i:s")); $query="insert into tours (`name`, `price`, `pickups`, `destination`, `dep_date`, `ret_date`, `fleet_number`, `driver`, `itinerary`, `submittedby`, `trn_date`)values ('$name', '$price', '$pickups', '$destination', '$dep_date', '$ret_date', '$fleet_number', '$driver', '$itinerary', '$submittedby', '$trn_date')"; mysqli_query($con,$query) or die(mysqli_error($con)); if(mysqli_affected_rows($con)== 1 ){ $message = '<i class="fa fa-check"></i> - Record Inserted Successfully'; } } } } } Here is the HTML form: <form role="form" method="post" name="add_tour" id="add_tour" action""> <input type="hidden" name="new" value="1" /> <div class="modal-body"> <div class="row form-group"> <div class="col-6"> <div class="form-group"><label for="name" class=" form-control-label">Name</label><input type="text" id="name" name="name" placeholder="Tour Name" class="form-control"> </div> </div> <div class="col-6"> <div class="form-group"><label for="price" class=" form-control-label">Price</label><input type="text" id="price" name="price" placeholder="0.00" class="form-control"> </div> </div> </div> <div class="row form-group"> <div class="col-6"> <div class="form-group origin" id="pickupsfield"><label for="pickups" class=" form-control-label">Pickup Location</label><input type="text" id="pickups" name="pickups[]" placeholder="Start Typing..." class="form-control"></div> <button type="button" class="btn btn-success add-field" id="add" name="add">Add New Location <span style="font-size:16px; font-weight:bold;">+ </span> </button> </div> <div class="col-6"> <div class="form-group"><label for="destination" class=" form-control-label">Destination</label><input type="text" id="destination" name="destination" placeholder="Start Typing..." class="form-control"></div> </div> </div> <div class="row form-group"> <div class="col-6"> <div class="form-group"><label for="dep_date" class=" form-control-label">Departure Date</label><input type="date" id="dep_date" name="dep_date" placeholder="" class="form-control"></div> </div> <div class="col-6"> <div class="form-group"><label for="ret_date" class=" form-control-label">Return Date</label><input type="date" id="ret_date" name="ret_date" placeholder="" class="form-control"></div> </div> </div> <div class="row form-group"> <div class="col-6"> <div class="form-group"><label for="fleet_number" class=" form-control-label">Fleet Number</label> <select class="form-control" id="fleet_number" name="fleet_number"> <option value="Select">== Select Fleet Number ==</option> <?php $sql = "SELECT fleet_number FROM fleet"; $result = $con->query($sql); while(list($fleet_number) = mysqli_fetch_row($result)){ $option = '<option value="'.$fleet_number.'">'.$fleet_number.'</option>'; echo ($option); } ?> </select> </div> </div> <div class="col-6"> <?php ?> <div class="form-group"><label for="driver" class=" form-control-label">Driver</label> <select class="form-control" id="driver" name="driver"> <option value="Select">== Select Driver ==</option> <?php $sql = "SELECT name FROM drivers"; $result = $con->query($sql); while(list($driver) = mysqli_fetch_row($result)){ $option = '<option value="'.$driver.'">'.$driver.'</option>'; echo ($option); } ?> </select> </div> </div> </div> <div class="form-group"><label for="itinerary" class=" form-control-label">Itinerary</label> <textarea class="form-control" id="itinerary" name="itinerary"></textarea> </div> <div class="modal-footer"> <button type="reset" class="btn btn-warning">Clear Form</button> <button type="submit" name="submit" id="submit" class="btn btn-primary">Confirm</button> </div> </form> And the Javascript for adding the new fields: <script> $(document).ready(function(){ var i = 1; $("#add").click(function(){ i++; $('#pickupsfield').append('<div id="row'+i+'"><input type="text" name="pickups[]" placeholder="Enter pickup" class="form-control"/></div><div><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></div>'); }); $(document).on('click', '.btn_remove', function(){ var button_id = $(this).attr("id"); $('#row'+button_id+'').remove(); }); $("#submit").on('click',function(){ var formdata = $("#add_tour").serialize(); $.ajax({ url :"", type :"POST", data :formdata, cache :false, success:function(result){ alert(result); $("#add_tour")[0].reset(); } }); }); }); </script> Anyone have any idea where I am going wrong? Before you say it, Yes, I know, Use Prepared statements 😷
-
Sorry I was joking with the Bro part. Ok, it seems that there is an issue with the JS this line: var dataResult = JSON.parse(dataResult); The Console keeps pointing to that line. Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>)
-
Love the Bubble bust lol No that part is PHP bro. I know you know that. I did a little more research and for some reason when it is being submitted it is not checking the ID in the WHERE clause.