Jump to content

Archived

This topic is now archived and is closed to further replies.

SneakyMax

Text inputted in to database just disappears

Recommended Posts

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):
[code]<?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();

}

?>[/code]

I know I don't [i]need[/i] 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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[list]
[*]Are there any cronjobs running on your box?
[*]Are you using any transactional (InnoDB) tables?
[/list]

Share this post


Link to post
Share on other sites
I'm using a hosting provider, they might have cronjobs on there. I could ask them

And, no, they're all MyISAM tables

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
have you also tried to check the db immediately after submission?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[quote]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";[/quote]

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?)

Share this post


Link to post
Share on other sites
It's basically a Mysql remake of Mysqli that I mostly got from a book, then tuned to what I needed.

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

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?)

Share this post


Link to post
Share on other sites
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.thereviewpalace.com/admin.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!

Share this post


Link to post
Share on other sites
Are you sure? If you go to http://www.thereviewpalace.com/admin.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.thereviewpalace.com/admin.php?page=news&method=edit&id=5 and you will go directly to the editing page of the news post that won't work

Share this post


Link to post
Share on other sites

×

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.