imarockstar Posted November 10, 2008 Share Posted November 10, 2008 does this look right ? $sql = "UPDATE homeblocks SET title='$title',text='$text' WHERE id=$id"; $result = mysql_query($sql); the problem is that its not updateing the database ... here is a link to the page : http://74.55.14.226/~green/admin/editboxes.php?cmd=edit&id=3 im trying to update the db via this js file code <!-- //XMLHttpRequest class function function datosServidor() { }; datosServidor.prototype.iniciar = function() { try { // Mozilla / Safari this._xh = new XMLHttpRequest(); } catch (e) { // Explorer var _ieModelos = new Array( 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP' ); var success = false; for (var i=0;i < _ieModelos.length && !success; i++) { try { this._xh = new ActiveXObject(_ieModelos[i]); success = true; } catch (e) { } } if ( !success ) { return false; } return true; } } datosServidor.prototype.ocupado = function() { estadoActual = this._xh.readyState; return (estadoActual && (estadoActual < 4)); } datosServidor.prototype.procesa = function() { if (this._xh.readyState == 4 && this._xh.status == 200) { this.procesado = true; } } datosServidor.prototype.enviar = function(urlget,datos) { if (!this._xh) { this.iniciar(); } if (!this.ocupado()) { this._xh.open("GET",urlget,false); this._xh.send(datos); if (this._xh.readyState == 4 && this._xh.status == 200) { return this._xh.responseText; } } return false; } var urlBase = "scripts/update.php"; var formVars = ""; var changing = false; function fieldEnter(campo,evt,idfld) { evt = (evt) ? evt : window.event; if (evt.keyCode == 13 && campo.value!="") { elem = document.getElementById( idfld ); remotos = new datosServidor; nt = remotos.enviar(urlBase + "?fieldname=" +encodeURI(elem.id)+ "&content="+encodeURI(campo.value)+"&"+formVars,""); //remove glow noLight(elem); elem.innerHTML = nt; changing = false; return false; } else { return true; } } function fieldBlur(campo,idfld) { if (campo.value!="") { elem = document.getElementById( idfld ); remotos = new datosServidor; nt = remotos.enviar(urlBase + "?fieldname=" +escape(elem.id)+ "&content="+escape(campo.value)+"&"+formVars,""); elem.innerHTML = nt; changing = false; return false; } } //edit field created function editBox(actual) { //alert(actual.nodeName+' '+changing); if(!changing){ width = widthEl(actual.id) + 20; height =heightEl(actual.id) + 2; if(height < 40){ if(width < 100) width = 150; actual.innerHTML = "<input id=\""+ actual.id +"_field\" style=\"width: "+width+"px; height: "+height+"px;\" maxlength=\"254\" type=\"text\" value=\"" + actual.innerHTML + "\" onkeypress=\"return fieldEnter(this,event,'" + actual.id + "')\" onfocus=\"highLight(this);\" onblur=\"noLight(this); return fieldBlur(this,'" + actual.id + "');\" />"; }else{ if(width < 70) width = 90; if(height < 50) height = 50; actual.innerHTML = "<textarea name=\"textarea\" id=\""+ actual.id +"_field\" style=\"width: "+width+"px; height: "+height+"px;\" onfocus=\"highLight(this);\" onblur=\"noLight(this); return fieldBlur(this,'" + actual.id + "');\">" + actual.innerHTML + "</textarea>"; } changing = true; } actual.firstChild.focus(); } //find all span tags with class editText and id as fieldname parsed to update script. add onclick function function editbox_init(){ if (!document.getElementsByTagName){ return; } var spans = document.getElementsByTagName("span"); // loop through all span tags for (var i=0; i<spans.length; i++){ var spn = spans[i]; if (((' '+spn.className+' ').indexOf("editText") != -1) && (spn.id)) { spn.onclick = function () { editBox(this); } spn.style.cursor = "pointer"; spn.title = "Click to edit!"; } } } //crossbrowser load function function addEvent(elm, evType, fn, useCapture) { if (elm.addEventListener){ elm.addEventListener(evType, fn, useCapture); return true; } else if (elm.attachEvent){ var r = elm.attachEvent("on"+evType, fn); return r; } else { alert("Please upgrade your browser to use full functionality on this page"); } } //get width of text element function widthEl(span){ if (document.layers){ w=document.layers[span].clip.width; } else if (document.all && !document.getElementById){ w=document.all[span].offsetWidth; } else if(document.getElementById){ w=document.getElementById(span).offsetWidth; } return w; } //get height of text element function heightEl(span){ if (document.layers){ h=document.layers[span].clip.height; } else if (document.all && !document.getElementById){ h=document.all[span].offsetHeight; } else if(document.getElementById){ h=document.getElementById(span).offsetHeight; } return h; } function highLight(span){ //span.parentNode.style.border = "2px solid #D1FDCD"; //span.parentNode.style.padding = "0"; span.style.border = "1px solid #54CE43"; } function noLight(span){ //span.parentNode.style.border = "0px"; //span.parentNode.style.padding = "2px"; span.style.border = "0px"; } //sets post/get vars for update function setVarsForm(vars){ formVars = vars; } addEvent(window, "load", editbox_init); --> below is the full update.php file header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); // HTTP/1.1 header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); // HTTP/1.0 $dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die('Could not connect to MySQL: ' . mysql_error()); mysql_select_db (DB_NAME) OR die('Could not select the database: ' . mysql_error()); $sql = "UPDATE homeblocks SET title='$title',text='$text' WHERE id=$id"; $result = mysql_query($sql); $fieldname = $_GET['fieldname']; echo stripslashes(strip_tags($_GET['content'],"<br><p><img><a><br /><strong><em>")); Quote Link to comment https://forums.phpfreaks.com/topic/132202-db-update-help/ Share on other sites More sharing options...
premiso Posted November 10, 2008 Share Posted November 10, 2008 Perhaps adding this to test would help diagnose the problem: $sql = "UPDATE homeblocks SET title='$title',text='$text' WHERE id=$id"; $result = mysql_query($sql) or die("ERROR: " . mysql_error()); Should tell you if there was an error with the sql. The prominent error I am guessing is that the string passed in has not be properly escaped and a ' will break the SQL. Good habit to use www.php.net/mysql_real_escape_string on any data being input to the database from GET/POST data. Quote Link to comment https://forums.phpfreaks.com/topic/132202-db-update-help/#findComment-687141 Share on other sites More sharing options...
imarockstar Posted November 10, 2008 Author Share Posted November 10, 2008 this is the error .. i dont understand it ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/132202-db-update-help/#findComment-687161 Share on other sites More sharing options...
premiso Posted November 10, 2008 Share Posted November 10, 2008 Let's try this then: $sql = "UPDATE homeblocks SET title='$title',text='$text' WHERE id=$id"; $result = mysql_query($sql) or die("ERROR: " . mysql_error() . "<Br>SQL: " . $sql); See what your SQL statement is trying to execute, chances are something does not contain a value when it needs to. Quote Link to comment https://forums.phpfreaks.com/topic/132202-db-update-help/#findComment-687168 Share on other sites More sharing options...
DarkWater Posted November 10, 2008 Share Posted November 10, 2008 You never set $title or $text, or even $id. =/ Quote Link to comment https://forums.phpfreaks.com/topic/132202-db-update-help/#findComment-687170 Share on other sites More sharing options...
.josh Posted November 10, 2008 Share Posted November 10, 2008 My guess: You use $title, $text and $id in your update. Those vars don't exist unless you have globals set to ON (which you probably don't, and shouldn't). Since globals are probably set to OFF, posted data will either be in $_GET['varname'] or $_POST['varname'], depending on what method you used (or $_REQUEST['varname'] will have info from either one). Quote Link to comment https://forums.phpfreaks.com/topic/132202-db-update-help/#findComment-687180 Share on other sites More sharing options...
imarockstar Posted November 10, 2008 Author Share Posted November 10, 2008 error ??? ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 SQL: UPDATE homeblocks SET title='',text='' WHERE id= the only things in the database are id, title, and text ... I am not updating the ID since that does not need to be updated Quote Link to comment https://forums.phpfreaks.com/topic/132202-db-update-help/#findComment-687181 Share on other sites More sharing options...
imarockstar Posted November 10, 2008 Author Share Posted November 10, 2008 so i need this ? $id = $_GET['id']; $title = $_GET['title']; $text = $_GET['text']; $sql = "UPDATE homeblocks SET title='$title',text='$text' WHERE id=$id"; $result = mysql_query($sql) or die("ERROR: " . mysql_error() . "<Br>SQL: " . $sql); Quote Link to comment https://forums.phpfreaks.com/topic/132202-db-update-help/#findComment-687186 Share on other sites More sharing options...
imarockstar Posted November 10, 2008 Author Share Posted November 10, 2008 ok i added what I typed above .... and now i dont get a sql error .. but it erases the $title and $text information .. so its not updating it .. its erasing it ... Quote Link to comment https://forums.phpfreaks.com/topic/132202-db-update-help/#findComment-687191 Share on other sites More sharing options...
imarockstar Posted November 10, 2008 Author Share Posted November 10, 2008 this is the file thats supposably passing on the variables to my update.php <!-- //script by http://www.yvoschaap.com //XMLHttpRequest class function function datosServidor() { }; datosServidor.prototype.iniciar = function() { try { // Mozilla / Safari this._xh = new XMLHttpRequest(); } catch (e) { // Explorer var _ieModelos = new Array( 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP' ); var success = false; for (var i=0;i < _ieModelos.length && !success; i++) { try { this._xh = new ActiveXObject(_ieModelos[i]); success = true; } catch (e) { } } if ( !success ) { return false; } return true; } } datosServidor.prototype.ocupado = function() { estadoActual = this._xh.readyState; return (estadoActual && (estadoActual < 4)); } datosServidor.prototype.procesa = function() { if (this._xh.readyState == 4 && this._xh.status == 200) { this.procesado = true; } } datosServidor.prototype.enviar = function(urlget,datos) { if (!this._xh) { this.iniciar(); } if (!this.ocupado()) { this._xh.open("GET",urlget,false); this._xh.send(datos); if (this._xh.readyState == 4 && this._xh.status == 200) { return this._xh.responseText; } } return false; } var urlBase = "scripts/update.php"; var formVars = ""; var changing = false; function fieldEnter(campo,evt,idfld) { evt = (evt) ? evt : window.event; if (evt.keyCode == 13 && campo.value!="") { elem = document.getElementById( idfld ); remotos = new datosServidor; nt = remotos.enviar(urlBase + "?fieldname=" +encodeURI(elem.id)+ "&content="+encodeURI(campo.value)+"&"+formVars,""); //remove glow noLight(elem); elem.innerHTML = nt; changing = false; return false; } else { return true; } } function fieldBlur(campo,idfld) { if (campo.value!="") { elem = document.getElementById( idfld ); remotos = new datosServidor; nt = remotos.enviar(urlBase + "?fieldname=" +escape(elem.id)+ "&content="+escape(campo.value)+"&"+formVars,""); elem.innerHTML = nt; changing = false; return false; } } //edit field created function editBox(actual) { //alert(actual.nodeName+' '+changing); if(!changing){ width = widthEl(actual.id) + 20; height =heightEl(actual.id) + 2; if(height < 40){ if(width < 100) width = 150; actual.innerHTML = "<input id=\""+ actual.id +"_field\" style=\"width: "+width+"px; height: "+height+"px;\" maxlength=\"254\" type=\"text\" value=\"" + actual.innerHTML + "\" onkeypress=\"return fieldEnter(this,event,'" + actual.id + "')\" onfocus=\"highLight(this);\" onblur=\"noLight(this); return fieldBlur(this,'" + actual.id + "');\" />"; }else{ if(width < 70) width = 90; if(height < 50) height = 50; actual.innerHTML = "<textarea name=\"textarea\" id=\""+ actual.id +"_field\" style=\"width: "+width+"px; height: "+height+"px;\" onfocus=\"highLight(this);\" onblur=\"noLight(this); return fieldBlur(this,'" + actual.id + "');\">" + actual.innerHTML + "</textarea>"; } changing = true; } actual.firstChild.focus(); } //find all span tags with class editText and id as fieldname parsed to update script. add onclick function function editbox_init(){ if (!document.getElementsByTagName){ return; } var spans = document.getElementsByTagName("span"); // loop through all span tags for (var i=0; i<spans.length; i++){ var spn = spans[i]; if (((' '+spn.className+' ').indexOf("editText") != -1) && (spn.id)) { spn.onclick = function () { editBox(this); } spn.style.cursor = "pointer"; spn.title = "Click to edit!"; } } } //crossbrowser load function function addEvent(elm, evType, fn, useCapture) { if (elm.addEventListener){ elm.addEventListener(evType, fn, useCapture); return true; } else if (elm.attachEvent){ var r = elm.attachEvent("on"+evType, fn); return r; } else { alert("Please upgrade your browser to use full functionality on this page"); } } //get width of text element function widthEl(span){ if (document.layers){ w=document.layers[span].clip.width; } else if (document.all && !document.getElementById){ w=document.all[span].offsetWidth; } else if(document.getElementById){ w=document.getElementById(span).offsetWidth; } return w; } //get height of text element function heightEl(span){ if (document.layers){ h=document.layers[span].clip.height; } else if (document.all && !document.getElementById){ h=document.all[span].offsetHeight; } else if(document.getElementById){ h=document.getElementById(span).offsetHeight; } return h; } function highLight(span){ //span.parentNode.style.border = "2px solid #D1FDCD"; //span.parentNode.style.padding = "0"; span.style.border = "1px solid #54CE43"; } function noLight(span){ //span.parentNode.style.border = "0px"; //span.parentNode.style.padding = "2px"; span.style.border = "0px"; } //sets post/get vars for update function setVarsForm(vars){ formVars = vars; } addEvent(window, "load", editbox_init); --> Quote Link to comment https://forums.phpfreaks.com/topic/132202-db-update-help/#findComment-687195 Share on other sites More sharing options...
.josh Posted November 10, 2008 Share Posted November 10, 2008 I don't see anywhere in your clientside code where you're doing name='text' name='content' in your input tags or passing those name/values to the script. Quote Link to comment https://forums.phpfreaks.com/topic/132202-db-update-help/#findComment-687203 Share on other sites More sharing options...
imarockstar Posted November 10, 2008 Author Share Posted November 10, 2008 that code i posted is from the js file. it is inline editing .. and here is where i got it from ... http://www.yvoschaap.com/index.php/weblog/ajax_inline_instant_update_text_20/ this is the code that is supposed to pass the varibles .. <!-- //script by http://www.yvoschaap.com //XMLHttpRequest class function function datosServidor() { }; datosServidor.prototype.iniciar = function() { try { // Mozilla / Safari this._xh = new XMLHttpRequest(); } catch (e) { // Explorer var _ieModelos = new Array( 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP' ); var success = false; for (var i=0;i < _ieModelos.length && !success; i++) { try { this._xh = new ActiveXObject(_ieModelos[i]); success = true; } catch (e) { } } if ( !success ) { return false; } return true; } } datosServidor.prototype.ocupado = function() { estadoActual = this._xh.readyState; return (estadoActual && (estadoActual < 4)); } datosServidor.prototype.procesa = function() { if (this._xh.readyState == 4 && this._xh.status == 200) { this.procesado = true; } } datosServidor.prototype.enviar = function(urlget,datos) { if (!this._xh) { this.iniciar(); } if (!this.ocupado()) { this._xh.open("GET",urlget,false); this._xh.send(datos); if (this._xh.readyState == 4 && this._xh.status == 200) { return this._xh.responseText; } } return false; } var urlBase = "scripts/update.php"; var formVars = ""; var changing = false; function fieldEnter(campo,evt,idfld) { evt = (evt) ? evt : window.event; if (evt.keyCode == 13 && campo.value!="") { elem = document.getElementById( idfld ); remotos = new datosServidor; nt = remotos.enviar(urlBase + "?fieldname=" +encodeURI(elem.id)+ "&content="+encodeURI(campo.value)+"&"+formVars,""); //remove glow noLight(elem); elem.innerHTML = nt; changing = false; return false; } else { return true; } } function fieldBlur(campo,idfld) { if (campo.value!="") { elem = document.getElementById( idfld ); remotos = new datosServidor; nt = remotos.enviar(urlBase + "?fieldname=" +escape(elem.id)+ "&content="+escape(campo.value)+"&"+formVars,""); elem.innerHTML = nt; changing = false; return false; } } //edit field created function editBox(actual) { //alert(actual.nodeName+' '+changing); if(!changing){ width = widthEl(actual.id) + 20; height =heightEl(actual.id) + 2; if(height < 40){ if(width < 100) width = 150; actual.innerHTML = "<input id=\""+ actual.id +"_field\" style=\"width: "+width+"px; height: "+height+"px;\" maxlength=\"254\" type=\"text\" value=\"" + actual.innerHTML + "\" onkeypress=\"return fieldEnter(this,event,'" + actual.id + "')\" onfocus=\"highLight(this);\" onblur=\"noLight(this); return fieldBlur(this,'" + actual.id + "');\" />"; }else{ if(width < 70) width = 90; if(height < 50) height = 50; actual.innerHTML = "<textarea name=\"textarea\" id=\""+ actual.id +"_field\" style=\"width: "+width+"px; height: "+height+"px;\" onfocus=\"highLight(this);\" onblur=\"noLight(this); return fieldBlur(this,'" + actual.id + "');\">" + actual.innerHTML + "</textarea>"; } changing = true; } actual.firstChild.focus(); } //find all span tags with class editText and id as fieldname parsed to update script. add onclick function function editbox_init(){ if (!document.getElementsByTagName){ return; } var spans = document.getElementsByTagName("span"); // loop through all span tags for (var i=0; i<spans.length; i++){ var spn = spans[i]; if (((' '+spn.className+' ').indexOf("editText") != -1) && (spn.id)) { spn.onclick = function () { editBox(this); } spn.style.cursor = "pointer"; spn.title = "Click to edit!"; } } } //crossbrowser load function function addEvent(elm, evType, fn, useCapture) { if (elm.addEventListener){ elm.addEventListener(evType, fn, useCapture); return true; } else if (elm.attachEvent){ var r = elm.attachEvent("on"+evType, fn); return r; } else { alert("Please upgrade your browser to use full functionality on this page"); } } //get width of text element function widthEl(span){ if (document.layers){ w=document.layers[span].clip.width; } else if (document.all && !document.getElementById){ w=document.all[span].offsetWidth; } else if(document.getElementById){ w=document.getElementById(span).offsetWidth; } return w; } //get height of text element function heightEl(span){ if (document.layers){ h=document.layers[span].clip.height; } else if (document.all && !document.getElementById){ h=document.all[span].offsetHeight; } else if(document.getElementById){ h=document.getElementById(span).offsetHeight; } return h; } function highLight(span){ //span.parentNode.style.border = "2px solid #D1FDCD"; //span.parentNode.style.padding = "0"; span.style.border = "1px solid #54CE43"; } function noLight(span){ //span.parentNode.style.border = "0px"; //span.parentNode.style.padding = "2px"; span.style.border = "0px"; } //sets post/get vars for update function setVarsForm(vars){ formVars = vars; } addEvent(window, "load", editbox_init); --> Quote Link to comment https://forums.phpfreaks.com/topic/132202-db-update-help/#findComment-687207 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.