Jump to content

Php Mysql Insert


Goins

Recommended Posts

 

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!';

}
?>

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.