Jump to content


Photo

Text inputted in to database just disappears


  • Please log in to reply
18 replies to this topic

#1 SneakyMax

SneakyMax
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 21 July 2006 - 06:04 PM

This problem has been bugging me for a while now, and I don't have the slightest clue what migh be causing it. It might not even relate to my php.

Ok, I have a news page on my website, which gets all the news posts from a mysql database and lists them. Then I have a bunch of admin pages, one of which I can add, edit, view, and delete news posts.

I believe the problem is something with the old news editing file, but I've checked it. The problem is that I will edit the file, then go to the news page. It will work fine, the news post was edited and everything. I refresh the page. Still there. Then I click on links that lead me to the same page. Still there. Then I wait a couple minutes. Try going to the news page, and the text I changed for the news post is just gone. It shows the time and then blank. Looking in to it, the text section of the part of it in the database is just gone. Blank. Everything else about the value is there though. Date, id.

Here is the script for editing it (edit.php):
<?php
include_once('includes.php');

$db=new DB_Mysql();
$scp=new Scp();
$rp=new Rp();
$scp->check_credentials(3);

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

switch($_GET['done']){
case 1:
$query="UPDATE rp_news SET text=:1 WHERE id=:2";
$db->prepare($query)->execute($_POST['text'],$id);
echo($_POST['text']);
$rp->set_quick("Update complete<br>
			<a href='http://www.thereviewpalace.com/admin.php?page=news&method=all'>Back</a>
			");
break;
default:

$query="SELECT * FROM rp_news WHERE id=:1 LIMIT 1";
$row=$db->prepare($query)->execute($id)->fetch_assoc();

$html.="<form method='POST' action='http://www.thereviewpalace.com/admin.php?page=news&method=edit&
	id=".$row['id']."&done=1' name='editform'><tr>
	<td>
	<textarea name='text' rows='30' cols='100'>".stripslashes($row['text'])."</textarea></td></tr><tr><td>
	<input type='submit' value='Submit' name='submit'></form></td></tr><tr><td>
	
	<a href='http://www.thereviewpalace.com/admin.php?page=news&method=view&id=".$id."'>
	<img src='http://www.thereviewpalace.com/images/icon_view.jpg'></a>
	
	<a href='http://www.thereviewpalace.com/admin.php?page=news&method=delete&id=".$id."'>
	<img src='http://www.thereviewpalace.com/images/icon_delete.jpg'></a>
	</td>
	</tr>";
	
$mainhtml="<big>Here is the page requested.<br>
		<a href='http://www.thereviewpalace.com/admin.php?page=news&method=all'>Back</a><br><br>
		<table border='1' cellpadding=3>
		".$html."
		</table>";
$rp->start();
$rp->set_page_text($mainhtml);
$rp->set_text();
$rp->end();

}

?>

I know I don't need a switch statement but I've found them useful, especially for $_GET variables

And this is every time the table rp_news is accessed in every single one of my scripts:

index.php (109): $sql="SELECT * FROM rp_news ORDER BY date DESC";
index.php (173): $sql="SELECT * FROM rp_news ORDER BY date DESC";
index.php (184): $sql="SELECT * FROM rp_news ORDER BY date DESC";
add.php (12):      $query="INSERT INTO rp_news (text,date) VALUES (:1,now())";
edit.php (14):      $query="UPDATE rp_news SET text=:1 WHERE id=:2";
edit.php (23):      $query="SELECT * FROM rp_news WHERE id=:1 LIMIT 1";
all.php (12):        $query="SELECT id, date FROM rp_news ORDER BY date ASC";
delete.php (14):    $query="DELETE FROM rp_news WHERE id=:1 LIMIT 1";

add, edit, all, and delete are for the news posts. I use an inclusion system and folders.

As it says, only edit.php updates rp_news. But that still doesn't explain the huge delay before it just erases itself.

What could be causing this?


#2 kalivos

kalivos
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationCalifornia

Posted 21 July 2006 - 06:23 PM

Do you include edit.php on any of the pages? If you do, you might check that you are not using $_GET['done'] on that page. This sounds like it's a simple problem, but could be hard to pinpoint.
Make a donation to phpfreaks. They need your help![br][br]

#3 SneakyMax

SneakyMax
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 21 July 2006 - 06:33 PM

Nope, I don't think so. The only page that includes it is admin.php, and that's so I don't have to access the script directly. The only time $_GET['done'] is used is in my four edit.php's (one for each thing that can be edited). Thanks though that would make sense.

If it helps, the format for rp_news:

'id' smallint(10) auto_increment
'text' text
'date' datetime

Could it be possible that someone is messing with the database?



#4 kalivos

kalivos
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationCalifornia

Posted 21 July 2006 - 06:51 PM

Although it is possible someone is messing with the database, I doubt that is the case. My reasoning is that it happens almost immediately after updating the text, right? If you can port this to a sandbox machine, that would verify if someone is messing you up or somethings buggy in the code. More than likely, it's some part of the code.
Make a donation to phpfreaks. They need your help![br][br]

#5 SneakyMax

SneakyMax
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 21 July 2006 - 09:14 PM

It doesn't really happen immediately after updating the text. It's really weird and sporatic. And I can't find when it happens. I will go to it many times, and other pages, and it will be fine. Then maybe 5 minutes later it's gone. It's just a really weird thing. I'll do some more tests. Thanks for your help

EDIT: It's really weird, I can go to almost every single page (and script) on my site and the news post stays there. Probably in 5 minutes it will disappear again. Does the database not like it?
EDIT2: Yep, right when I finished writing the edit, I went back and refreshed the page. And if course, it was gone again.

#6 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 21 July 2006 - 09:35 PM

  • Are there any cronjobs running on your box?
  • Are you using any transactional (InnoDB) tables?

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#7 SneakyMax

SneakyMax
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 21 July 2006 - 09:55 PM

I'm using a hosting provider, they might have cronjobs on there. I could ask them

And, no, they're all MyISAM tables

#8 dwees

dwees
  • Members
  • PipPipPip
  • Advanced Member
  • 47 posts
  • LocationUnited Kingdom

Posted 21 July 2006 - 10:37 PM

Is it possible that you can see the pages because of your browser's cache?  Have you tried entering the information into the form, saving it, then clearing the cache immediately, THEN  refreshing the page?  This is a pretty simple debug I've done many times, don't know if you've tried it yet or not.

Also, have you tried sending the text that you saved to a file?

#9 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 21 July 2006 - 11:22 PM

have you also tried to check the db immediately after submission?
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#10 SneakyMax

SneakyMax
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 22 July 2006 - 12:30 AM

I'll try those thanks.

EDIT: Okay, I cleared the cache then refreshed it and it disappeared. Then I tried again (editing to say edit and going there), it was there, I cleared the cache, and it was still there.

I then edited it (it disappeared after a while), and immediately checked the database. It's right there. Then I went to the news page, and checked the database again. Still there

This is just weird...and it just disappeared again

EDIT 2: And this time it's staying. Both on the page and in the database. And it will probably be gone again by the time I'l done writing this. I'm really stuck on this, could it be the database not liking it or my hosting not liking it? It's just weird

#11 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 22 July 2006 - 01:54 AM

add.php (12):      $query="INSERT INTO rp_news (text,date) VALUES (:1,now())";
edit.php (14):      $query="UPDATE rp_news SET text=:1 WHERE id=:2";
edit.php (23):      $query="SELECT * FROM rp_news WHERE id=:1 LIMIT 1";
delete.php (14):    $query="DELETE FROM rp_news WHERE id=:1 LIMIT 1";


I'm wondering what those queries are all about, particularly the syntax using : and := which is not a syntax I've seen before. Is that really what you have or was that a typo in your post or this forum playing tricks with what you posted? (or have I just learned something and not recognized it?)
Legend has it that reading the manual never killed anyone.
My site

#12 SneakyMax

SneakyMax
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 22 July 2006 - 02:26 AM

It's basically a Mysql remake of Mysqli that I mostly got from a book, then tuned to what I needed.

<?php
$query="UPDATE rp_news SET text=:1 WHERE id=:2";
$db->prepare($query)->execute($_POST['text'],$id);
?>


#13 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 22 July 2006 - 02:30 AM

maybe have you reachs max space limit on ur database or host all together..i know when i got my database the max space on it was set to 30mb...then i reset it later..but check that

EDIT: When i say database i mean like "the database" not your site! (i.E My site has 40gigs, database set to max 1gig)
"Syntax error" .. WHERE THE **** IS IT?!

#14 SneakyMax

SneakyMax
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 22 July 2006 - 02:33 AM

I thought of that, but I have a phpbb forum, and it's adding new posts just fine. And I've only used like 20mb out of 30gb

#15 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 22 July 2006 - 02:36 AM

hmm ya if the phpbb forum is working fine it shouldnt be something with database... would you be able to give us a link to the admin page to edit and add post to try it(maybe something to do with ur comp? (firewall? cookies? security settings?)
"Syntax error" .. WHERE THE **** IS IT?!

#16 SneakyMax

SneakyMax
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 22 July 2006 - 02:49 AM

Okay, I guess a second set of eyes to see if they can isolate the problem would be good. I may get a bit of spammyness but I can easily revert it back. I saved all of the other news posts that worked (eventually)

UrL: http://www.thereview...n.php?page=main

You will have access only to Old News, and in there, editing (adding might give more spam, if there's a less spam way to tell you I will let you add ones). For the list of news posts the newest one (the one that won't work) is at the bottom.

I'm going to get spam. I'm using htmlentities though so no malicious code.

Also, yay for advertisement!

#17 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 22 July 2006 - 03:05 AM

this comes up when i try any of the links "Incorrect credentials"
"Syntax error" .. WHERE THE **** IS IT?!

#18 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 22 July 2006 - 03:10 AM

also i got the page noted down if you want to remove it
"Syntax error" .. WHERE THE **** IS IT?!

#19 SneakyMax

SneakyMax
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 22 July 2006 - 03:21 AM

Are you sure? If you go to http://www.thereview...n.php?page=main then click on 'old news' then on the bottom one click the middle picture you get the error? You shouldn't I'm not logged in and I can do just those things, nothing else

Or, you can go to http://www.thereview...ethod=edit&id=5 and you will go directly to the editing page of the news post that won't work




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users