/    Sign up×
Community /Pin to ProfileBookmark

ghost entries

hello all

i tried looking for an answer on google and here for this but couldnt find any and this is making me go nuts ?

my prob is:
i have a php page that retrieves data from a form using extract($_POST);
and then correctly adds the data to a database using the usual mysql insert command

problem is:
whenever i insert an item, the data is inserted correctly but there’s an additional empty entry inserted out of nowhere,
i have no clue why or from where

the moment i insert the data into the database, i refresh the phpmyadmin page almost directly and i see my new entry alone , but like another second later, i refresh, and the empty entry is inserted out of nowhere

any idea guys?

to post a comment
PHP

14 Comments(s)

Copy linkTweet thisAlerts:
@bathurst_guyJan 02.2007 — I guess that you are running the mysql query and then error checking the query to see if it inserted. Can you post a block of your PHP around your INSERT statement for us to look at?
Copy linkTweet thisAlerts:
@karxixauthorJan 02.2007 — hello

this is it:

[FONT=Courier New]

extract($_POST);

//there's bunch of code here that outputs the variable on screen in a table

$insert_query = "insert into dogs values('','$name', '$DOB', '$country_en', '$country_fr', '$pedigree', '$full_image_path', '$comment_en', '$comment_fr', '$vendre')";

mysql_query($insert_query);


if (mysql_affected_rows() != 1) {

print "An error occurred";

} else {

print "";

}

[/FONT]




what am doing is having the database open in phpmyadmin ("broswe"), and i refresh to c if the entry was added, but on my 2nd refresh,i see a blank ghost entry out of nowhere

thanks
Copy linkTweet thisAlerts:
@NightShift58Jan 02.2007 — Can you code this right before [b]mysql_query($insert_query);[/b]:[code=php]print "<pre>";
print_r($insert_query);
print "</pre>";[/code]
and share with us what is displayed on screen?

You may have an unlucky combination of characters in one of the variables, which could lead to MySQL believing that you are trying to do a multiple insert.
Copy linkTweet thisAlerts:
@karxixauthorJan 02.2007 — ok,

this is it:

insert into dogs values('','test name', '22/10/1995', 'lebanon', 'liban', 'l.o.s.h', 'ped.jpg','photo.jpg', 'comment, english', 'comment, french', '0')


there was no blank entry afterwrds this time though

it's weird,

i just tried many entries after each other now, and i dont seem to get any blank ones for some reason


ah ok, after some testing again

apparently the blank entry is only appearing when i am not inputting anything in certain fields as in here:

insert into dogs values('','test name1', '22/10/1995', 'lebanon', 'liban', 'l.o.s.h', '','', 'comment, english...', 'comment, french.', '1')

what's the solution to this prob?

and what exactly is causing this to happen?
Copy linkTweet thisAlerts:
@NightShift58Jan 02.2007 — I don't know if this is really causing the problem, but this will not work:[code=php]
insert into dogs values('','test name', '22/10/1995', 'lebanon', 'liban', 'l.o.s.h', 'ped.jpg','photo.jpg', 'comment, english', 'comment, french', '0')[/code]
because they are so-called "unescaped" commas in your values. You will have to use [b]addslashes()[/b] on each variable that is likely to contained "unauthorized" characters before inserting in the database - probably best to do it on all character variables.

In the above code, MySQL thinks you're trying to insert not 11 but 13 fields...

Try that and see what happens.

a+
Copy linkTweet thisAlerts:
@karxixauthorJan 03.2007 — ok

thanks alot

will keep u updated what happens

any explanation on why when all fields are filled there's no problem, but when one is left empty, the prob occurs?
Copy linkTweet thisAlerts:
@NightShift58Jan 03.2007 — No, I can't tell you why this is happening - other than that there's a coding error somewhere.
Copy linkTweet thisAlerts:
@karxixauthorJan 03.2007 — hmm ok

what type of coding error...or what makes u think there's a coding error?

so i can at least know how/where to check for it

thanks
Copy linkTweet thisAlerts:
@NightShift58Jan 03.2007 — It's hard for me to tell from afar. I just know that most inserts don't end up making "ghost entries". I can practically rule out MySQL as the culprit.

That leaves your code or the content of the variables you are trying to insert, which brings us back to your code, unfortunately.

What I do I know is that your SQL looks like this:[code=php] insert into dogs values('','test name', '22/10/1995', 'lebanon', 'liban', 'l.o.s.h', 'ped.jpg','photo.jpg', 'comment, english', 'comment, french', '0')[/code]but it should look like this:[code=php] insert into dogs values('','test name', '22/10/1995', 'lebanon', 'liban', 'l.o.s.h', 'ped.jpg','photo.jpg', 'comment, english', 'comment, french', '0')[/code]
Copy linkTweet thisAlerts:
@karxixauthorJan 03.2007 — alright

many thanks

i will look into this tomorrow afternoon/night as i got an exam before that

and will let you know how it all works out
Copy linkTweet thisAlerts:
@bathurst_guyJan 04.2007 — NightShift58,

a) commas don't need to be escaped (or can you provide me a link to where this is stated otherwise);

b) addslashes() only places backslashes before a single quote ('), double quote ("), backslash () and NUL (the NULL byte) characters, not a comma anyway;

c) you probably should use mysql_real_escape_string() rather than addslashes() for MySQL queries.

karxix would you mind posting your whole code then aswell as the database structure
Copy linkTweet thisAlerts:
@NightShift58Jan 04.2007 — Nightshift...[/quote]You're right. Don't know where my thoughts were.
Copy linkTweet thisAlerts:
@karxixauthorJan 04.2007 — $_POST = array_map('mysql_real_escape_string', $_POST);

i saw this on the php manual,

would it work?


also as a side question, if u use this:

imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

how do i know where the new image is stored, or how can i move it to where i want, rename it...i couldnt easily find that in the manual, thought u can point me out to what to look for (ps: all variables are set right )

thanks
Copy linkTweet thisAlerts:
@aussie_girlJan 05.2007 — If you are not specifying the column names and you are using auto_increment you should

use NULL as the value not ''
[code=php]
insert into dogs values(NULL,'test name', '22/10/1995', 'lebanon', 'liban', 'l.o.s.h', 'ped.jpg','photo.jpg', 'comment, english', 'comment, french')
[/code]
×

Success!

Help @karxix spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...