|
|
|
|
Thread title: php adding duplicate data, help needed :) |
|
|
|
|
|
Thread tools
Search this thread
Display Modes
|
|
02-11-2005, 03:01 PM
|
#1
|
Status: The BidMaster
Join date: Nov 2004
Location: England
Expertise:
Software:
Posts: 10,821
|
php adding duplicate data, help needed :)
Hey everyone, i have a script and for some reason it's adding the same information twice (even though i'm submitting it only once via a form).
Please review my code and see where i'm going wrong! Thanks
$type=$HTTP_POST_VARS['type'];
$price=$HTTP_POST_VARS['price'];
$bedrooms=$HTTP_POST_VARS['bedrooms'];
$location=$HTTP_POST_VARS['location'];
if (!$type || !$price || !$bedrooms || !$location)
{
echo 'You have not entered all the required details.<br />'
.'Please go back and try again.';
exit;
}
$db = mysql_pconnect('localhost', 'talkfreelance', 'password');
if (!$db)
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
mysql_select_db('talkfreelance_com_-_3') or die(mysql_error());
$query = "INSERT INTO property VALUES ('', '$type','$price','$bedrooms','$location')";
mysql_query($query);
$result = mysql_query($query) or die(mysql_error());
if ($result)
echo mysql_affected_rows().' property inserted into database.';
?>
|
|
|
02-11-2005, 03:15 PM
|
#2
|
Status:
Join date: Dec 2004
Location: California, US
Expertise:
Software:
Posts: 406
|
Easy Rob
You're running the query twice:
mysql_query($query);
$result = mysql_query($query) or die(mysql_error());
|
Regards,
Patrick
|
|
02-11-2005, 03:23 PM
|
#3
|
Status: The BidMaster
Join date: Nov 2004
Location: England
Expertise:
Software:
Posts: 10,821
|
Cheers, i got it working now. Finally, it's actually adding information into the database
|
|
02-12-2005, 05:29 PM
|
#4
|
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
Posts: 3,820
|
Randomish question, but why HTTP_POST_VARS rather than _POST? Or are you learning from a reasonably "old" book?
|
|
02-12-2005, 05:40 PM
|
#5
|
Status: The BidMaster
Join date: Nov 2004
Location: England
Expertise:
Software:
Posts: 10,821
|
Yeah, I have been using a book that i purchased about a year ago. It was based on php 4 so it's not upto date as such. However, it's a decent read and i'm learning quite abit from it!
|
|
02-13-2005, 12:47 AM
|
#6
|
Status: Request a custom title
Join date: Jan 2005
Location: UK
Expertise:
Software:
Posts: 1,216
|
Yeah I wondered that, I'd use $_POST['object'] but if it works, it's cool
|
|
02-13-2005, 05:06 PM
|
#7
|
Status: Member
Join date: Jul 2004
Location:
Expertise:
Software:
Posts: 445
|
$_POST['object'] was acceptable in php 4. I think the book I have used both methods because it was a few years old but maybe in the third edition or something.
|
|
02-13-2005, 07:46 PM
|
#8
|
Status: Request a custom title
Join date: Jan 2005
Location: UK
Expertise:
Software:
Posts: 1,216
|
Ah i see, I guess it was just personal preference of the original writer of the book.
|
|
|
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|