Jump to content

Moorcam

Members
  • Posts

    197
  • Joined

  • Last visited

Posts posted by Moorcam

  1. 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.

    On 3/20/2021 at 7:47 PM, requinix said:
    $query = "SELECT * FROM locations WHERE location_name LIKE '{$_GET['term']}%' LIMIT 25";

    Stop that. You have mysqli so use its prepared statements.

     

    If you want the phone number to show up somewhere then you're going to have to return it with your AJAX. Look into the documentation for your autocomplete plugin to see how you should proceed.
    For example, one possibility is that your AJAX (autocomplete.php) returns an array of [location_name, phone number], you tell the plugin that it should use the "location_name" value, and you provide a callback function when an entry is selected so you can take the phone number and set it in the textbox.

    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

  2. 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.

  3.  

     

    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.

  4. 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.

  5. 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.

  6. 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?

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

  8. 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 &nbsp; 
          <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 😷

  9. 8 minutes ago, requinix said:

    Well your code, bro, very clearly includes the id in the WHERE, so...

    My point was that if there was an error then you would not get an alert() about it. The code would die with an error in your browser's developer console, which you may or may not be checking.

    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>) 

  10. 5 hours ago, requinix said:

    :psychic:

    
    echo "Error: " . $query . "<br>" . mysqli_error($con);

    That is not valid JSON. If this gets outputted then the AJAX code will break because JSON.parse() will fail.

    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.

  11. Hi all,

    I am hopeless with Javascript etc but want to do updates, add, delete etc via a Bootstrap Modal. Everything works fine except for Update.

    No errors etc, just nothing happens.

    Here is the JS for the Update:

    	$(document).on('click','.update',function(e) {
    		var id=$(this).attr("data-id");
    		var name=$(this).attr("data-name");
    		var email=$(this).attr("data-email");
    		var phone=$(this).attr("data-phone");
    		var address=$(this).attr("data-address");
    		$('#id_u').val(id);
    		$('#name_u').val(name);
    		$('#email_u').val(email);
    		$('#phone_u').val(phone);
    		$('#address_u').val(address);
    	});
    	
    	$(document).on('click','#update',function(e) {
    		var data = $("#update_form").serialize();
    		$.ajax({
    			data: data,
    			type: "post",
    			url: "includes/functions.php",
    			success: function(dataResult){
    					var dataResult = JSON.parse(dataResult);
    					if(dataResult.statusCode==200){
    						$('#editDriverModal').modal('hide');
    						alert('Data updated successfully !'); 
                            location.reload();						
    					}
    					else if(dataResult.statusCode==201){
    					   alert(dataResult);
    					}
    			}
    		});
    	});

    Here is the php for the Update:

    if(count($_POST)>0){
    	if($_POST['type']==2){
    		$id=$_POST['id'];
    		$name=mysqli_real_escape_string($con, $_POST['name']);
    		$email=$_POST['email'];
    		$phone=$_POST['phone'];
    		$address=$_POST['address'];
    		$query = "UPDATE `drivers` SET `name`='$name',`email`='$email',`phone`='$phone',`address`='$address' WHERE id=$id";
    		if (mysqli_query($con, $query)) {
    			echo json_encode(array("statusCode"=>200));
    		} 
    		else {
    			echo "Error: " . $query . "<br>" . mysqli_error($con);
    		}
    		mysqli_close($con);
    	}
    }

    And finally the Bootstrap form:

    	<!-- Edit Modal HTML -->
    	<div id="editDriverModal" class="modal fade">
    		<div class="modal-dialog">
    			<div class="modal-content">
    				<form id="update_form">
    					<div class="modal-header">						
    						<h4 class="modal-title">Edit User</h4>
    						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    					</div>
    					<div class="modal-body">
    						<input type="hidden" id="id_u" name="id" class="form-control" required>					
    						<div class="form-group">
    							<label>Name</label>
    							<input type="text" id="name_u" name="name" class="form-control" required>
    						</div>
    						<div class="form-group">
    							<label>Email</label>
    							<input type="email" id="email_u" name="email" class="form-control" required>
    						</div>
    						<div class="form-group">
    							<label>PHONE</label>
    							<input type="phone" id="phone_u" name="phone" class="form-control" required>
    						</div>
    						<div class="form-group">
    							<label>Address</label>
    							<input type="city" id="address_u" name="address" class="form-control" required>
    						</div>					
    					</div>
    					<div class="modal-footer">
    					<input type="hidden" value="2" name="type">
    						<input type="button" class="btn btn-default" data-dismiss="modal" value="Cancel">
    						<button type="button" class="btn btn-info" id="update">Update</button>
    					</div>
    				</form>
    			</div>
    		</div>
    	</div>

    Data displays fine inside the Modal so it is communicating with the Database. But just when I click on Update nothing happens.

    Any help or guidance would really be appreciated.

    Thanks in advance...

  12. Hi all,

    Bit of a dilema.

    If I add, update items through the Modal form, all works well. But, if I delete an item, everything works fine, but the window stays greyed out. Even if I check a checkbox and delete that way it works fine.

    The Delete part of the Ajax:

    	$(document).on("click", ".delete", function() { 
    		var id=$(this).attr("data-id");
    		$('#id_d').val(id);
    		
    	});
    	$(document).on("click", "#delete", function() { 
    		$.ajax({
    			url: "includes/save.php",
    			type: "POST",
    			cache: false,
    			data:{
    				type:3,
    				id: $("#id_d").val()
    			},
    			success: function(dataResult){
    					$('#deleteDriverModal').modal('hide');
    					$("#"+dataResult).remove();
    			
    			}
    		});
    	});

    Here is the Multiple Delete section:

    	$(document).on("click", "#delete_multiple", function() {
    		var user = [];
    		$(".user_checkbox:checked").each(function() {
    			user.push($(this).data('user-id'));
    		});
    		if(user.length <=0) {
    			alert("Please select records."); 
    		} 
    		else { 
    			WRN_PROFILE_DELETE = "Are you sure you want to delete "+(user.length>1?"these":"this")+" row?";
    			var checked = confirm(WRN_PROFILE_DELETE);
    			if(checked === true) {
    				var selected_values = user.join(",");
    				console.log(selected_values);
    				$.ajax({
    					type: "POST",
    					url: "includes/save.php",
    					cache:false,
    					data:{
    						type: 4,						
    						id : selected_values
    					},
    					success: function(response) {
    						var ids = response.split(",");
    						for (var i=0; i < ids.length; i++ ) {	
    							$("#"+ids[i]).remove(); 
    						}	
    					} 
    				}); 
    			}  
    		} 
    	});
    	$(document).ready(function(){
    		$('[data-toggle="tooltip"]').tooltip();
    		var checkbox = $('table tbody input[type="checkbox"]');
    		$("#selectAll").click(function(){
    			if(this.checked){
    				checkbox.each(function(){
    					this.checked = true;                        
    				});
    			} else{
    				checkbox.each(function(){
    					this.checked = false;                        
    				});
    			} 
    		});
    		checkbox.click(function(){
    			if(!this.checked){
    				$("#selectAll").prop("checked", false);
    			}
    		});
    	});

    If anyone could help that would be great.

  13. 21 minutes ago, Barand said:

    Both updates happen only when

    
    if(!empty($_FILES['image']['name'])) { ...

    image.thumb.png.e47f79c382cc4201137e30e1cd20249c.png

    DOH!!!

    Makes sense and works.

      	// image file directory
      	$target = "uploads/".basename($image);
      	    if(!empty($_FILES['image']['name'])) {
        $sql = "UPDATE slide SET slide_text='".$slide_text."', image='".$image."', youtube='".$youtube."', vid_text='".$vid_text."'"; 
      	}
      else{
        $sql = "UPDATE slide SET slide_text='".$slide_text."', youtube='".$youtube."', vid_text='".$vid_text."'"; 
      }
         $result = mysqli_query($con, $sql);

    Thanks man. :)

  14. 12 minutes ago, Barand said:

    What exactly does that mean? What happens, or doesn't happen.

    Hi mate,

    Nothing happens. No errors etc.

    If I just update some text and click submit, nothing happens. But, if I load a new image into the file input and click update, any changes to text are successful.

    What I am trying to achieve is for me to be able to change text without having to upload a new image each time.

  15. Hi folks,

    This has been wrecking my brain. I did do a google a few times to see if I can find a solution but nothing unfortunately.

    I want to be able to update the details on a page without having to reupload a new image each time. But if I don't open a new image for upload, I cannot update any of the other details.

    Below is the code and form etc for this particular thing...

    Please note this is just a project and will not be going live. I know there are vulnerabilities and I will work on those at a later stage. Thanks for any help with this current issue.

    <?php
    include_once('includes/header.php');
    
    
    
    if(isset($_POST['new']) && $_POST['new']==1){
    
    if (isset($_POST['submit'])) {
        if(!empty($_FILES['image']['name'])) {
      	// Get image name
      	$image = $_FILES['image']['name'];
    
    $image = mysqli_real_escape_string($con, $_FILES['image']['name']);
    $slide_text = mysqli_real_escape_string($con, $_POST['slide_text']);
    $youtube = mysqli_real_escape_string($con, $_POST['youtube']);
    $vid_text = mysqli_real_escape_string($con, $_POST['vid_text']);
    
    
      	// image file directory
      	$target = "uploads/".basename($image);
      	if($_POST['image'] = ""){
        $sql = "UPDATE slide SET slide_text='".$slide_text."', image='".$image."', youtube='".$youtube."', vid_text='".$vid_text."'"; 
      	}
      else{
        $sql = "UPDATE slide SET slide_text='".$slide_text."', youtube='".$youtube."', vid_text='".$vid_text."'"; 
      }
         $result = mysqli_query($con, $sql);
    
      	if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
      		$msg = "Image uploaded successfully";
      	}else{
      		$msg = "Failed to upload image";
      	}
      	
         if(!$result){ 
            die('Error: ' . mysqli_error($con));
         } else{ 
                
           $message = ' - <i class="fa fa-check success"> Record Updated!</i>';
    
        } 
        }
    }
    }
    $sql = "SELECT * FROM slide";
    $result = $con->query($sql);
    
    if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
    ?>
            <!-- Header-->
    
            <div class="breadcrumbs">
                <div class="col-sm-4">
                    <div class="page-header float-left">
                        <div class="page-title">
                            <h1>Slide Show</h1>
                        </div>
                    </div>
                </div>            <div class="col-sm-8">
    
                </div>
            </div>
    
            <div class="content mt-3">
                <div class="animated fadeIn">
                    <div class="row">
    
                     <div class="col-lg-12">
                        <div class="card">
                          <div class="card-header"><strong>Image </strong><small>Slide</small></div>
                          <div class="card-body card-block">
                                <form role="form" method="post" action"" enctype="multipart/form-data">
                                    <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="image" class=" form-control-label">Image</label>
                                    <input type="file" id="image" name="image" value="<?php echo $row['image']; ?>" class="form-control">
                                    </div>
                                    </div>
                              <div class="col-6">
                               <div class="form-group"><label for="name" class=" form-control-label">Uploaded Image</label>
                              <img src="uploads/<?php echo $row['image']; ?>" width="150" height="150" class="img-fluid hover-shadow" />
                              </div>
                              </div>
                              </div>
    
                            <div class="row form-group">
                              <div class="col-6">
                                    <div class="form-group"><label for="youtube" class=" form-control-label">Video</label>
                                    <input type="text" id="youtube" name="youtube" value="<?php echo $row['youtube']; ?>" placeholder="Enter Video URL" class="form-control">
                                    
                                    </div>
                                    </div>
                              <div class="col-6">
                                    <div class="form-group"><label for="vid_text" class=" form-control-label">Video Text</label>
                                    <input type="text" id="vid_text" name="vid_text" value="<?php echo $row['vid_text']; ?>" placeholder="Video Text" class="form-control">
                                    
                                    </div>
                              </div>
                              </div>
                              
                            <div class="form-group"><label for="slide_text" class=" form-control-label">Text Overlay</label>
                            <textarea is="slide_text" name="slide_text" class="form-control"><?php echo $row['slide_text']; ?></textarea>
                            </div>
                            
                                <div class="modal-footer">
                                    <button type="submit" name="submit" id="submit" class="btn btn-primary">Confirm</button>
                                </div>
                                </form>
                      </div>
                    </div>
                </div><!-- .animated -->
            </div><!-- .content -->
    <?php
    }
    }
    ?>
    
        </div><!-- /#right-panel -->
    
        <!-- Right Panel -->
    
    
        <script src="assets/js/vendor/jquery-2.1.4.min.js"></script>
        <script src="assets/js/popper.min.js"></script>
        <script src="assets/js/plugins.js"></script>
        <script src="assets/js/main.js"></script>
    
    
        <script src="assets/js/lib/data-table/datatables.min.js"></script>
        <script src="assets/js/lib/data-table/dataTables.bootstrap.min.js"></script>
        <script src="assets/js/lib/data-table/dataTables.buttons.min.js"></script>
        <script src="assets/js/lib/data-table/buttons.bootstrap.min.js"></script>
        <script src="assets/js/lib/data-table/jszip.min.js"></script>
        <script src="assets/js/lib/data-table/pdfmake.min.js"></script>
        <script src="assets/js/lib/data-table/vfs_fonts.js"></script>
        <script src="assets/js/lib/data-table/buttons.html5.min.js"></script>
        <script src="assets/js/lib/data-table/buttons.print.min.js"></script>
        <script src="assets/js/lib/data-table/buttons.colVis.min.js"></script>
        <script src="assets/js/lib/data-table/datatables-init.js"></script>
    
     <script src="https://cdn.tiny.cloud/1/sw6bkvhzd3ev4xl3u9yx3tzrux4nthssiwgsog74altv1o65/tinymce/5/tinymce.min.js" referrerpolicy="origin"></script>
    
      <script>
        tinymce.init({
          selector: 'textarea',
          plugins: 'advlist autolink lists link image charmap print preview hr anchor pagebreak',
          toolbar_mode: 'floating',
       });
      </script>
      
        <script type="text/javascript">
            $(document).ready(function() {
              $('#customer-table').DataTable();
            } );
        </script>
    
    
    </body>
    </html>

    As you can see I am trying to use an If clause if the image field in the form is empty then I just want to update the other details. Else, if I fill the image field with a file, then update the lot.

      	if($_POST['image'] = ""){
        $sql = "UPDATE slide SET slide_text='".$slide_text."', image='".$image."', youtube='".$youtube."', vid_text='".$vid_text."'"; 
      	}
      else{
        $sql = "UPDATE slide SET slide_text='".$slide_text."', youtube='".$youtube."', vid_text='".$vid_text."'"; 
      }

    This doesn't work.

    Any ideas, besides give up? :D

     

  16. 15 hours ago, requinix said:

    To answer the question itself, check your assumptions about those placeholders and the template file.

    But this is all wrong. Creating files like this is definitely not the way to go about it. You say this is for learning purposes, right? Then you should definitely want to learn the right way to do it.

    Given that the template stuff isn't working correctly (or rather, why it isn't working correctly) I can't quite say for sure exactly what it is you need to do. What I can tell you is that should be having one single PHP file handling every "page". A file that will probably look a lot like your template.php, in fact.
    What you do is tell your web server that certain URLs it doesn't recognize should be routed to a PHP script. In this case, that URL would be something resembling the "name" you're currently templating. The PHP script takes that name, looks up the information in the database, and displays it.

    The term you need to research is "URL rewriting". It's not hard to do.

    Hi mate,

    You are spot on. It is a learning curve and I have taken your input on board and decided to go in the direction you suggested.

    Cheers,

    Dan

    • Like 1
×
×
  • 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.