Jump to content


query only works on first row

  • Please log in to reply
2 replies to this topic

#1 h4v0c

  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 05 September 2006 - 01:48 PM

Hi, Its me again

I asked a question concerning saving posted data out of the FCKeditor v.2.3.1 in the thread below:

http://www.phpfreaks....msg426288.html (Thanks to xyn, who was very helpful)

I got that problem solved, but now the editor only saves to the first row in the database.

Just to sum it up again:

The editor is passed the page ID from a page listing. Editor then loads the data using this query:

			mysql_connect("server URL", "user name", "password") or die ('I can?t connect to the database.') ;  
			mysql_select_db("clientd_psp") ;
			$pagedid = $_GET['id'];
			$posted_id = $_POST['id'];
			$result = mysql_query("SELECT * FROM content_tbl WHERE page_id=$pagedid") ;
			$row = mysql_fetch_array($result) ;
			echo "<div style=\"font-size:18px;\">" . $row['name'] . "</div><br />" ;

			//$sBasePath = $_SERVER['PHP_SELF'] ;
			//$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "_samples" ) ) ;
			$oFCKeditor = new FCKeditor('PSP_editor') ;
			$oFCKeditor->BasePath	= '/psp/fckeditor/' ;
			$oFCKeditor->Value		= $row['page_content'] ;
			$oFCKeditor->Height		= '500' ;
			$oFCKeditor->Create() ;
			echo ("<input type='hidden' value='$pagedid' name='page_id_value' />") ;

This part works flawlessly. The problem I have is that when posting it to this script:
<?php$host="server URL" ;
	$login="user name" ;
	$pwd="password" ;
	$db="clientd_psp" ;

	$conn = mysql_connect("$host", "$login", "$pwd") or die('SQL Error: '.mysql_error().'') ;
	mysql_select_db($db, $conn) ;
	mysql_query("UPDATE content_tbl SET page_content='".stripslashes($_POST['PSP_editor'])."' WHERE page_id='".$_POST['page_id_value']."'") ;

This only works when page_id is 100(the very first row in the database) I have no idea whats going, and I am definately a php noob, so I am at a loss as to whats going on with it not working. Like I said, its a problem with every row except the first one. Does anyone have any experience in using this wysiwyg?

#2 ober

  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 05 September 2006 - 02:06 PM

I assume you have other rows in the database that it can update?

As a troubleshooting technique, you should always build your query outside of the mysql_query() function.  Then you can echo the query to see what is actually going into the query.

Also, you're not checking for failure of the query.  You should be doing this:

$result = mysql_query($query);
    echo mysql_error();

Info: PHP Manual

#3 paul2463

  • Members
  • PipPipPip
  • Advanced Member
  • 955 posts
  • LocationUK

Posted 05 September 2006 - 02:08 PM

I have had problems with queries before and I found that a couple of my problems have been in putting complex variables into the query statement, it might be worth a try setting thos variables up and then writing the query i.e
$edit = stripslashes($_POST['PSP_editor']);
$page = $_POST['page_id_value'];
mysql_query("UPDATE content_tbl SET page_content='$edit' WHERE page_id='$page") ;
it might work, it might not, but I have had some success doing things this way.
you cannot affect the past but you can ruin a perfectly good present by worrying about the future

The <A HREF="http://www.php.net/d...php">MANUAL</A> is actually a useful resource

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users