Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 558
  • Last Modified:

Javascript / JQuery / PHP Query

Hi all,

I need some direct, simple sample code to do the following.

Pages would be:

1. index.html
2. index.php

The index.html uses Jquery / Ajax to call the php and thr index.php queries the database and my index.html then displays the results.

Basically, I just need to php file to do the connection / query and the html / javascript page would do the rest?

The Database is MySQL by the way ...

Can anyone help please?

I just need the pure working basics for I can userstand it.

Thanks

Any suggestions
0
error77
Asked:
error77
  • 5
  • 5
  • 3
2 Solutions
 
Lukasz ChmielewskiCommented:
Wouldn't it be easier to use only the php files ? Why additional html ?
Could you be more specific about the queries or the files, the code ? Do you have any ?
0
 
Lukasz ChmielewskiCommented:
You can put everything in one php file, jQuery, JS, PHP - in my opinion it would be better to debug.
0
 
onemadeyeCommented:
If you want the page to be accessible from browser as HTML file then you can do that later via HTACCESS ... and for now, as @Roads_Roads said, I think it will be better to work it on 1 PHP file.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
error77Author Commented:
It's for use on a mobile so basically I can only use HTML, Javascript and CSS ... So ehat I thought was to query a online php file or something ... unless have a better suggestion? All the data is on an online database and I need to get it but cannot use php only html and javascript on the mobile.
0
 
error77Author Commented:
Anyone please?
0
 
Lukasz ChmielewskiCommented:
So the html page would have some kind of form right ?
0
 
error77Author Commented:
Yes
0
 
onemadeyeCommented:
If you have it written in a PHP file and able to access it from regular browser as
http://yoursite.com/yourfile.php

Next, add a .htaccess to the root and fill this:
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\.html$ $1.php [L]

Open in new window


And then the same file above is accessible through
http://yoursite.com/yourfile.html

Try it...
0
 
error77Author Commented:
Sorry, onemadeye, I don't think you understood my question. I'm not looking into htaccess issues, I need to connect to an sql database using html / ajax into a php ... html / ajax being local ... and a request being made to the php file which is remote.
0
 
onemadeyeCommented:
Nope, I think you dont understand the solution that i gave...
You're looking for 50+50=100 and I come up with 25+75=100 and you said I'm wrong?

But ok, let just do this your way, as said you need to connect to an sql database using html / ajax into a php ... html / ajax being local ... and a request being made to the php file which is remote.
And how do you want us to grant you a solution??
What have you achieve so far? How bout let us know your codes so far?
0
 
Lukasz ChmielewskiCommented:
No need to be irritated. This can be done with htaccess and only php files. But that would be assumption that te=here is an apache server instead of iis (for example). Let's stick to the html + ajax -> php way.

This would be the html file

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-1.5.js"></script>
</head>
<body>
<script>

    function checkForm()
    {
            $.ajax({
                type: "POST",
                url: "./check.php",
                data: $('#myform').serialize(),
                dataType: "json",
                success: function(msgadd){
                
                    alert(msgadd.txt);
             
                }
            });
    }

    $(document).ready(function(){
        $('#myform').submit(function(e){
            checkForm();
            e.preventDefault();
        });
    });

</script>


<form action="#" method="post" id="myform">
<input type="text" name="something" />
<input type="submit" value="send" />
</form>

</body>
</html>

Open in new window

0
 
Lukasz ChmielewskiCommented:
And this would be the check.php file

<?php header('Content-Type: text/html; charset=utf-8'); ?>
<?php
// CONNECT TO DATABASE
//include("dbconnect.php");

function msgadd($errorno,$txt)
{
	return '{"errorno":'.$errorno.',"txt":"'.$txt.'"}';
}	

if(empty($_POST[something]))
{
    die(msgadd(1,"Empty something"));
}	
else
{

    // HERE A DATABASE STUFF, CHECKING ETC
    die(msgadd(1,"Done."));

}	

?>

Open in new window

0
 
error77Author Commented:
Thanks!

p.s: onemadeye, didn't mean't for you to get offended. I'm sure your solution is fine and works but it wasn't what I was looking for. I was looking for HTML and PHP code. Thanks again.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now