PHP - Ajax Status Code Problem
I have an AJAX request but my problem is that is always returns a status code of 0. Below I have my JavaScript function. They send a request to a page called inc_submit.php which just echo's "hi" (as I'm just try to test it).
Code: [Select] function submitForm(website_name, website_caption, website_contact, website_email, website_link) { var url4 = "includes/inc_submit.php?website_name=" + escape(website_name) + "&website_caption=" + escape(website_caption) + "&website_contact=" + escape(website_contact) + "&website_email=" + escape(website_email) + "&website_link=" + escape(website_link); alert (url4); request4.open("GET", url4, true); request4.onreadystatechange = confirmSubmit; request4.send(null); } function confirmSubmit() { if (request4.readyState == 4) { if (request4.status == 200) { var response4 = request4.responseText; document.getElementById("submit_status").innerHTML = response4; } else { alert("Error: status code is " + request4.status); } } } Similar TutorialsHello I recently got a "to many connection" error on my site, and want to know if anyone here knows a few codes that will show how many connection currently are in use (maybe even what files that creates them). I found I can use "Threads_connected" to show current open connections, but no info on how to write the code or where to pu the file. I hope you can show my what to do My issue in my php page where i need to show all the news that have the status only active. in my mysql table i have 3 fiels news,posted date and expiry date. on page load i check the status of the news and displays only the active news.For that i am doing the following code,which gives me error. that is on page load, first i select all the news ,update the status inactive for the news which has crossed expiry time i check the status of the news and displays only the active news.For that i am doing the following code,which gives me error. $query1="select time(date_posted),time(expiry_time) from muh_title where status='Active'"; $res=mysql_query($query1); $row=mysql_fetch_row($res); $expiry_time=$row[0];$dateposted=$row[1]; $query11="select addtime(time(date_posted),time(expiry_time)) from muh_title"; $res11=mysql_query($query11); $row11=mysql_fetch_row($res11); $newtime=$row11[0]; $query2="SELECT TIMEDIFF(time(date_posted) ,time(NOW())) FROM muh_title"; $res2=mysql_query($query2); $row2=mysql_fetch_row($res2); $diff=$row2[0]; //while($newtime){ $query5="select *from muh_main_title where date_posted> date_sub(now(),interval (expiry_time) hour-minute )"; //$query3="update muh_title set status='Inactive' "; $res3=mysql_query($query5); } $q="select * from muh_title where status='Active' "; $r= mysql_query($q); $row= mysql_fetch_row($r); echo "<font size='6' color='white'><b><marquee direction='left' loop='-1' align='absmiddle' behaviour='scroll' scrolldelay='90'>$row[1]</marquee></b></font>"; ?> i am sure some where i have lost the flow of code. Hi all! Yet again I have a problem. I really couldn't find what the heck's wrong with this thing. It's extremely simple and still... I'm trying to put a php script in my website to monitor the status of my FTP and HFS servers. Help? <TITLE>Server Status</TITLE> <?php $data .= " </div> <center> <div style=\"border-bottom:1px #999999 solid;width:480;\"><b> <font size='1' color='#3896CC'>Server Status</font></b> </div> </center> <br>"; //configure script $timeout = "1"; //set service checks $port[1] = "80"; $service[1] = "Apache"; $ip[1] = "localhost"; $icon[1] = "habbo.jpg"; $alt[1] = "Apache"; $port[2] = "8080"; $service[2] = "HFS Server"; $ip[2] = "localhost"; $icon[2] = "web.png"; $alt[2] = "HFS Server"; $port[3] = "21"; $service[3] = "FTP Server"; $ip[3] = "localhost"; $icon[3] = "web.png"; $alt[3] = "FTP Server"; // // NO NEED TO EDIT BEYOND HERE // UNLESS YOU WISH TO CHANGE STYLE OF RESULTS // //count arrays $ports = count($port); $ports = $ports + 1; $count = 1; //beggin table for status $data .= "<table width='480' border='1' cellspacing='0' cellpadding='3' style='border-collapse:none' bordercolor='#CCCCCC' align='center'>"; while($count < $ports){ if($ip[$count]==""){ $ip[$count] = "localhost"; } $fp = @fsockopen("$ip[$count]", $port[$count], $errno, $errstr, $timeout); if (!$fp) { $data .= "<tr><td width='18' align='center'><img src='http://127.0.0.1/stat/$icon[$count]' title='$alt[$count]' alt='$alt[$count]'></td><td>$service[$count]</td><td width='18' align='center'><img src='http://127.0.0.1/stat/off.png'></td></tr>"; } else { $data .= "<tr><td width='18' align='center'><img src='http://127.0.0.1/stat/$icon[$count]' title='$alt[$count]' alt='$alt[$count]'></td><td>$service[$count]</td><td width='18' align='center'><img src='http://127.0.0.1/stat/on.png'></td></tr>"; fclose($fp); } $count++; } //close table $data .= "</table><div>"; echo $data; ?> The output of this is... Quote Parse error: syntax error, unexpected T_VARIABLE in D:\Program Files\xampp\xampp\htdocs\stat\server.php on line 18 Also, does somebody have a link or something to a tutorial/pre-made script (although I'd like to follow instructions about it) about server statistics? I want to have data on how much a certain partition on the server has free or full. Thank you in advance. 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; } } } This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=343031.0 Hello everyone, I begin in everything web related but I have been programming for years. I tried to code something simple : small Mysql DB (works fine) and to begin a search bar to browse data. I adapted a code that I understood provided here : https://www.cloudways.com/blog/live-search-php-mysql-ajax/. Base principle is simple : as you type in your query, it will pass the text to script.js that will forward this request to ajax.php file. In the ajax.php, a javascript function named “fill()” will pass the fetched results. This function will also display the result(s) into “display” div in the “search.php” file. The problem is that when I type anything it displays, below the search bar, at the moment I type a character: Quote
'; //Fetching result from database. while ($Result = MySQLi_fetch_array($ExecQuery)) { ?> ")'>
instead of the actual answer from my database (no error in the browser console). I tested the SQL query + the user I provide and everything seems fine. Any clue what could be the root cause ? I strongly suspect a mistake in the code as I already corrected one (script.js instead of scripts.js) but I really cannot figure out where. Thanks in advance,
problematic code (ajax.php):
<?php //Including Database configuration file. include "db.php"; //Getting value of "search" variable from "script.js". if (isset($_POST['search'])) { //Search box value assigning to $Name variable. $Name = $_POST['search']; //Search query. $Query = "SELECT Name FROM search WHERE Name LIKE '%$Name%' LIMIT 5"; //Query execution $ExecQuery = MySQLi_query($con, $Query); //Creating unordered list to display result. echo ' <ul> '; //Fetching result from database. while ($Result = MySQLi_fetch_array($ExecQuery)) { ?> <!-- Creating unordered list items. Calling javascript function named as "fill" found in "script.js" file. By passing fetched result as parameter. --> <li onclick='fill("<?php echo $Result['Name']; ?>")'> <a> <!-- Assigning searched result in "Search box" in "search.php" file. --> <?php echo $Result['Name']; ?> </li></a> <!-- Below php code is just for closing parenthesis. Don't be confused. --> <?php }} ?> </ul>
Just a heads up, my OOP skills are in development so sorry for the roughness of things...(any tips always appreciated!) I'm basically making my own little repository site that will have snippets (for quick copy paste anywhere) (I know there are other services, but mine is a little different and needs to be private). I'll try to just post the necessary code: HTML trying to pass: Code: [Select] <p><br /><span class="something">Hey buddy</span></p> Javascript/JQuery: Code: [Select] //send info $.ajaxFileUpload({ url:'./upload_zip.php', secureuri:false, fileElementId:'form_zip', dataType: 'json', data: {... 'description': htmlEntities($('#modularContent form textarea[name="description"]').val())...}, success:function(data, status){ var html = ... html+= ...'<div class="description"><p>'+data.description+'<br /><br />';... $('#list').append(html); ... $('#modularOverlay,#modularContent').remove(); }, error:function(data, status, e){ alert(e); } ... function htmlEntities(str) { return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); } //found via: http://css-tricks.com/snippets/javascript/htmlentities-for-javascript/ PHP: Code: [Select] <?php //Start object and modify initial values public function __construct($title,$description,$url,$snippet){ ... if($this->snippet == 'yes'){ $this->handle_snippet(); } } public function handle_snippet(){ $code = htmlentities($this->description, ENT_QUOTES | ENT_IGNORE, 'UTF-8',false); $this->description = $code; } //returning value public function getJSON($action){ //temp fix for js breaking if remove_tag_ids is empty/null if(empty($this->remove_tag_ids)){ $this->remove_tag_ids = 'null'; } if($this->snippet == 'yes'){ $this->description = stripslashes($this->description); } switch($action){ case 'delete': //not important default: $json = array(...'description'=>$this->description...); break; return $json; } ?> POST Value: (via firebug) Code: [Select] description: <p><br /><span class="something">Hey buddy</span></p> JSON Return value: (via firebug) Code: [Select] description: <p><br /><span class="something">Hey buddy</span></p> DB value: Code: [Select] <p><br /><span class=\"something\">Hey buddy</span></p> As far as error, I have no idea what the error is haha. It does not get through to the error code cause the plugin tosses an error b4 that (using an ajaxUpload plugin http://www.phpletter.com/Our-Projects/AjaxFileUpload/, (this does not affect the upload, it uploads just fine, but it tosses an error for some reason)). Anyone have any insights/ideas? Thanks for any and all help, Justin All I am trying to do is add a record on a page without the page refreshing. For that ajax is used. Here is the code.
It does not add the record to mysql table. Can anyone tell me what I am doing wrong?
record.php
<!DOCTYPE HTML> <html lang="en"> <head> <script type="text/javascript" src="js/jquery-1.11.0.min.js"></script> <script type="text/javascript" > $(function() { $(".submit_button").click(function() { var textcontent = $("#content").val(); var name = $("#name").val(); var dataString = 'content='+ textcontent + '&name='+name; if(textcontent=='') { alert("Enter some text.."); $("#content").focus(); } else { $("#flash").show(); $("#flash").fadeIn(400).html('<span class="load">Loading..</span>'); $.ajax({ type: "POST", url: "action.php", data: dataString, cache: true, success: function(html){ $("#show").after(html); document.getElementById('content').value=''; $("#flash").hide(); $("#content").focus(); } }); } return false; }); }); </script> </head> <body> <?php $record_id = $_GET['id']; // getting ID of current page record ?> <form action="" method="post" enctype="multipart/form-data"> <div class="field"> <label for="title">Name *</label> <input type="text" name="name" id="name" value="" maxlength="20" placeholder="Your name"> </div> <div class="field"> <label for="content">content *</label> <textarea id="content" name="content" maxlength="500" placeholder="Details..."></textarea> </div> <input type="submit" name="submit" value="submit" class="submit_button"> </form> <div id="flash"></div> <div id="show"></div> </body> </html>action.php if(isset($_POST['submit'])) { if(empty($_POST['name']) || empty($_POST['content'])) { $error = 'Please fill in the required fields!'; } else { try { $name = trim($_POST['name']); $content = trim($_POST['content']); $stmt = $db->prepare("INSERT INTO records(record_id, name, content) VALUES(:recordid, :name, :content"); $stmt->execute(array( 'recordid' => $record_id, 'name' => $name, 'content' => $content )); if(!$stmt){ $error = 'Please fill in the required fields.'; } else { $success = 'Your post has been submitted.'; } } catch(Exception $e) { die($e->getMessage()); } } } Evening fellow freaks I am having a major problem with what I think is quite a simple script, its basically just a ajax same page registration script that is throwing up some php errors. I am not sure if the error lies in the php or js, or both! Ill post the scripts and then explain the problem login.php <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> $(document).ready(function() { //if submit button is clicked $('#signin_submit').click(function () { //Get the data from all the fields var username = $('input[name=username]'); var email = $('input[name=email]'); var password = $('input[name=password]'); //Simple validation to make sure user entered something //If error found, add hightlight class to the text field if (username.val()=='') { name.addClass('hightlight'); return false; } else name.removeClass('hightlight'); if (email.val()=='') { email.addClass('hightlight'); return false; } else email.removeClass('hightlight'); if (password.val()=='') { comment.addClass('hightlight'); return false; } else password.removeClass('hightlight'); //organize the data properly var data = 'username=' + username.val() + '&email=' + email.val() + '&password=' + password.val(); //disabled all the text fields $('.text').attr('disabled','true'); //show the loading sign $('.loading').show(); //start the ajax $.ajax({ //this is the php file that processes the data and send mail url: "processreg.php", //GET method is used type: "GET", //pass the data data: data, //Do not cache the page cache: false, //success success: function (html) { //if process.php returned 1/true (send mail success) if (html==1) { //hide the form $('.form').fadeOut('slow'); //show the success message $('.done').fadeIn('slow'); //if process.php returned 0/false (send mail failed) } else alert('Sorry, unexpected error. Please try again later.'); } }); //cancel the submit button default behaviours return false; }); }); </script> <div id="logincontainer"> <div id="topnav" class="topnav"> <a href="login" class="login"><span>Register</span></a> <a href="login" class="signin"><span>Log In</span></a> </div> <fieldset id="signin_menu"> <form method="post" id="signin" action=""> <label for="username">Username</label> <input id="username" name="username" value="" title="username" tabindex="4" type="text"> <br> <label for="password">Password</label> <input id="password" name="password" value="" title="password" tabindex="5" type="password"> <p class="remember"> <input id="signin_submit" value="Sign in" tabindex="6" type="submit"> <input id="remember" name="remember_me" value="1" tabindex="7" type="checkbox"> <label for="remember">Remember me</label> </p> <p class="forgot"> <a href="#" id="resend_password_link">Forgot your password?</a> </p> <p class="forgot-username"> <A id=forgot_username_link title="If you remember your password, try logging in with your email" href="#">Forgot your username?</A> </p> </form> </fieldset> <fieldset id="login_menu"> <form method="post" id="login" action="processreg.php"> <label for="username">Username</label> <input id="username" name="username" title="username" type="text"> <br> <label for="email">Email</label> <input id="email" name="email" title="email" type="text"><br> <label for="password">Password</label> <input id="password" name="password" title="password" type="password"> <input id="submit" value="Register" type="submit"> </p> </form> </fieldset> <div class="loading"></div> <div class="done"> <b>Thank you for joining!</b> You can now login. </div> </div> <script type="text/javascript"> $(document).ready(function() { $(".signin").click(function(e) { e.preventDefault(); $("fieldset#signin_menu").toggle(); $(".signin").toggleClass("menu-open"); }); $("fieldset#signin_menu").mouseup(function() { return false }); $(document).mouseup(function(e) { if($(e.target).parent("a.signin").length==0) { $(".signin").removeClass("menu-open"); $("fieldset#signin_menu").hide(); } }); }); $(document).ready(function() { $(".login").click(function(e) { e.preventDefault(); $("fieldset#login_menu").toggle(); $(".login").toggleClass("menu-open"); }); $("fieldset#login_menu").mouseup(function() { return false }); $(document).mouseup(function(e) { if($(e.target).parent("a.login").length==0) { $(".login").removeClass("menu-open"); $("fieldset#login_menu").hide(); } }); }); </script> <script src="javascripts/jquery.tipsy.js" type="text/javascript"></script> <script type='text/javascript'> $(function() { $('#forgot_username_link').tipsy({gravity: 'w'}); }); </script> and processreg.php <?php include('connect.php'); //Retrieve form data. //GET - user submitted data using AJAX //POST - in case user does not support javascript, we'll use POST instead $username = ($_GET['username']) ? $_GET['username'] : $_POST['username']; $email = ($_GET['email']) ?$_GET['email'] : $_POST['email']; $password = ($_GET['password']) ?$_GET['password'] : $_POST['password']; //flag to indicate which method it uses. If POST set it to 1 if ($_POST) $post=1; //Simple server side validation for POST data, of course, you should validate the email if (!$username) $errors[count($errors)] = 'Please enter your name.'; if (!$email) $errors[count($errors)] = 'Please enter your email.'; if (!$password) $errors[count($errors)] = 'Please enter your required password.'; //if the errors array is empty, send the mail if (!$errors) { $newpassword= md5($password); $result="INSERT INTO userbase (username, email, password) VALUES ('$username','$email','$newpassword')"; //if POST was used, display the message straight away if ($_POST) { if (!mysql_query($result)) echo 'Thank you! We have received your message.'; else echo 'Sorry, unexpected error. Please try again later'; //else if GET was used, return the boolean value so that //ajax script can react accordingly //1 means success, 0 means failed } else { echo $result; } //if the errors array has values } else { //display the errors message for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>'; exit; } ?> The output errors Quote Notice: Undefined index: username in C:\wamp\www\buy2earn\processreg.php on line 7 Notice: Undefined index: email in C:\wamp\www\buy2earn\processreg.php on line 8 Notice: Undefined index: password in C:\wamp\www\buy2earn\processreg.php on line 9 Notice: Undefined variable: errors in C:\wamp\www\buy2earn\processreg.php on line 21 Thank you! We have received your message. Now this is basic basic errors, which I know normally means I have named my form inputs different to the processing script, but in this case they are correct. I am using the second form in the login script which is this one: Code: [Select] <form method="post" id="login" action="processreg.php"> <label for="username">Username</label> <input id="username" name="username" title="username" type="text"> <br> <label for="email">Email</label> <input id="email" name="email" title="email" type="text"><br> <label for="password">Password</label> <input id="password" name="password" title="password" type="password"> <input id="submit" value="Register" type="submit"> Can anyone explain what's the problem? My js skills are non existent so this came from my collection of saved rar files with no explanations and some very basic editing! Many Thanks The Ajax Code: Code: [Select] <script language="javascript" type="text/javascript"> <!-- //Browser Support Code function ajaxFunction(){ var ajaxRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ var ajaxDisplay = document.getElementById('ajaxDiv'); ajaxDisplay.innerHTML = ajaxRequest.responseText; } } var pic = document.getElementById('pic').value; var queryString = "?pic=" + pic; ajaxRequest.open("GET", "ajax-example.php" + queryString, true); ajaxRequest.send(null); } //--> </script> The PHP code: Code: [Select] <?php require_once("configure.php"); mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database" . mysql_error()); @mysql_select_db("$DBName") or die("Unable to select database $DBName" . mysql_error() ); $user_sqla = "select * from $emaila " ; while($user_array = mysql_fetch_array($user_resulta)) { $pictures = $user_array[picture]; ?> <form name='myForm'> <?php echo "<div align='left' style='padding-left:25px'><table border='1'><tr><td><img src=".$pictures." width='65' height='65'><input type='hidden' name='pic' id='pic' value=".$pictures.">". $pictures;?></td> <td><div style="padding-left:5px; padding-top:15px"><?php echo "<a href='#' onclick='ajaxFunction()' >Remove</a></td></tr></table></div>"; ?></div> </form><?php } ?> the ajax-example.php code: Code: [Select] <?php // Retrieve data from Query String $age = $_GET['pic']; echo $age; ?> Now the Php code gives the following result: "image1" "Remove" "image2" "Remove" "image3" "Remove" when I click the "Remove" the result I keep getting is "image1" even if I click the remove beside image3 I still get the Image1 Name transffered from my ajax code to the ajax-example.php page This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=332473.0 I'm trying to upload a file using ajax, but I have some problems. First I'll show the code : HTML Code: [Select] <form id="foto" action="index.php?action=send" method="post" enctype="multipart/form-data"> <fieldset> <label>Kleur</label> <input id="Binded" type="text" value="ffffff" /> <br /> <label>Upload foto</label> <input id="file" type="file" name="upload" id="upload"/> <a href="index.php?action=foto" id="uploaden">uploaden</a> </fieldset> <fieldset id="audioplayer"> <h3>Kies een soundtrack</h3> <ol id="lijst"> <li id="een" class="active"><a href="assets/audio/Gayla_Peevey-I_Want_a_Hippopotamus_For_Christmas.mp3">Gayla Peevey - I Want a Hippopotamus For Christmas</a> <img class="mute" src="assets/images/mute.png" width="30" height="30" alt="mute"/></li> <li id="twee"><a href="assets/audio/SouthFamilyXmas2005-NuttinForChristmas.mp3">South Family - Nuttin for Christmas</a> <img class="mute" src="assets/images/mute.png" width="30" height="30" alt="mute"/></li> <li id="drie"><a href="assets/audio/southpark_merry_christmas.mp3">South Park - Merry Christmas</a> <img class="mute" src="assets/images/mute.png" width="30" height="30" alt="mute"/></li> </li> </ol> <audio id="audio" preload="auto" autobuffer autoplay src="assets/audio/Gayla Peevey - I Want a Hippopotamus For Christmas.mp3"> </audio> </fieldset> <fieldset id="emailen"> <h3>Email een vriend</h3> <br /> <input type="email" name="email" placeholder="Email" required="true" /> <input type="submit" name="verstuur" id="verstuur" value="Verstuur" /> </fieldset> </form> PHP Code: [Select] function getAjaxContent(){ global $smarty; $dir = "uploads"; $tempdir = $_FILES['upload']["tmp_name"]; $realdir = $dir."/".$_FILES["upload"]["name"]; //$fotoTonen = '<img src="'.$realdir.'" alt="foto upload">'; //$toonFoto = true; if(!is_dir($dir)){ mkdir($dir); } move_uploaded_file($tempdir, $realdir); var_dump($_FILES); return $smarty->fetch('kaart-ajax.htm'); }Here I get the error <b>Notice</b>: Undefined index: upload in <b>/Applications/MAMP/htdocs/2011-2012/kerstkaart/includes/index.php</b> on line <b>16</b><br /> and the var_dump gives an empty array AJAX Code: [Select] $('input[name=foto]').change(function(event){ $.ajax({ url:"index.php?action=foto", data: $('input[type=file]').val(), type: "POST", timeout: 3000, error: function(jqXHR, textStatus,errorThrown){ alert("probleem met ajax "+textStatus); }, success: function(data, textStatus, jqXHR){ alert("jaja "+data); canvas.width = canvas.width; context.drawImage(image, 0, 0); image.src = 'uploads/'+data; } }); event.preventDefault(); }); What I try to do here is getting the value of the selected file and redraw my canvas ( HTML5 ) so that the chosen pic is the background. The file i upload to test is a gif of 4KB, so not that big. Can anyone help me with this confusing problem ? Thanks, Hello, First of all ,I have been a regular reader of the forum and it has increased my knowledge in the PHP a lot. Till now i had just been a guest user and used to go through the queries and tips posted here. Today , for the first time i am posting on the forum Coming to a problem: I have to design a function for a client from travel domain. Where he wants the script/function to go and extract data from an airline website on the available fare for a specific date and destination. The problem is that only a part of fare(Base fare) is visible on the site and you have to select one of the given flight option(s) (after selecting the option through AJAX the full fare is displayed on the same page on the left hand site) to get the complete fare including fare and surcharges. Now i want my function/script to extract the full fare for all the available flight options. I have written the below piece of code. But its not efffective as it gets only the base fare part of the result page and not the complete fare.. The airline booking url is : http://book.spicejet.com/skylights/cgi-bin/skylights.cgi My code: //---- Spicejet start // ENGINE URL http://book.spicejet.com/skylights/cgi-bin/skylights.cgi?page=homecomp //Taking some sample search data - just to test the script $event="search" ; $module="SB" ; $page="SEARCH" ; $mode="empty" ; $travel="1" ; // ONE WAY OR 2 WAY $from1="HYD" ; $to1="DEL" ; $departDay1="13" ; $departDay2=""; $departMonth1="201010" ; $ADULT="1" ; $CHILD="0" ; $INFANT="0" ; $toCity1="DEL" ; $numberMarkets="1" ; // the page needs data in POST form $curlPost = 'event=' . urlencode($event) . '&module=' . urlencode($module) .'&page=' . urlencode($page) .'&mode=' . urlencode($mode) .'&travel=' . urlencode($travel) .'&from1=' . urlencode($from1) .'&to1=' . urlencode($to1) .'&departDay1=' . urlencode($departDay1) .'&departMonth1=' . urlencode($departMonth1) .'&ADULT=' . urlencode($ADULT) .'&CHILD=' . urlencode($CHILD) .'&INFANT=' . urlencode($INFANT) .'&toCity1=' . urlencode($toCity1) .'&numberMarkets=' . urlencode($numberMarkets).'&submitSearch=submitSearch'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://book.spicejet.com/skylights/cgi-bin/skylights.cgi'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 2.0.50727; .NET CLR 1.1.4322)"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost); $data = curl_exec($ch); curl_close($ch); echo($data); Also one more query Is there something like beautiful soup (As in Python) to parse the data. I want to extract the flight timing and total price from the page and insert into a database. Thanxs in advance Hi, Using arabic characters, I have a project, in the admin panel, where i am trying to change the value in the text box(ajax) on onblur js function. Firefox simply working great but i am getting square brackets in the text box in the browser ie. I simply guessing the value from the text box is not in the form of utf-8 encoding, i am calling the external javascript file, this is the code am using.. Code: [Select] // JavaScript Document var xmlhttp; //function namechange(name_fieldvalue) function namechange(name_fieldvalue,name_fieldname,id_val,id_fieldname,table_name) { /* alert(name_fieldvalue); alert(name_fieldname); alert(id_val); alert(id_fieldname); alert(table_name); */ if (name_fieldvalue.length==0) { document.getElementById("txtHint").innerHTML=""; return; } xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Your browser does not support XMLHTTP!"); return; } var url="ajax_namechange.php"; url=url+"?name_fieldvalue="+name_fieldvalue; url=url+"&name_fieldname="+name_fieldname; url=url+"&id_val="+id_val; url=url+"&id_fieldname="+id_fieldname; url=url+"&table_name="+table_name; xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function stateChanged() { if (xmlhttp.readyState==4) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } Anyone has the idea on this, please help me. Thanks, This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=315198.0 Hello, I am trying to implement some code I found and downloaded he http://www.roscripts.com/Ajax_autosuggest_autocomplete_from_database-154.html When I try and run this I get no search results back when searching? I have entered data in the database and all connections seem good. Several people in the comments say they have problems, but no solution. Any one that can find the fault here? - THANKS <?php require_once('db.php'); include('classes/stem.php'); include('classes/cleaner.php'); if( !empty ( $_POST['search'] ) ): $string = $_POST['search']; $main_url = 'http://www.roscripts.com/'; $stemmer = new Stemmer; $stemmed_string = $stemmer->stem ( $string ); $clean_string = new jSearchString(); $stemmed_string = $clean_string->parseString ( $stemmed_string ); $new_string = ''; foreach ( array_unique ( split ( " ",$stemmed_string ) ) as $array => $value ) { if(strlen($value) >= 3) { $new_string .= ''.$value.' '; } } $new_string = substr ( $new_string,0, ( strLen ( $new_string ) -1 ) ); if ( strlen ( $new_string ) > 3 ): $split_stemmed = split ( " ",$new_string ); mysql_select_db($database); $sql = "SELECT DISTINCT COUNT(*) as occurences, title, subtitle FROM articles WHERE ("; while ( list ( $key,$val ) = each ( $split_stemmed ) ) { if( $val!='' && strlen ( $val ) > 0 ) { $sql .= "((title LIKE '%".$val."%' OR subtitle LIKE '%".$val."%' OR content LIKE '%".$val."%')) OR"; } } $sql=substr ( $sql,0, ( strLen ( $sql )-3 ) );//this will eat the last OR $sql .= ") GROUP BY title ORDER BY occurences DESC LIMIT 10"; $query = mysql_query($sql) or die ( mysql_error () ); $row_sql = mysql_fetch_assoc ( $query ); $total = mysql_num_rows ( $query ); if($total>0): echo ' <div class="entry">'."\n"; echo ' <ul>'."\n"; while ( $row = mysql_fetch_assoc ( $query ) ) { echo ' <li>'."\n"; echo ' <a href="'.$main_url.'articles/show/'.$row['id'].'">'.$row['title'].''."\n"; echo ' <em>'.$row['subtitle'].'</em>'."\n"; echo ' <span>Added on 2007-06-03 by roScripts</span></a>'."\n"; echo ' </li>'."\n"; } echo ' </ul>'."\n"; echo ' </div>'."\n"; endif; endif; endif; ?> The code can be found in attached zip file. Hi... I have a problemand I tried to resolved it but still I failed.. I need to add a code in a php file where I'm not the one who code, now I need to add code on that file, and the problem is the one who the owner of code is not here. I need to add code : Code: [Select] $sub_lotcode = substr($lotCode, 9, 4); $sql = "SELECT k.PCODE, k.kanban, p.Compounds, p.Max_Lot FROM kanban_checker k, param_settings p WHERE k.kanban = p.Max_Lot AND k.PCODE = '$sub_lotcode' AND p.Compounds = '$sub_lotcode'"; $result = mysql_query($sql, $con); $total = mysql_num_rows($result); if ($total <= 0) { notify that PCODE reach the maximum } else{ echo "continue"; } here is the code where I need to add this condition: Code: [Select] <?php error_reporting(0); $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); $lotCode = mysql_real_escape_string($_GET['normal']); $lotCodeDownGrade = mysql_real_escape_string($_GET['downgrade']); $terminalNo = mysql_real_escape_string($_GET['n']); $downMode = mysql_real_escape_string($_GET['down']); //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> if ($terminalNo == "1") { if ($lotCode != "") { $sql = "SELECT BARCODE FROM LEGALCODES WHERE BARCODE='$lotCode'"; $result = mysql_query($sql, $con); $total = mysql_num_rows($result); if ($total <= 0) { echo "X"; // X - for non existent in the mes table } else { //do this if code exist in the database: // //code exist in the database $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND TERMINAL_ID='1' AND ACTIVE=TRUE"; $result = mysql_query($sql, $con); $total = mysql_num_rows($result); if ($total <= 0) { echo "0"; // continue to transact } else { // query the last terminal it was used $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND ACTIVE=TRUE ORDER BY DATE_ENTRY DESC LIMIT 1"; $result = mysql_query($sql, $con); $row = mysql_fetch_array($result); $total = mysql_num_rows($result); echo $row['TERMINAL_ID'] ; // already used here - me nakita // GET THE LAST TERMINAL NUMBER ACTIVE ADD 1 HERE TO DISPLAY WHICH TERMINAL TO GO } } } } //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> elseif ($terminalNo == "4") { if ($lotCode != "") { $sql = "SELECT BARCODE FROM LEGALCODES WHERE BARCODE='$lotCode'"; $result = mysql_query($sql, $con); $total = mysql_num_rows($result); if ($total <= 0) { echo "X"; // X - for non existent in the mes table } else { //if downgrade is checked do this : if ($downMode == "true") { $advanceTerminal = ((integer)($terminalNo) + 1); $advanceTerminal = (string)($advanceTerminal); $preTerminal = ((integer)($terminalNo) - 1); $preTerminal = (string)($preTerminal); //query if the lot code exist in advance terminal .. $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND TERMINAL_ID='$advanceTerminal' AND ACTIVE=TRUE"; $result = mysql_query($sql, $con); $total = mysql_num_rows($result); if ($total <= 0) { // check naman kung wala sa naunang terminal $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND TERMINAL_ID='$preTerminal' AND ACTIVE=TRUE"; $result = mysql_query($sql, $con); $total = mysql_num_rows($result); if ($total <= 0) { $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND ACTIVE= TRUE ORDER BY TERMINAL_ID DESC LIMIT 1"; $result = mysql_query($sql, $con); $row = mysql_fetch_array($result); $total = mysql_num_rows($result); if ($total <= 0) { // NO RECORDS FOUND GO TO TERMINAL 1 == optional echo "notran"; } else { echo $row['TERMINAL_ID'] ; } } else { $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND TERMINAL_ID='$terminalNo' AND ACTIVE=TRUE"; $result = mysql_query($sql, $con); $total = mysql_num_rows($result); if ($total <= 0 || $total >= 0) { echo "G"; } } } else { $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND ACTIVE= TRUE ORDER BY TERMINAL_ID DESC LIMIT 1"; $result = mysql_query($sql, $con); $row = mysql_fetch_array($result); $total = mysql_num_rows($result); echo $row['TERMINAL_ID'] ; } } else { //query if the lot code exist in this terminal .. $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND TERMINAL_ID='$terminalNo' AND ACTIVE=TRUE"; $result = mysql_query($sql, $con); $total = mysql_num_rows($result); if ($total <= 0) { // wala nakita - then tsek if nag exist sa terminal na sinundan $preTerminal = ((integer)($terminalNo) - 1); $preTerminal = (string)($preTerminal); //then tsek if nag exist sa terminal na sinundan $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND TERMINAL_ID='$preTerminal' AND ACTIVE=TRUE"; $result = mysql_query($sql, $con); $total = mysql_num_rows($result); if ($total <= 0) { // walang nakita sa mga naunang terminal // do this if no previous transaction with pre requisite process // query the last terminal it was used $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND ACTIVE= TRUE ORDER BY TERMINAL_ID DESC LIMIT 1"; $result = mysql_query($sql, $con); $row = mysql_fetch_array($result); $total = mysql_num_rows($result); // $row = mysql_fetch_array($result); if ($total <= 0) { // NO RECORDS FOUND GO TO TERMINAL 1 == optional echo "notran"; } else { echo $row['TERMINAL_ID']; // GET THE LAST TERMINAL NUMBER ACTIVE ADD 1 HERE TO DISPLAY WHICH TERMINAL TO GO } } else { echo "G"; } } else { //me record na nakita sa terminal na pinag transakan // query the last terminal it was used $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND ACTIVE=TRUE ORDER BY TERMINAL_ID DESC LIMIT 1"; $result = mysql_query($sql, $con); $row = mysql_fetch_array($result); $total = mysql_num_rows($result); echo $row['TERMINAL_ID'] ; // already used here - me nakita // GET THE LAST TERMINAL NUMBER ACTIVE ADD 1 HERE TO DISPLAY WHICH TERMINAL TO GO } } // here is the terminator of else in downgrade } } //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> if ($lotCodeDownGrade != "") { $sql = "SELECT BARCODE FROM LEGALCODES WHERE BARCODE='$lotCodeDownGrade'"; $result = mysql_query($sql, $con); $total = mysql_num_rows($result); if ($total <= 0) { echo "X"; // X - for non existent in the mes table } else { //do this if code exist in the database: // //code exist in the database $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCodeDownGrade' AND ACTIVE=TRUE"; $result = mysql_query($sql, $con); $total = mysql_num_rows($result); if ($total <= 0) { echo "0"; // continue to transact } else { // query the last terminal it was used $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCodeDownGrade' AND ACTIVE=TRUE ORDER BY TERMINAL_ID DESC LIMIT 1"; $result = mysql_query($sql, $con); $row = mysql_fetch_array($result); $total = mysql_num_rows($result); echo $row['TERMINAL_ID'] ; // already used here - me nakita // GET THE LAST TERMINAL NUMBER ACTIVE ADD 1 HERE TO DISPLAY WHICH TERMINAL TO GO } } } } //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> else { if ($lotCode != "") { $sql = "SELECT BARCODE FROM LEGALCODES WHERE BARCODE='$lotCode'"; $result = mysql_query($sql, $con); $total = mysql_num_rows($result); if ($total <= 0) { echo "X"; // X - for non existent in the mes table } else { //query if the lot code exist in this terminal .. $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND TERMINAL_ID='$terminalNo' AND ACTIVE=TRUE"; $result = mysql_query($sql, $con); $total = mysql_num_rows($result); if ($total <= 0) { // wala nakita - then tsek if nag exist sa terminal na sinundan $preTerminal = ((integer)($terminalNo) - 1); $preTerminal = (string)($preTerminal); //then tsek if nag exist sa terminal na sinundan $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND TERMINAL_ID='$preTerminal' AND ACTIVE=TRUE"; $result = mysql_query($sql, $con); $total = mysql_num_rows($result); if ($total <= 0) { // walang nakita sa mga naunang terminal // do this if no previous transaction with pre requisite process // query the last terminal it was used $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND ACTIVE=TRUE ORDER BY TERMINAL_ID DESC LIMIT 1"; $result = mysql_query($sql, $con); $row = mysql_fetch_array($result); $total = mysql_num_rows($result); if ($total <= 0) { // NO RECORDS FOUND GO TO TERMINAL 1 == optional echo "notran"; } else { echo $row['TERMINAL_ID']; // GET THE LAST TERMINAL NUMBER ACTIVE ADD 1 HERE TO DISPLAY WHICH TERMINAL TO GO } } else { echo "G"; } } else { //me record na nakita sa terminal na pinag transakan // query the last terminal it was used $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND ACTIVE= TRUE ORDER BY TERMINAL_ID DESC LIMIT 1"; $result = mysql_query($sql, $con); $row = mysql_fetch_array($result); $total = mysql_num_rows($result); echo $row['TERMINAL_ID'] ; // already used here - me nakita // GET THE LAST TERMINAL NUMBER ACTIVE ADD 1 HERE TO DISPLAY WHICH TERMINAL TO GO } } } } mysql_close($con); ?> Code: [Select] function unUsedLotId(txtElemID){ var txtElemID_Active = txtElemID; //alert("VV" + txtElemID_Active.value + "VV" ); responsePHP = "no_reply"; changeFocus = false; var termNo = terminalNo(); ajaxRequest = remoteRequestObject(); ajaxRequest.onreadystatechange = function(){ if (ajaxRequest.readyState==4 && ajaxRequest.status==200) { // var result = ajaxRequest.responseText; responsePHP = ajaxRequest.responseText; //alert(responsePHP) // if (result=="1") { result = "Already used Tag";} // if (result=="0") { result = "Tag ok";} // if (result=="G") { result = "Tag ok";} // if (result=="B") { result = "Incomplete Process";} // var resultStr = (result=="1") ? 'Tag used or incomplete prerequisites' : 'Tag unused'; if (responsePHP == "failed") { txtElemID_Active.disabled = false; txtElemID_Active.value = ""; txtElemID_Active.focus(); notify("Report to MIS<br /> Please scan again."); } //------------------------------added by rhoda for integration-------------------------------------------------- /* else if (responsePHP == "C"){ notify("CCCC"); if (txtElemID_Active.disabled) { txtElemID_Active.disabled = false; } txtElemID_Active.value = ""; txtElemID_Active.focus(); } */ //-------------------------------------------------------------------------------- else if (responsePHP == "X") { //result = "Lot ID invalid."; //responsePHP = "Lot ID invalid."; notify("Lot ID invalid. Scan Again."); if (txtElemID_Active.disabled) { txtElemID_Active.disabled = false; } txtElemID_Active.value = ""; txtElemID_Active.focus(); } //-------------------------------------------------------------------------------- else if (responsePHP =="0" || responsePHP =="G"){ if (txtElemID_Name == "txtLotCode") { window.LotID = (txtElemID_Active.value) } if (txtElemID_Name == "txtLotCodeDownGrade") { window.LotID_Down = (txtElemID_Active.value) } strip(txtElemID_Active) if (termNo == "1") { isSelected('txtLotCode', 'selWeight_MachineID'); } if (termNo == "2" || termNo == "3") { isSelected('txtLotCode', 'txtKitWeight'); } if (termNo == "4" || termNo == "5" || termNo == "6" || termNo == "7") { //////////////////////////////// downgrade modification /////////////////////////////////////// if (termNo == "4") { //alert(termNo) var chkDownGrade = document.getElementById('chkDownGrade') if (chkDownGrade.checked == 1) { //alert("here") if (txtElemID_Name == 'txtLotCode') { isSelected('txtLotCode', 'txtLotCodeDownGrade'); } if (txtElemID_Name == 'txtLotCodeDownGrade') { isSelected('txtLotCodeDownGrade', 'selMachineID'); } } else { //alert("here") if (txtElemID_Name == 'txtLotCode') { isSelected('txtLotCode', 'selMachineID'); } } } else { isSelected('txtLotCode', 'selMachineID'); } //////////////////////////////////////////////////////////////////////////////////////// } if (document.getElementById('notice')!== null) { document.getElementsByTagName('body')[0].removeChild(document.getElementById('notice')) //>> clear the box } } //-------------------------------------------------------------------------------- else if (responsePHP == "notran") { var mensahe1 = "Please return to<br /><span style='font-size:30px;'>Chemical Weighing<br /> or Supervisor</span>"; notify(mensahe1); if (txtElemID_Active.disabled) { txtElemID_Active.disabled = false; } txtElemID_Active.value = ""; txtElemID_Active.focus(); } //-------------------------------------------------------------------------------- else { /* responsePHP == "1" || responsePHP == "B") { do this if tag is used in this terminal if (responsePHP == "1") { result = "Already used Lot ID"; responsePHP = "Already used Lot ID"; notify("Already used Lot ID.<br />Scan again."); } else if (responsePHP == "B") { // result = "Incomplete Transaction Process"; // responsePHP = "Incomplete Transaction Process"; notify("Incomplete Transaction Process.<br />Scan again."); } */ var mensahe1 = "Last Process: <span style='font-size:30px;'> Terminal " + responsePHP + "</span><br /><br />"; var mensahe2 = "Pls. Proceed: <span style='font-size:30px;'> Terminal " + (parseInt(responsePHP) + 1) + "</span>"; notify(mensahe1 + mensahe2); // notify("Incomplete Transaction Process.<br />Scan again."); if (txtElemID_Active.disabled) { txtElemID_Active.disabled = false; } txtElemID_Active.value = ""; txtElemID_Active.focus(); } //-------------------------------------------------------------------------------- } } var txtElemID_Name = txtElemID_Active.id; if (termNo == "4") { var downGrade = document.getElementById('chkDownGrade').checked; var str = txtElemID_Active.value + "&n=" + termNo + "&down=" + downGrade; } else { var str = txtElemID_Active.value + "&n=" + termNo; } if (txtElemID_Name == "txtLotCode") { //alert(txtElemID_Name) var url = "verifyLotId.php?normal=" + str; } if (txtElemID_Name == "txtLotCodeDownGrade") { //alert(txtElemID_Name) var url = "verifyLotId.php?downgrade=" + str; } ajaxRequest.open("GET", url, true); // force i.e. not to cache ajaxRequest.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"); //-------------------------------------------------- ajaxRequest.send(null); ajaxTimeOut = window.setTimeout("timeOut('" + txtElemID_Name + "');", 6000); } 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. Problem: I'm trying to make it so the array responds to the integer of status in the database. So, to check if it's one, I try this: $get["status"]["1"] = "Message here..."; But, on my result, I'm just getting WWTT - And the value in the database for the ticket is 0. I'm not sure if I'm using the array correctly. My full code: <?php session_start(); include("../includes/mysql.php"); include("../includes/config.php"); ?> <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="../style.css" rel="stylesheet" type="text/css" /> <title><?php echo $title; ?></title> </head> <body> <div id="container"> <div id="content"> <div id="left"> <div class="menu"> <?php include("../includes/navigation.php"); ?> <div class="menufooter"></div> </div> <?php include("../includes/menu.php"); ?> </div> <div id="middle"> <?php $existing = $_POST['existing']; $query = mysql_query("SELECT COUNT(id),id,status,date,question,title FROM tickets WHERE id='$existing'"); $get = mysql_fetch_assoc($query); if(!$existing) { echo ' <div class="post"> <div class="postheader"><h1>Error</h1></div> <div class="postcontent"> <p>You have not enetered in a ticket ID. Please go back and do so.</p> </div> <div class="postfooter"></div> </div> '; } elseif($get['COUNT(id)'] < 1) { echo ' <div class="post"> <div class="postheader"><h1>Error</h1></div> <div class="postcontent"> <p>The ticket ID you are trying to use doesnt exist. Please go back or submit another ticket.</p> </div> <div class="postfooter"></div> </div> '; } else { $get["status"]["0"] = "Waiting for support..."; $get["status"]["1"] = "Waiting for user..."; $get["status"]["2"] = "Ticket Closed..."; $get["status"]["3"] = "Ticket Opened..."; echo ' <div class="post"> <div class="postheader"><h1>View Ticket Status - ID '. $get["id"] .'</h1></div> <div class="postcontent"> <p>Title: '. $get["title"] .' - Posted on: '. $get["date"] .'</p> <p>Ticket Status: '. $get["status"] .'</p> <p>Question: '. nl2br($get["question"]) .'</p> </div> <div class="postfooter"></div> </div> '; } ?> </div> </div> </div> </body> </html> Hi there, i have code that enables a user to login to my site. I have a player table that consists of: PlayerName, Password and Status. The playername and password is what logs the user in however i want to make it so that when a user logs in it automatically sets that users Status to 1. Can some one point me in the right direction please?? Thanks Code: [Select] <?php if (!isset($_SESSION)) { session_start(); } $loginFormAction = $_SERVER['PHP_SELF']; if (isset($_GET['accesscheck'])) { $_SESSION['PrevUrl'] = $_GET['accesscheck']; } if (isset($_POST['textfield'])) { $loginUsername=$_POST['textfield']; $password=$_POST['textfield2']; $MM_fldUserAuthorization = ""; $MM_redirectLoginSuccess = "index.php"; $MM_redirectLoginFailed = "fail.php"; $MM_redirecttoReferrer = false; mysql_select_db($database_swb, $swb); $LoginRS__query=sprintf("SELECT PlayerName, Password FROM player WHERE PlayerName=%s AND Password=%s", GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); $LoginRS = mysql_query($LoginRS__query, $swb) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = ""; //declare two session variables and assign them $_SESSION['MM_Username'] = $loginUsername; $_SESSION['MM_UserGroup'] = $loginStrGroup; if (isset($_SESSION['PrevUrl']) && false) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); } } ?> Thank you |