PHP - Requesting Help Regarding Ajax
Hi there,
I have a question, which I seem to be unable to find out myself;
I have my own webshop (coded by myself), and trying to add multiple configurable options into it, each option having their own stock limit.
Here is the problem:
I am trying to implement AJAX for the following:
Lets say: Customer wants Product A with Config 1: A, Config 2: C and Config 3: C
Lets say config 1 is length, Config 2 is design of the product, and config 3 is the dimension of the product.
Config 1 Option A has 12 items in stock
Config 2 Option C has 7 items in stock
Config 3 Option C has 1 item in stock.
Here is my question:
How do I implement AJAX to check all these variables (so lets say: You have Config A with Option A (12 stock) B (16 stock) and C(109 stock), etc, and when she selects for example Config 3 Option C, that she can ONLY order 1 of the items, and if she tries to put the order in higher (in the selector) that it sais that with the current configuration only 1 order can be made?
Similar TutorialsHi
What is the best recommended way to "sort through" and "place certain data" into a sql table?
For example, I create a input form.php
Company Name:
The Blah CompanyProduct/Industry Dedicated ServersHTML Source Code <div class="allservers"> <div class="serverType" id="server1"> <div class="myFeaturesBox"> <ul class="tabination"> <li><a href="#" class="activeTab" data-tab='feature'>FEATURED</a></li> <li><a href="#" data-tab='single'>SINGLE PROCESSOR</a></li> <li><a href="#" data-tab='dual'>DUAL PROCESSOR</a></li> <div class="clear"></div> </ul> <div class="feature myTab activeTabs"> <table class="table"> <tr> <th></th> <th>Processor</th> <th>RAM</th> <th>Hard Drive</th> <th>Price/Mo</th> <th></th> <th></th> </tr> <tr> <td><img src='img/server.png' alt='Server' width="20" height="20" /></td> <td>Intel Xeon E3-1230 (4x3.2GHz)</td> <td>8 GB DDR3</td> <td>1x500 GB SATA</td> <td>$98.00</td> <td><a href="https://portal.securedservers.com/wap-jpost3/UP011013E31230" target="_self"><img src='img/deploy.png' alt='Deploy Now' width="86" height="18" /></a></td> <td class="wB"></td> </tr> <tr> <td><img src='img/server.png' alt='Server' width="20" height="20" /></td> <td><div style="position:relative;">Intel Xeon E3-1240 v3 (4x3.4GHz)</div></td> <td>8GB DDR3</td> <td>1x1 TB SATA</td> <td>$128.00</td> <td><a href="https://portal.securedservers.com/wap-jpost3/UP031013E31240" target="_self"><img src='img/deploy.png' alt='Deploy Now' width="86" height="18" /></a></td> <td class="wB"></td> </tr> <tr> <td><img src='img/server.png' alt='Server' width="20" height="20" /></td> <td><div style="position:relative;">Intel Xeon E3-1240 v3 4-bay (4x3.4GHz)</div></td> <td>8GB DDR3</td> <td>4x500 GB SATA</td> <td>$148.00</td> <td><a href="https://portal.securedservers.com/wap-jpost3/UP431013E31240" target="_self"><img src='img/deploy.png' alt='Deploy Now' width="86" height="18" /></a></td> <td class="wB"></td> </tr> <tr> </table>Submit Button --> sends to the "sorting process?" than into proper DB tables for search query. Ultimately, there I require to be able to pull from my DB upon query, pricing, hardware, processor, etc.. Any recommendation for me to try? I'm new to PHP but I want to learn and do it myself (better after effect feeling than paying someone) Hi: I am trying to request an id to do a transfer back to a page, but am having difficulties. This is on a page where a person can add a new section, which gets assigned a unique id. I am trying to send the user to the page where they can edit the new page, once it has been created. Like this: a_websiteDataADD.php Code: [Select] <?php $id = $_REQUEST['id']; ?> ... <script language="JavaScript"> alert("The new section was added!"); location.href = "a_websiteData.php?id=[id]"; </script> What am I missing on this ?? Hi all. I have been trying something for 2 days, having no success and was hoping someone could help. I know this is a long post but it's mostly just php code below. I'm trying to do "pagination" for a script that I came across. First of all.. I am not a programmer in any way. I didn't even know what pagination was until 2 days ago when I was trying to explain what I wanted in a forum and was educated. So.. off to Google I went. I found all kinds of "free pagination" script articles with "how-to's". Well.. I think you need to at least have an idea of how to program becuase I've tried 4 now and failed every time. Or... maybe I'm just the world's worst at understanding programming concepts (very possible). I really have spent just hours and hours trying to make pagination happen.. to no avail. So.. if you know an easier way, please share! Or.. If you care to read on and help with the pagination script I've been trying to make work, that would be awesome. Either way, I would be most grateful! Here's what I got and what I've tried.. My index.php page: Code: [Select] <?php include_once('inc_dbcon.php'); require_once('admin/config.php'); require_once($languageFile); // Preview descrition length in characters $previewLength = 240; // check to see if in admin mode and validate key global $keyOut; $keyOut = ""; if (isset($_GET["k"])) if($_GET["k"] == $key){ // Key comes from admin/password.php file $keyOut = "&k=" . $key; } global $category; $category = "%"; if (isset($_GET["category"])) $category = mysql_real_escape_string($_GET["category"]); $msg = ""; if (isset($_GET["msg"])) $msg = mysql_real_escape_string($_GET["msg"]); // SEARCH CODE START $searchQuery = ""; if (isset($_GET["q"])) $searchQuery = mysql_real_escape_string($_GET["q"]); if ($searchQuery != "") { $query_Recordset1 = "SELECT postId,category,title,description,isAvailable,description,price,confirmPassword,category,imgURL,imgURLThumb,DATE_FORMAT(timeStamp,'%b %d, %Y %l:%i %p') AS timeStamp1 FROM md_postings WHERE isConfirmed = '1' AND title like '%$searchQuery%' OR description like '%searchQuery%' ORDER BY `timeStamp` DESC"; } else { $query_Recordset1 = "SELECT postId,category,title,description,isAvailable,description,price,confirmPassword,category,imgURL,imgURLThumb,DATE_FORMAT(timeStamp,'%b %d, %Y %l:%i %p') AS timeStamp1 FROM md_postings WHERE isConfirmed = '1' AND category like '$category' ORDER BY `timeStamp` DESC"; } // SEARCH CODE END - see also line 113 below $maxRows_Recordset1 = 100; $pageNum_Recordset1 = 0; if (isset($_GET['pageNum_Recordset1'])) { $pageNum_Recordset1 = mysql_real_escape_string($_GET['pageNum_Recordset1']); } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1); $Recordset1 = mysql_query($query_limit_Recordset1); if (!$Recordset1){ print("It appears we have a problem: " . mysql_error()); exit(); } $row_Recordset1 = mysql_fetch_assoc($Recordset1); if (isset($_GET['totalRows_Recordset1'])) { $totalRows_Recordset1 = mysql_real_escape_string($_GET['totalRows_Recordset1']); } else { $all_Recordset1 = mysql_query($query_Recordset1); $totalRows_Recordset1 = mysql_num_rows($all_Recordset1); } $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1; $queryString_Recordset1 = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_Recordset1") == false && stristr($param, "totalRows_Recordset1") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams)); } } $queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1); ?> <!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"> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="md_style.css" rel="stylesheet" type="text/css" /> <script language="JavaScript"> function doFilter(dis) { window.location.href = "index.php?category=<?php echo $category ?>&type=" + dis.value + "<?php echo $keyOut;?>" } </script> </head> <body> <?php include_once("inc_navigation.php") ;?> <div id="md_container"> <?php if ($msg == "deleted") print("<br clear='all' /> <div class='md_msg' style='margin-top:-10px;'>" . STR_DELETED ."</div>"); ?> <br clear="all" /> <div id='md_listingBox'> <?php if($totalRows_Recordset1 < 1) { // SEARCH START new Code - added IF statement to support search if ($searchQuery != "") echo "<p><br /><br /><br />" . STR_NORESULTS . "<b>" . $searchQuery ."</b></p>"; else echo "<p><br /><br /><br />" . STR_NOITEMS . "</p>"; // SEARCH END NEW CODE } else { do { $img = "/images/gift_light.gif' title='This is a gift!'"; $type = $row_Recordset1['type']; $isAvailable = $row_Recordset1['isAvailable']; $isAvailableClass = ($isAvailable == 0) ? 'md_taken' : ''; $thumbnail = ' '; if (strlen($row_Recordset1['imgURLThumb']) > 3){ $thumbnail = "<a href='viewItem.php?id=" . $row_Recordset1['postId'] . "' class='md_recordLink " . $isAvailableClass . "'>"; $thumbnail .= "<img src='" . $row_Recordset1['imgURLThumb'] . "' class='md_thumbnail' border='0'></a>"; } ?> <table width="100%" border="0" cellpadding="4" class="md_listingTable"> <tr> <td width="54" align="center"><?php echo $thumbnail; ?></td> <td valign="top"> <div class='md_date'><?php echo $row_Recordset1['timeStamp1'];?></div> <a href="viewItem.php?id=<?php echo $row_Recordset1['postId'] . $keyOut;?>" class='md_recordLink<?php echo $isAvailableClass; ?>'><?php echo stripslashes($row_Recordset1['title']); ?></a> — $<?php echo $row_Recordset1['price']; ?> <br /> <?php echo stripslashes(substr($row_Recordset1['description'],0,$previewLength)); ?>... </td> </tr> </table> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); } // end else clause ?> </div> </div> <?php include_once("inc_footer.php");?> </body> </html> <?php mysql_close($dbConn); ?> Here's the inc_dbcon.php file that it calls to connect: Code: [Select] <?php // Change these to be for your database $dbhostname = "localhost"; $dbname = "justtes1_123"; $dbusername = "justtes1_12"; $dbpassword = "abc12"; if(!$dbConn = mysql_connect($dbhostname, $dbusername, $dbpassword)) die('I could not connect to the database. Clease check the inc_dbcon file and make sure everything is correct.'); if(!mysql_select_db($dbname, $dbConn)) die('I could not select the database. Check the inc_dbcon file and make sure everything is correct.'); ?> I've trying to use the pagination script from: http://www.phpeasycode.com/pagination/ Here's the "usage example" that is in the pagination script: Code: [Select] <?php $rpp = 10; // results per page $adjacents = 4; $page = intval($_GET["page"]); if($page<=0) $page = 1; $reload = $_SERVER['PHP_SELF']; // connect to your DB: $link_id = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error()); mysql_select_db($dbname, $link_id); // select appropriate results from DB: $sql = "SELECT * FROM table_name WHERE table_field LIKE '%search string%' ORDER BY field_name"; $result = mysql_query($sql, $link_id); // count total number of appropriate listings: $tcount = mysql_num_rows($result); // count number of pages: $tpages = ($tcount) ? ceil($tcount/$rpp) : 1; // total pages, last page number $count = 0; $i = ($page-1)*$rpp; while(($count<$rpp) && ($i<$tcount)) { mysql_data_seek($result,$i); $query = mysql_fetch_array($result); // output each row: echo "<p>" . $query['table_field_1'] . ", " . $query['table_field_2'] . "</p>\n"; $i++; $count++; } // call pagination function: include("paginate.php"); echo paginate_three($reload, $page, $tpages, $adjacents); ?> The pagination script also comes with a demo.php. I uploaded that and it works just great. But.. when I try to incorporate the above usage into my index.php, I fail miserably. So.. If you prefer, I can copy index.php with what I've tried.. which is apparently very wrong. The page I tried it in is he http://justtesting.freehosting.com/indexPaginate.php So.. if anyone is able to tell me how they'd incorporate the usage script into the index.php, that would solve my 2 day dilemna and I would be eternally grateful. If you want to login to my test version (feel free to edit as this is purely a test site), it's he http://justtesting.freehosting.com/ ftp host: 62.75.203.94 FTP Username: justtes1 FTP Password: JpxF34j80h A HUGE thanks for anyone who can help! I have tried everything for hours and hours.. This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=351526.0 Hey everyone, I'm new to this forum and I came here looking for some help with PHP. I've just started getting into PHP and you guys are probably a smile ahead. So basically, I have some inputs and want them to be sent to my email in a basic layout shown below. Code: [Select] Inputs: Title = _title Forum Name = _forumname Name = _irlname Age = _age I want the email to be sent to me like: Code: [Select] Email Title --------------- Forum Name: TextGiven Real Life Name: TextGiven Age: TextGiven Here is my current code which titles the email correctly, but I want to figure out how to make $message set to the example email I showed above. Code: [Select] <?php $to = "******@*********.net"; $subject = $_REQUEST['_title']; $headers = "From: ***** Applicant \r\n"; $headers .= "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\r\n" . "Content-Transfer-Encoding: 7bit\r\n"; $message = $_REQUEST['_forumname' & '_irlname']; <--- Part I want fixed if(mail($to, $subject, $message, $headers)) { echo 'MAIL SENT'; } else { echo 'MAIL FAILED'; } ?> I have this code, and it works. But I want $message = "" to make the message contain not just the forum name, but as well as the name, age, and all other inputs I want. Hello guys,
I require a suggestion about how shall I proceed as when I am about to set a goal for my future in programming world, Just so that you could suggest me better, I urge you to please read about a little background history of mine. And please stay neutral in regards of language, dont say PHP because you are a PHP developer and dont say Java because you are a Java developer.
Thanks.
I stepped into programming when I was in school (below A-levels at 14, now I am 29) and I started to bunk school and went to internet cafe and would sit there reading sources of HTML pages in year 2000. I would observe their programming styles, I would learn about the tags they used and then search internet (it was IE6 then and Yahoo searching at its peak) so I could learn about it.
Years passed, and having my family related to medical professions, I took admission in Pharmacy in University and quit after 2 years and entered working class. My development slowed down but passion always stayed the same.
Now I am in Spain and working as a technician of mobile repairing with a company, but I still have this passion of programming and when I learn that etc etc friend of mine now is working with CISCO in Germany, now is working as a game developer in America, I become really sad. I could have been one of those. But the fact is that I am not. So I restarted again with development and started learning PHP on my work desk using online resources and tutorials and asking silly questions.
Nothing I could become but an obsolete language programmer with a mess.
Now when I havent been able to become someone, till now, I still have passion and I want to be somewhere.
-----------------------------
I am confused for some days now, shall I continue with PHP (apart from the fact that i am a MYSQL learner, haven't learned PDO or MYSQLi till now) or shall I step into Java learning, using the online resources ofCourse, but if I step into Java, It will be a fresh start and I will be able to organize it better on my way with guidance of professionals like you.
The Things confusing me: (as I am imagining in my mind)
PHP:
A great web development language being used on billions of website, have an extraodinary support, well documented, World is moving online, so future is e-commerce in these terms.
JAVA:
Feels a giant to me, and impresses me at times, a myth to me, I am speaking illogical I know, and after android, I see a great potential in this language.
Edited by Digitizer, 28 August 2014 - 06:03 PM. I'm developing a javascript widget to display on other people's websites that will have a php file(on my hosting account) as its source. Is there a way for php to get the domain of the site that is requesting the php file? I want the user to be able to specify if they want the widget to only display on their website. So i would store the user's domain name in my db and then write in the php script to check to see if the website requesting the widget matches whats in my db...if so display widget...if not..don't. Ok so I am writing a CMS to wrap around a company script I wrote a while back. I am having trouble requesting dynamic form names. Heres the code to generate the input fields: $fields = mysql_result($result,$i,"fields"); $exFields = explode(",", $fields); for($i = 0; $i < count($exFields); $i++){ echo "$exFields[$i] : <input type=\"text\" name=\"$exFields[$i]\"> <br>"; } Ok so it generates the fields the way I want. (design crap will be done later) But I am having issues on processing the form, for example: Fields get generated -> Client Fills them in -> Submitted into our already built function. The function takes those form values and creates an XDF file with the correct requested values. But like I said I am having issues requesting the form values because they wont be static they will differ depending on each PDF. Can anyone point me in the direction on how to get the form values? Hi Everyone, This is Tamilmani Mohan , i have few doubts in SQL Stored Procedure. I am able to run the SQL SP using odbc driver and also get the result set. For Example: odbc_exec($connection,"exec get_Members"); I don't know how to run the input / output parameters SP's? Example:- If i run the below code by using SQL Management Visual Studio, I am able to insert to new record and get the member id and error code values. declare @MemberId int,@Error int EXEC INSERT_MEMBER 1,'Tamilmani','Mohan','Address1', 'Address2', 'Address3','Salem','Tamilnadu','India',9993234234 , @MemberId OUTPUT , @Error OUTPUT SELECT @MemberId , @Error I don't know how to run this type code in PHP ODBC ? Kindly , please any one give me good suggestion for this problem ? Thanks Tamilmani Mohan Right now I redirect to index page after I delete a record. However I am looking to make it so that I can delete a record without redirecting the page. I know this can be accomplised using Ajax. I have spent countless hours before trying to make it work, but it did not work.
So here is a basic setup I created. Can you please update it with ajax code so that I can see how it's done properly?
<!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8"> <title>Home Page</title> </head> <body> <div class="record" > <a href="record.php?id=<?php echo $record_id ?>"><?php echo $record_name; ?></a> <div class="delete-record"> <a href="delete.php">Delete Record</a> </div> </div> </body> </html> Edited by man5, 18 August 2014 - 08:55 PM. Now I'm having this strange issue with my website I'm currently working on a tester system and I've encountered a problem that I'm unable to find the issue, tho I'm thinking my ajax php part of the script to be the thing causing it even tho it seems strange that it would cause it. The first part which is connected to where the problem occurs is the echo"<form>"; and from there, It should take you to index.php?page=tester&select=answer, now that is where it in the browser goes there tho it still shows the page stuff from the last page which is index.php?page=tester&select=applications, so it's like showing both &select=answer and &select=applications on the same page. <?php $q=$_GET["q"]; include'../config/connection.php'; $result = mysql_query("SELECT * FROM applications WHERE id = '$q'"); echo "<center><table border='1'> <tr> <th>Account Name</th> <th>Character Name</th> <th>Gender</th> <th>Skin Color</th> </tr>"; $row = mysql_fetch_array($result); echo "<tr>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['charactername'] . "</td>"; echo "<td>" . $row['gender'] . "</td>"; echo "<td>" . $row['race'] . "</td>"; echo "</tr></table></center>"; echo"<br/>"; echo"<table><tr> <th>Description</th> <th>Metagaming</th> <th>Powergaming</th></tr>"; echo"<tr>"; echo "<td><textarea readonly='readonly' style='width:22em; height:20em;'>".$row['description']."</textarea></td>"; echo "<td><textarea readonly='readonly' style='width:22em; height:20em;'>".$row['mg']."</textarea></td>"; echo "<td><textarea readonly='readonly' style='width:22em; height:20em;'>".$row['pg']."</textarea></td>"; echo"</tr></table><table><br/><center><h1>Answer</h1><br/><form action='index.php?page=tester&select=answer' method='post'>"; echo"<textarea name='why' style='height:10em; width:60em;'></textarea><br/>"; echo"<input type='submit' name='answer' value='Accept' /><a/>"; echo"<input type='submit' name='answer' value='Decline' /></center>"; echo"<input type='hidden' name='id' value='$q'/>"; echo"</form></table>"; ?> Now on &select=answer it included a page which the script of that include consist of the stuff below, it outputs that the query was successfully, and all that. <? if(!empty($_POST['why'])) { $why = mysql_real_escape_string($_POST['why']); $answer = trim($_POST['answer']); $id = $_POST['id']; if($answer == "Accept") { $query1 = mysql_query("UPDATE characters SET accepted = '1' WHERE id = '".$id."'"); echo"Successfully accepted"; $answer = 1; } elseif($answer == "Decline") { echo"Successfully declined"; $answer = 0; } $query = mysql_query("UPDATE applications SET answer = '$why' AND tester = '".$_COOKIE['Username']."' AND accepted = '$answer' AND answered = '1' WHERE cid = '".$id."'") or die('Could not connect: ' . mysql_error()); if($query) { echo"<br/>Query went through without problems"; header("Refresh: 5;url=index.php?page=tester"); } } ?> This is the ajax part javascript of it which gets the information for index.php?page=tester&select=applications Code: [Select] <script type="text/javascript"> function showApplication(str) { if (str==""||str==0) { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","tester/applications.php?q="+str,true); xmlhttp.send(); } </script>If you need any more information feel free to ask for it. Thanks in advance. Hello, I've been trying this for hours now, looking at different examples and trying to change them to work for me, but with no luck... This is what I am trying to do: I have a simple form with: - 1 input field, where I can enter a number - 1 Submit Button When I enter a number into the field and click submit, I want that number to be send to the php file that is in the ajax call, then the script will take that number and run a bunch of queries and then return a new number. I want that new number to be used to call the php script via ajax again, until no number is returned, or something else is returned like the word "done" or something like that, at which point is simply makes an alert or populated a div with a message... The point is, that depending on the number entered it could take up to an hour to complete ALL the queries, so I want the script that is called to only run a fixed amount of queries at a time and then return the number it is currently at (+1), so that it can continue with the next number when it is called again. I would like to use jquery, but could also be any other way, as long as I get this to work. I already have the php script completed that needs to be called by the ajax, it returns a single number when being called. Thank you, vb As the title say, I can not for the life of me get the "$bank" content to display, no matter HOW much I try... Does anyone see any errors. I am sooooooo wiped out at this! main page <? $body = ' <script type="text/javascript" src="change-content.js"></script> <div id="addSold"> <form action="'.$_SERVER['REQUEST_URI'].'" method="post" name="form" autocomplete="off"> <fieldset id="Vehicle"> <legend>Vehicle</legend> <ul> <li><label for="Year">Year</label>'.$Year.'</li> <li><label for="Make">Make</label>'.$Make.'</li> <li><label for="Model">Model</label>'.$Model.'</li> <li><label for="Trim">Trim</label><input type="text" name="Trim" id="Trim" size="10" value="'.$trim.'" disabled="disabled"></li> </ul> <ul> <li><label for="Mileage">Mileage</label><input type="text" name="Mileage" id="Mileage" size="5" maxlength="6" value="'.$row['mileage'].'"></li> <li><label for="VIN">VIN</label><input type="text" name="VIN" id="VIN" size="23" maxlength="17" value="'.$row['vin'].'" disabled="disabled"></li> <li><label for="Color">Color</label>'.$Exterior.'</li> </ul> </fieldset> <fieldset id="Deal"> <legend>Deal</legend> <ul> <li> <label for="soldDte1">Date</label> <input type="text" name="soldDte1" id="soldDte1" size="1" maxlength="2" onkeyup="return autoTab(this, 2, event)" value="08"> / <input type="text" name="soldDte2" id="soldDte2" size="1" maxlength="2" onkeyup="return autoTab(this, 2, event)" value="30"> / <input type="text" name="soldDte3" id="soldDte3" size="1" maxlength="2" value="'.$year.'"> <a href="#"><img id="date_'.$row[stock].'" src="images/Icons/dateOff.png" onfocus="this.select();lcs(this)" onmouseover="MM_swapImage(\'date_'.$row[stock].'\',\'\',\'images/Icons/dateOn.png\',1)" onmouseout="MM_swapImgRestore()" alt="Choose Date"></a> </li> <li> <label for="salesman">Salesman</label> <select name="salesman" id="salesman"> <option></option> '.$salesmen.' </select> </li> </ul> <ul> <li> <label for="dealType">Deal Type</label> <select name="dealType" class="select-content" onchange="getFile(this.value)"> <option></option> <option value="AL">Auto Loan</option> <option value="Cash">Cash</option> <option value="CAC">Credit Acceptance</option> <option value="IH">In House</option> <option value="SAL">Sensible Auto</option> </select> </li> <li> <label for="tradeDrop">Trade</label> <select name="tradein" id="tradeDrop" onchange="show_hide_trade(this.value);"> <option value="No">No</option> <option value="Yes">Yes</option> </select> </li> </ul> </fieldset> <div id="Bank" class="view">'.$bank.'</div> </form> </div> '; ?> get_Bank.php <? if ($_GET['dealType'] == "AL") { $bank = ' <fieldset id="AL"> <legend>Auto Loan Figures</legend> <ul> <li><label for="price">Price</label><input type="text" name="price" id="price" class="price" size="7" onchange="currency(this)"></li> <li><label for="down">Down</label><input type="text" name="down" id="down" class="price" size="6" onchange="currency(this)"></li> <li><label for="tax">Tax</label><input type="text" name="tax" id="tax" class="price" size="6" onchange="currency(this)"></li> <li><label for="reg">Plates</label><input type="text" name="reg" id="reg" class="price" size="4" onchange="currency(this)"></li> <li><label for="gap">Gap</label><input type="text" name="gap" id="gap" class="price" size="4" onchange="currency(this)"></li> </ul> <ul> <li> <label for="pymtNum">--------------- Payment ---------------</label> <input type="text" name="pymtNum" id="pymtNum" size="3" maxlength="3" onkeyup="return autoTab(this, 3, event)"> @ <input type="text" name="pymtAmnt" id="pymtAmnt" class="price" size="5" onchange="currency(this)"> per <select name="pymtType"> <option value="Weekly" selected="selected">Week</option> <option value="Monthly">Month</option> </select> </li> <li><label for="APR">APR</label><input type="text" name="APR" id="APR" class="rate" size="6" value="19.00"></li> </ul> </fieldset> '; } elseif ($_GET['dealType'] == "CAC") { $bank = ' Credit Acceptance stuff goes here '; } else { $bank = 'You must choose a bank before continuing'; } ?> change-content.js Code: [Select] window.onload = init; // finds all <select> tags will class="select-content" and activates function function init() { var sel = document.getElementsByTagName("select"); for (var i=0; i<sel.length; i++){ if (sel[i].className == "select-content") { sel[i].onchange = getFile; } sel[i].selectedIndex = 0; } } function getFile (url) { var url = "AJAX/get_Bank.php?dealType="+ this.value; if (window.XMLHttpRequest) {xmlhttp=new XMLHttpRequest();} else {xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");} xmlhttp.open("GET",url,false); xmlhttp.send(); // a loop that looks through all <div>s on the page // and then replaces the id with the value and gets that file var divs = document.getElementsByTagName("div"); for (var i=0; i<divs.length; i++) { if(divs[i].id == "bank") { divs[i].id = this.value; divs[i].innerHTML=xmlhttp.responseText; } } } i have a select box and need to change the data with the selection.it is working correctly , my problem is that in the data i have a paging .when we going to next page no data showing . ie select box will not have any value. how to solve this problem. thanks in advance Hi guys, I am after some simple code/tutorial that shows how to make an AJAX/jQuery function to fetch data from a PHP MySQL Database on a timed interval. So far I have not been able to find a simple example of this so if anyone can help out that would be very much appreciated. Cheers in advance. How should I structure XMLHTTPRequests? Should I create a controller called Ajax and post/get all ajax calls through the methods of that controller? What have other people done in the past? What worked best for you? Just thought I would ask as I see that the AJAX help board is something of a ghost town (much like the MS SQL board). Since my post there doas also have some php in it, and I am in no way certain my problem is not in the php could anyone that knows a bit of both please have a look at it he http://www.phpfreaks.com/forums/index.php?topic=343419.0 cheers, just hope this circumvents the double posting rule Pardon my noobness, but I'm learning to wrap AJAX into my work and use it to get XML instead of "static" PHP that generates the HTML. The login/security portion has my head spinning, but it's probably not as difficult as I think and I'm probably just confusing myself. In the past, for each PHP page in my site, I would perform a quick salted login check based on the username/password stored in the $_SESSION variables. Perhaps it was a bit overboard to check on each page, but, well, I did it. With AJAX, I *NEED* to ensure that the php resulting from an AJAX POST request won't run if the user isn't authenticated, and I need to ensure that they didn't just somehow force a $_SESSION variable to reflect an authenticated session. I also need to ensure that someone can't just load up the PHP page on it's own, somehow send a POST to it and run it without being authenticated. I suppose that beyond the larger picture of "How do I ensure that the user is authenticated, the POST request is authentic, and nobody has forced a change in the $_SESSION stored on the server, I have a few specific questions. I know that in part I'm confused about the whole cookie/SESSION process. In my old PHP site, the SESSION number was stored on the cookie on the user's machine. If the info is sent via AJAX, does the PHP get the SESSION info from the cookie or does it have to be explicitly sent? With potentially several users sending AJAX requests at the same time, how will my PHP know which SESSION to use for each request? Is is secure enough to set an "Autheticated" flag in $_SESSION once the user is authenticated the first time? Is it really just as simple as sending a username/salted password hash as AJAX/POST and setting an authenticated flag in the SESSION to ensure that the rest of the AJAX application runs without allowing someone to back-door the PHP? Please help me in this guys....... I am using MVC model for my application . I am stuck with the ajax call. this is my controller application/controller/admin/index.php function getCity() { $city=$this->model->getCity(); foreach($this->city as $key => $value) { echo '<option>'.$value['name'].'</option>' ; } } this is my model application/model/admin_model.php public function getCity() { if($_POST['id']) { $cid=$_POST['id']; $sth = $this->db->prepare('SELECT id, name FROM unit WHERE cid= :cid'); $sth->execute(array(':cid' => $cid)); return $sth->fetchAll(); } } this is my view <form id="city" action="<../application/admin/regstr/" method="post"> Country <select name="country" class="country"> <option value="" selected="selected">--Select Taluka--</option> <option value="1">India</option> <option value="2">USA</option> <option value="3">China</option> </select> City <select name="city" class="city"> <option selected="selected">--Select City--</option> </select> <input type="submit" /> </form> and this is my javascript for Ajax $(document).ready(function() { $(".country").change(function() { var id=$(this).val(); var dataString = 'id='+ id; $.ajax ({ type: "POST", url: "admin/getCity", data: dataString, cache: false, success: function(html) { $(".city").html(html); } }); }); }); But I am not getting the output. I have tested it with firebug in response tab. Instead of getting only option values html code as output I am getting the whole HTML page content (i.e. content of view page admin/index.php. Please help me out. Ok, so I am new to Ajax and am making a forma that will check the user etc. Seems easy, but wow, I'm just lost with all the different things I'm reading, but I know exactly what I want and can easily do it in PHP but of course that is slower and reloads the page. But I am trying to really secure my page so I am stripping everything before it gets to anywhere on my site, even the ajax. So this is what I am doing. My form on index.php Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <script src="js/runonload.js"></script> <script type="text/javascript" src="js/checkcreateuser.js"></script> <link href="css/check.css" media="all" type="text/css" rel="stylesheet"> </head> <body id="mysite"> <form method="post" id="registerForm" name="create_form" action="index.php"> <input type="hidden" name="action" value="create" /> <table width="290px"> <tr> <td align="right"> User Name: </td><td> <input name="usernamecreate" id="usernamecreate" class="sign_up_input_area" type=text value=""> </td> </tr><tr> <td align="right"> Password: </td><td> <input name="passwordcreate" id="passwordcreate" class="sign_up_input_area" type=password value=""> </td> </tr> </table> <input type="submit" class="submitButton2" name="Login" value="Create Account"> <div id="error_log"> <label class="error" for="usernamecreate" id="username_error">Username is required.</label> <label class="error" for="usernamecreate" id="username_error2">Username is already in use.</label> <label class="error" for="passwordcreate" id="password_error">Password is required.</label> </div> Then I want my javascript to work, which does work right now, but only for empty values. I want to be able to compare if the user is in the database and for other PHP functions. Like Would I put this in a seperate checkcreate.php file? Code: [Select] $usernamemain1 = trim($_POST['username']); $usernamemain = stripslashes(strip_tags($usernamemain1)); $usernamecheck = mssql_real_escape_string($usernamemain, $link); $username_lower = strtolower($usernamecheck); $sql = "SELECT LoweredUserName FROM Users where LoweredUserName = '$username_lower'"; $sql_result = mssql_query($sql); $login_row = mssql_fetch_assoc($sql_result); $username = $login_row['LoweredUserName']; $passwordmain1 = trim($_POST['password']); $passwordmain = stripslashes(strip_tags($passwordmain1)); $passwordcheck = mssql_real_escape_string($passwordmain, $link); so I want to be able to use thos evariables in my checkcreateuser.js which is settup like Code: [Select] $(function() { $('.error').hide(); $('input.sign_up_input_area').css({backgroundColor:"#FFFFFF"}); $('input.sign_up_input_area').focus(function(){ $(this).css({backgroundColor:"#FFDDAA"}); }); $('input.sign_up_input_area').blur(function(){ $(this).css({backgroundColor:"#FFFFFF"}); }); $(".submitButton2").click(function() { // validate and process form // first hide any error messages $('.error').hide(); var username = $("input#usernamecreate").val(); if (username == "") { $("label#username_error").show(); $("input#usernamecreate").focus(); return false; } if (<?echo $username_lower?> == "<?echo $username?>") { $("label#username_error2").show(); $("input#usernamecreate").focus(); return false; } var password = $("input#passwordcreate").val(); if (password == "") { $("label#password_error").show(); $("input#passwordcreate").focus(); return false; } var dataString = 'username='+ username + '&password=' + password; //alert (dataString);return false; $.ajax({ type: "POST", url: "", data: dataString, success: function() { $('#contact_form').html("<div id='message'></div>"); $('#message').html("<h2>Form Submitted!</h2>") .hide() .fadeIn(1500, function() { $('#message').append("<img id='checkmark' src='images/check.png' />"); }); } }); return false; }); }); runOnLoad(function(){ $("input#username").select().focus(); }); I can't get the if (<?echo $username_lower?> == "<?echo $username?>") to use variables, of course they aren't seeing any of the variables because I don't know if I put this into a different file, then point my form action to that file and the ajax then sees it run or what? I'm really confused on it all, if anyone can help out that would be great. All the tutorials I keep finding are the same things over and over and don't really help because they always leave out various parts they are using or doing. I understand this much so far tho, but how do I do the variables in ajax when it posts type thing? Thanks!!! |