Goins Posted March 18, 2008 Share Posted March 18, 2008 Hey im using Ajax and Php To Insert Data Into the database. Can Someone Please CHeck my Code! Also Check The Php Cause Im not 100% Good At it. I keep just getting Just a second... In the Response Div Lol. Html <form action="javascript:insert()" method="post"> <input name="keyword" type="text" id="keyword" value=""/> <input name="name" type="text" id="name" value="<# FILENAME #>"/> <input type="submit" name="Submit" value="Insert"/> <div id="insert_response"></div> The <# FILENAME #> Is a template System It Pull The file name From the Database. Ajax.js /* ---------------------------- */ /* XMLHTTPRequest Enable */ /* ---------------------------- */ function createObject() { var request_type; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer"){ request_type = new ActiveXObject("Microsoft.XMLHTTP"); }else{ request_type = new XMLHttpRequest(); } return request_type; } var http = createObject(); /* -------------------------- */ /* INSERT */ /* -------------------------- */ /* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */ var nocache = 0; function insert() { // Optional: Show a waiting message in the layer with ID login_response document.getElementById('insert_response').innerHTML = "Just a second..." // Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding. var keyword= encodeURI(document.getElementById('keyword').value); var name = encodeURI(document.getElementById('name').value); // Set te random number to add to URL request nocache = Math.random(); // Pass the login variables like URL variable http.open('get', 'insert.php?site_url='+site_url+'&name=' +name+'&nocache = '+nocache); http.onreadystatechange = insertReply; http.send(null); } function insertReply() { if(http.readyState == 4){ var response = http.responseText; // else if login is ok show a message: "Keyword added". document.getElementById('insert_response').innerHTML = 'Keyword added:'+response; } } And Php <?php // ======================================== \ // Package: Mihalism Multi Host // Version: 4.0.0 // Copyright (c) 2007, 2008 Mihalism, Inc. // License: http://www.gnu.org/licenses/gpl.txt GNU Public License // ======================================== / require_once "./source/includes/data.php"; if(isset($_GET['keywordl']) && isset($_GET['name'])){ $keyword= $_GET['keyword']; $name= $_GET['name']; $insertKeyword_sql = "UPDATE `mmh_file_storage` SET `keyword` = '{$keyword}' WHERE `filename` = '{$name}'"; $insertKeyword= mysql_query($insertKeyword_sql) or die(mysql_error()); echo $keyword; } else { echo 'Error! Please fill all fileds!'; } ?> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted March 18, 2008 Share Posted March 18, 2008 This is more of a javascript/ajax issue rather than a PHP issue. You might have more luck posting in the correct forum. I can't see anything immediately wrong with the javascript, exect that you're not sending the keyword in the url. As for the PHP, the only thing i see is that on one line, you use $_GET['keywordl']. I assume that's meant to be just 'keyword' Are you using firefox? Does the javascript error console give any indication of the problem? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.