0

I'm working on a PHP web app which at the moment allows a user to enter property information. Part of this information is rent amounts. What I am trying to do is to create a page where each rent is listed alongside a tick box. When a user ticks the box the rent is removed (paid) and displayed in another page, the rent paid page.

I have the rents list for each user displaying correctly but where I need help is implementing the checkbox that allows the user to tick and mark a rent as paid which is then moved to another page.

Can anyone offer a few pointers? I am fairly new to PHP so any help would be great.

3
  • 1
    pointer: write code - test, if fail try again. Commented Apr 22, 2012 at 20:04
  • Do a web search first (try this) and ask a question (with code) if you get stuck. Good luck! Commented Apr 22, 2012 at 20:06
  • what have you done so far? lets see your code so we can help Commented Apr 22, 2012 at 20:20

2 Answers 2

2

i think you must use AJAX for your project in this case, when a user select a checkbox then send a get or post request to server and if evry things was ok, you can redirect user to another page and show results! php itself is a serverside programming so you need a clientside scripting.

Sign up to request clarification or add additional context in comments.

Comments

1

Using jQuery and PHP:

<?php
    foreach($property as $p):
        ... # somewhere along the line where you list properties
        echo "<input class='property_rent_checkbox' type='checkbox' value='".$p['id']."' />";
    endforeach;
?>

Then use Ajax as suggested by vahid (with jQuery):

<script type="text/javascript">
    $('input.property_rent_checkbox').click(function(){
        $.ajax('/make_rented.php', dataType:'html',type:'GET',data:{id:($(this).val())}, 
            complete:function(r){ 
                if(r.responseText!=='OK') 
                    return alert('didn\'t work'); 
            return alert('Successfully rented'); 
        }});
    });
</script>

And you also need a file make_rented.php:

<?php 
    if(empty($_GET['id']) || !is_numeric($_GET['id'])) return;
    // ... use SQL to make rented... then send back "OK"
    die('OK');
?>

This example is conceptual and should guide you on how to program but you should also know that boilerplates do not exist outside of frameworks and it's all up to your own programming technique and other factors within your application that you want to take into account when writing code.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.