• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Need help with UPDATE

ducktape

NLC
NLC
I have a script that I use to update my pages via the internet. This works fine on all my other cpanel servers. But when I use this on my company's hosting account at Apollo Hosting it wont update the pages. Everything appears to wor properly but in the end it will not update the database. Can anyone see anything wrong with this that may prevent it from working properly.

PHP:
<script language="JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}
//-->
</script>

<?

require "../config.inc";

$edit = $_GET['edit'];
$id = $_GET['id'];

# edit - show
if ($edit == "show") {

$db = mysql_connect("$dbhost", "$dbuser", "$dbpassword"); 
mysql_select_db("$dbname",$db);

$result = mysql_query("SELECT * FROM site WHERE id = '$id'",$db);
$content = mysql_fetch_array($result);

do {
$id = ($content["id"]);
$title = ($content["title"]);
$text = ($content["text"]);

echo "
<form method=\"post\" action=\"?id=$id&edit=done\">

<input type=\"hidden\" name=\"id\" value=\"$id\">

<b>Page Title</b><br>
<INPUT TYPE=\"TEXT\" NAME=\"title\" size=\"35\" maxlength=\"70\" class=\"text-field\" value=\"$title\"><p>

<b>Page Content</b><br>
<TEXTAREA NAME=\"text\" ROWS=\"30\" COLS=\"85\" class=\"text-field2\">$text</TEXTAREA><p>

<input type=\"Submit\" name=\"submit\" value=\"Enter Information\" style=\"border:1px solid #C80708; background-color: #cccccc; color: #000000; font-weight: bold\">";

} while ($content = mysql_fetch_array($result));

echo "</form>";

#edit - done
} elseif ($edit == "done") {

$db = mysql_connect("$dbhost", "$dbuser", "$dbpassword"); 
mysql_select_db("$dbname",$db);

   $id = $_POST['id'];
   $title = $_POST['title'];
   $text = $_POST['text'];


        $sql = "UPDATE site SET id='$id',title='$title',text='$text' WHERE id=$id";
        //replace news with your table name above 
   		$result = mysql_query($sql);
        echo "<center><span class=\"main\">Thank you! Information updated.<p>
		<a href=\"edit_pages.php\">Edit Another Page</a>&nbsp;|&nbsp;
		<a href=\"index.php\">&raquo; Back to Control Panel</a></span></center>"; 


#edit - else
} else {

$db = mysql_connect("$dbhost", "$dbuser", "$dbpassword"); 
mysql_select_db("$dbname",$db);

$result = mysql_query("SELECT * FROM site ORDER BY id",$db);
$content = mysql_fetch_array($result);

echo "<form name=form2>
<select onChange=\"MM_jumpMenu('parent',this,0)\" name=menu2>
<option value=\"\">Make a Selection</option>";

do {
$id = ($content["id"]);
$title = ($content["title"]);

echo "<option value=\"?id=$id&edit=show\">$title</option>";

} while ($content = mysql_fetch_array($result));

echo "</select></form>";

}

?>
 
Well... According to that do-while loop, you have multiple form-open tags but only one form-close tag...
 
PHP:
$sql = "UPDATE site SET id='$id',title='$title',text='$text' WHERE id=$id";

PHP:
$sql = "UPDATE site SET id='$id',title='$title',text='$text' WHERE id='$id'";
 
Try it out... http://synergyrecycling.com/edit_pages.php?id=5&edit=show . It is getting the information from the database and displaying it in the form. It allows you to type the information into the form, but when its actually supposed to update the database it says it does with no errors and when you look at the page http://synergyrecycling.com/index.php it doesnt actually update it.

Also does someone know how to connect to a mysql database remotely? I have tried the ip address of the remote server and ipaddress:3306 where localhost is replaced and i couldnt connect. I have set cpanel to accept remote connections and it wont connect.

PHP:
<?php

$dbhost = "localhost";

$dbname = "xxxxxxxxxxx";

$dbuser = "xxxxxxxxxx";

$dbpassword = "xxxxxxxxxx";

?>
 
Last edited:
I sometimes bodge together online html editors for members that aren't too computer minded, and have written scripts similar to this before...the other thing you can do, is delete, then insert by id....did you try the ' around $id ?

I'l show you how I did it, this is more or less the same thing as you have only...longer and messier

PHP:
include '../settings.php';
if ($_POST['op'] != "ds") {
	  mysql_connect(localhost,$sqluser,$sqlpass);
	  $id = $_GET['id'];
	  @mysql_select_db($sqldb) or die( "Unable to select database");
	  $query= 'select * FROM `articles` WHERE id="'.$id.'"';
	  $result=mysql_query($query);
	  $id=mysql_result($result,$i,"id");
      $desc=mysql_result($result,$i,"description");
	  $title=mysql_result($result,$i,"title");
      $content=mysql_result($result,$i,"content");
} 
if (isset ($_POST['submit'])) {
  
	  // Update Content
	  $id = stripslashes($_GET['id']);
	  $title = stripslashes($_POST['title']);
	  $content = stripslashes($_POST['content']);
	  $desc = stripslashes($_POST['desc']);
	  mysql_connect(localhost,$sqluser,$sqlpass);
	  @mysql_select_db($sqldb) or die( "Unable to select database");
	  $query = "UPDATE articles SET title = '$title', content = '$content', description = '$desc' WHERE id='$id'";
      mysql_query($query);
      mysql_close();
      mysql_connect(localhost,$sqluser,$sqlpass);
	  @mysql_select_db($sqldb) or die( "Unable to select database");
	  $query= 'select * FROM `articles` WHERE id="'.$id.'"';
	  $result=mysql_query($query);
      $id=mysql_result($result,$i,"id");
      $title=mysql_result($result,$i,"title");
      $desc=mysql_result($result,$i,"description");
      $content=mysql_result($result,$i,"content");
      $date=mysql_result($result,$i,"date");
}



This way works without fail every time....good luck
 
Back
Top