Hi

I've read through the posting regarding 'actions on a link' but as my function is not in javascript I didn't want to confuse the conversation.

I was wondering how/if it is possible to call a function from a text link, button, image etc via something like this:

<?php if (isset($_POST["condo_nm"])) 

     echo condoavailable($_POST["condo_nm"]) ;?>

The actuaal function is this:

function condoavailable($condo_nm)
{
// Connect to the database
 require_once ('myaccess/dbc.php');

// Make sure a review doesn't already exist for this Condo
  $query = "SELECT * FROM condo_reviews WHERE condo_nm = '$condo_nm'";
  $data = mysqli_query($dbc, $query);
  if (mysqli_num_rows($data) == 0) 
  {
echo 'Available';
  }
else {
    echo 'Review Complete';
}
}
}

What I'm trying to do is allow users to check to see whether a review has already been submitted for a particular name and if it has echo back to the screen: 'Review Complete' and if it does not exist echo to the screen 'Available'.

I just want users to be able to do this check before clicking on the 'submit' button at the end of the form.

Is there a way?

Mamy thanks

Recommended Answers

All 2 Replies

You'd need Javascript to do an AJAX call to a PHP script, which executes that function and returns the result.

You can only run a php function whilst the page is being generated - it is a server side script.

You need a javascript function to do something once the page has loaded and the user starts interacting.

AJAX that Pritaeas mentioned is a way to get javascript to open a php page when a user clicks/triggers something so you can run a php script based on what he has done(in javascript) then the php script does something and returns the data to your javascript function and shows him the data or does something based on what the php script returned.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.