Solved

Javascript / JQuery / PHP Query

Posted on 2011-02-23
13
550 Views
Last Modified: 2012-06-21
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
Comment
Question by:error77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 3
13 Comments
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 34963655
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
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 34963665
You can put everything in one php file, jQuery, JS, PHP - in my opinion it would be better to debug.
0
 
LVL 5

Expert Comment

by:onemadeye
ID: 34963721
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:error77
ID: 34963819
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
 

Author Comment

by:error77
ID: 34966106
Anyone please?
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 34967666
So the html page would have some kind of form right ?
0
 

Author Comment

by:error77
ID: 34967840
Yes
0
 
LVL 5

Expert Comment

by:onemadeye
ID: 34968117
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
 

Author Comment

by:error77
ID: 34968434
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
 
LVL 5

Expert Comment

by:onemadeye
ID: 34968485
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
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 500 total points
ID: 34968942
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
 
LVL 27

Assisted Solution

by:Lukasz Chmielewski
Lukasz Chmielewski earned 500 total points
ID: 34968959
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
 

Author Closing Comment

by:error77
ID: 34969312
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question