maybe the x's on line 10 and 13 in the html area are messing up your code? I am not sure, you also have to have all your connections updated pulling from your own sql database. anywhere you see xxxxx you have to put your own information.
mikecronauer 0 Newbie Poster
Thanks for your reply! That was very helpful.
As a back drop, I am updateding abc123.html using AJAX, which gets data from PHP/MYSQL. Once that data is placed in a pure html file....
How does the PHP session know to stay open if I am not on a PHP page (and that PHP page has already done its job by spitting back data)?
Also, if 5 people on different computers are working with their own data, where are these sessions stored? How does a computer know which session it should use if there are multiple sessions floating around on the server put there by other computers?
mikecronauer 0 Newbie Poster
Hi all, a few quick questions. (Theory related)
1. Can you put javascript in a PHP file?
2. If the answer to that is no ... how can a website have user sign ins / security and also be using ajax to dynamically update a pure xhtml web page?
3. If the answer is yes, does using all of these things at once make it so that you are not in XHTML strict compliance?
Thanks so much for any help people can provide,
Mike
mikecronauer 0 Newbie Poster
Does AJAX(javascript) have user session functionality? I want to use AJAX PHP and MYSQL to dynamically update my static HTML page. I have got an example to work where I push and pull data out of an HTML page using AJAX, but now I want to break it up and allow individual users to do the same thing with their own data. They will have to have their own sessions / sign ins to do this ... what is the best strategy for them to do this?
Do all my .HTML pages need to be .PHP pages now? (at lease where I want to force a sign in)?
mikecronauer 0 Newbie Poster
Hi, this may or may not help ...
You have to make sure your database tables/fields line up between all these files and your database ... in this example I am using ID, username, and email to pull data in and out of an HTML file without a full page reload. Your HTML file needs to call an AJAX function which communicates with a PHP file that pulls data out of a MYSQL database. It "echos" back HTML into a specific area within the HTML file.
HERE IS PART OF THE HTML FILE .... (notice all Javascript files in the head section ... all of the onlclick functions within the HTML body can be found in the code below)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>abc123</title>
<link type="text/css" rel="stylesheet" href="bnk.css" />
<script type="text/javascript" src="utils.js"></script>
<script type="text/javascript" src="mctestpush.js"></script>
<script type="text/javascript" src="mctestpull.js"></script>
<script type="text/javascript" src="mctestremove.js"></script>
</head>
<body>
<h3>Input Transactions</h3>
<p>Input transactions here.</p>
<input type="text" id="username" name="username" />
<input type="text" id="email" name="email" />
<button type="button" onclick="mcpushdata()">pushdata</button>
<br />
<label for="rememail">Remove Data</label>
<input id="rememail" name="rememail" type="text" size="15" />
<button type="button" onclick="mcremovedata()">Remove</button><br />
<button type="button" onclick="mcshowdata()">showdata</button>
<div id="mcplacedata">
</div>
</body>
</html>
Here are the javascript files ....
mctestpull
function mcshowdata()
{
request = createRequest();
if (request==null){
return;
}
var url = 'mcgetalldata.php?+randNum=' + new Date().getTime();
request.open("GET",url,true);
request.onreadystatechange = displayDetails;
request.send(null);
}
function displayDetails() {
if (request.readyState == 4) {
if (request.status == 200) {
mcplacedata.innerHTML = request.responseText;
}
} …
mikecronauer 0 Newbie Poster
OK first I want to say ... Nyigt ...thank you so much for all of your help! You were right, IE was caching the results and this was messing up the ajax call. It was pulling non current results ... results stored away in the browsers cache. Line 8 the adjustment or "cache buster" is what solved this issue . . . the appending of a date and time. Basically it makes the URL unique, so it is different the next time someone runs it, so it does not pull the cached result.
Thanks again, there is no way I would have known about this if not for your help.
function showdata()
{
request = createRequest();
if (request==null){
return;
}
var url = 'getalldata.php?+randNum=' + new Date().getTime();
request.open("GET",url,true);
request.onreadystatechange = displayDetails;
request.send(null);
}
function displayDetails() {
if (request.readyState == 4) {
if (request.status == 200) {
placedata.innerHTML = request.responseText;
}
}
}
mikecronauer 0 Newbie Poster
I used the alerts, that helped my understaning.
Here is the thing though ... the code is working, just not more than once within the same browser session. So if you add three lines to the table and click the show data button, it works, but if you go to add more lines and click the show data button, the no new lines show up. Even if you click refresh. You have to completely close the browser and then reopen it for it to work.
Am I allowed to give you the web address so you can see what I mean? (not sure the rules of this forum)
mikecronauer 0 Newbie Poster
I trying to get this to work off of an "email" table that I have available to me....
HTML FILE - This file has the form to push the data into MYSQL and has the button to run the function to pull data back using ajax from a php file that talks to sql
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>--------------------------</title>
<link type="text/css" rel="stylesheet" href="sig.css" />
<script type="text/javascript" src="utils.js"></script>
<script type="text/javascript" src="test.js"></script>
<script type="text/javascript" src="testpull.js"></script>
</head>
<body>
<div id="allcontent">
<div id="sidebar">
<br />
<p id="home">
-------------------------
<form method="post" action="addemail.php">
<label for="username">User name:</label>
<input type="text" id="username" name="username" /><br />
<label for="email">Email:</label>
<input type="text" id="email" name="email" /><br />
<input type="submit" name="Submit" value="Submit" />
</form>
---------------------
---------------
<button type="button" onclick="showdata()">showdata</button>
<div id="placedata">
</div>
</div>
</div>
</body>
</html>
addemail.php --- no ajax here, HTML feeds mysql using post ----
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Kill Debt Get Rich</title>
<link type="text/css" rel="stylesheet" href="sig.css" />
</head>
<body>
<?php
$dbc = mysqli_connect('localhost', '-----, -----,------')
or die('Error connecting to MySQL server.');
$user_name = $_POST['username'];
$email = $_POST['email'];
$query = "INSERT INTO email_list (user_name, email) VALUES ('$username', '$email')";
mysqli_query($dbc, $query)
or die('Error querying database.');
echo 'Email added.';
mysqli_close($dbc);
?>
</body>
</html>
If I add 10 items to MYSQL I want to be able to instantly view them by clicking my "show data button" .... so the rest is Javascript / …
mikecronauer 0 Newbie Poster
I am using a web page to input data into mysql using php.
I am using ajax to pull back the same data from a php file on the same web page.
I click my "get data" button (it runs my ajax/php function) right after I make an update to the database, and the data will not refresh! It only will show the newly input data if I fully close and re open my browser (internet explorer). I tried refreshing the page and then re running the function but it does not work. I actually have to fully close the ie session and open it back up to get the new data to show up.
Why is this?
mikecronauer 0 Newbie Poster
This stuff can get complicated. I recently read beginner books on HTML, JavaScript, PHP&MYSQL, and finally AJAX. I read the Head First books as I found they brought it to my level of experience (basically no experience). Now I am at least able to surf around and put snippets of code together.
HTML is full of objects that can be manipulated on the fly with Javascript (client side programming) PHP is your server side language that can interact with MySQL
AJAX is a good bridge between the two, but you can always just use PHP to do the same thing.
I would study PHP & MYSQL first and then branch out.
mikecronauer 0 Newbie Poster
I really appreciate your response, I am checking out pagination and have made progress. I will post the code here soon and mark as solved .... I would never have searched for that term so your replys is very helpful!
mikecronauer 0 Newbie Poster
How would I build a web page similar to an online banking page that has a running account balance, only I want to make each line editable. If a specific line was edited the total would then change up through the top. (transactions are sorted by date order)
How do you break up a sql table in 50 line increments? So it only shows you 50 lines on one page with the ability to click on the previous 50 items, etc etc until you reach the first/oldest transaction?
I can pull back full tables, but breaking them up in sections is hard. I also cant figure out where to do the "running total" math.
If someone could give me some specific functions I could study, or a strategy using the various technologies I would be very very grateful. (I have read beginner books on SQL, Javascript, PHP, AJAX, HTML/CSS and now am reading an advanced book on PHP.)
It seems relatively simple what I am trying to do ...
ID key--Date--Name--CODE--Cleared?--Amount--RunningTotal-- EDIT--SUBMIT
1-50 -> 50-100 (link at bottom of block)
ID Key - this would be primary key, never to be deleted, just made zero if necessary
Date - Creation Date for each record
Name - What a person would want to name each transaction
CODE - A dropdown to code the transaction type
Cleared - YES or NO dropdown to tell if transaction cleared the bank
Amount …
mikecronauer 0 Newbie Poster
OK- After some study I am able to answer my own question ... here is the code ...
HTML CODE ----- Will show data in place data area
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>xxxxxxxxx</title>
<link type="text/css" rel="stylesheet" href="sig.css" />
<script type="text/javascript" src="utils.js"></script>
<script type="text/javascript" src="testpull.js"></script>
</head>
<body>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
<button type="button" onclick="showdata()">showdata</button>
<div id="placedata">
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</div>
</div>
</div>
</body>
</html>
Here is Utils.js Javascript code
function createRequest() {
try {
request = new XMLHttpRequest();
} catch (tryMS) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (otherMS) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = null;
}
}
}
return request;
}
HERE IS THE TESTPULL.JS JAVASCRIPT FILE
function showdata()
{
request = createRequest();
if (request==null){
return;
}
var url = "getalldata.php";
request.open("GET",url,true);
request.onreadystatechange = displayDetails;
request.send(null);
}
function displayDetails() {
if (request.readyState == 4) {
if (request.status == 200) {
placedata.innerHTML = request.responseText;
}
}
}
AND FINALLY THE getalldata.php PHP CODE
<?php
$con = mysql_connect('localhost', 'XXXX', 'XXXX');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("XXXX", $con);
$result = mysql_query("SELECT * FROM email_list");
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['user_name'] . "</td>";
echo " ---- ";
echo "<td>" . $row['email'] . "</td>";
echo "<br />";
echo "</tr>";
}
mysql_close($con);
?>
I have a strange sort of satisfaction having figured this out. Hope this helps someone out there.
mikecronauer 0 Newbie Poster
Hi, I am trying to use AJAX to pull back mysql table information. I tried to alter an example I found (w3 schools) where they showed how use a selection table to pull a specific line out of a mysql table, using the "q" (not really sure if the "q" character is important or not) .... (xmlhttp.open("GET","xxxxxxx.php?q="+str,true);) I follow what they were doing there, but I want to pull the entire table back not just specific lines. (So I got rid of the Q)
Here is a snipit of HTML. The showdata function is part of the testpull.js code. You click the button and it should run the javascript to pull back the entire table and place it in the "placedata" div section.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>xxxxxxxxx</title>
<link type="text/css" rel="stylesheet" href="sig.css" />
<script type="text/javascript" src="testpull.js"></script>
</head>
<body>
...................
<div id="getdata">
</div><br />
<button type="button" onclick="showdata()">showdata</button>
<div id="placedata">
</div>
</div>
Here is my javascript file ..........
function showdata()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("placedata").innerHTML=xmlhttp.responseText;
}
xmlhttp.open("GET","getalldata.php",true);
xmlhttp.send();
}
}
Here is my PHP "getalldata.php" file........ let assume there are three fields in each row of the table but I only want column 2 & 3...
<?php
$con = mysql_connect('xxxxx', 'xxxxxx', 'xxxxxx');
if (!$con)
{
die('Could not …
mikecronauer 0 Newbie Poster
Thanks for all your help! I will move in this direction.
mikecronauer 0 Newbie Poster
Hi thank you for your response. A couple more questions :) I definately want to use AJAX. There will only be one input line at the top and I want it to auto refresh the "lower list" beneath it. (with the option of editing each line in the lower list... this will be to mark a check as cleared or still outstanding)
What would be better in this situation, to use XML or a TEXT string with the AJAX call back? If XML, how do I get my MYSQL database to produce the XML within a PHP file so I can pull it back into HTML with the AJAX "xmlhttprequest"?
With the "lower list", does each separate line/list element need to be with a form element? So would I call back 50 form elements at a time? I want each transaction to have a live link back into the database.
It seems there are so many types of strategies for moving data ... Is there a specific one I can study that will be the best one to tackle this problem? I can pieces of data back from mysql, but to make one line out of 50 "re editable" so I can push it back has proven to be very difficult.
And finally, it would be nice to have to option of sorting by any one of the fields. What function handles this?
Thanks so much.
mikecronauer 0 Newbie Poster
I am trying to set up a web based tool for my wife and I to use to balance our checkbook together. I am using HTML, Javascript (Ajax), PHP and MYSQL. I have read beginner books on all of these subjects, I can get data out of MYSQL, BUT can't do it the way I want to do it. If someone could point me to a book, or even the name of what I need to study it would be very helpful. The top line will always be input. But as you submit the top line it refreshes the "growing list" beneath it. (kind of like on-line banking, where you can look at 50 or so lines and then go back further if necessary) The catch is within the "growing list" I want to show Bank and book balance running totals and have three buttons next to each transaction ... EDIT DELETE SUBMIT. If edit is clicked, I want to be able to change that line and then resubmit it to MYSQL.
HTML form .... []=input {}=drop down list \/=auto populate ()=button
here is the line...
\date&time/ [transaction name] {type} [positve amt] [negative amt] {Cleared} (SUBMIT)
so once submit is clicked it gets pushed to the top of the running list below
Same line shows, W/running totals \bankbalance/ \bookbalance/ (EDIT) (DELETE) (SUBMIT)
This way we can both input our transactions as we spend money and know at all times how much money is in …