Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 1008 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

php adding duplicate data, help needed :)

Thread title: php adding duplicate data, help needed :)
Closed Thread    
    Thread tools Search this thread Display Modes  
02-11-2005, 03:01 PM
#1
DateinaDash is offline DateinaDash
Status: The BidMaster
Join date: Nov 2004
Location: England
Expertise:
Software:
 
Posts: 10,821
iTrader: 0 / 0%
 

DateinaDash is on a distinguished road

  Old  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
patrickPaul is offline patrickPaul
Status:
Join date: Dec 2004
Location: California, US
Expertise:
Software:
 
Posts: 406
iTrader: 1 / 100%
 

patrickPaul is on a distinguished road

Send a message via AIM to patrickPaul Send a message via MSN to patrickPaul Send a message via Yahoo to patrickPaul

  Old

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
DateinaDash is offline DateinaDash
Status: The BidMaster
Join date: Nov 2004
Location: England
Expertise:
Software:
 
Posts: 10,821
iTrader: 0 / 0%
 

DateinaDash is on a distinguished road

  Old

Cheers, i got it working now. Finally, it's actually adding information into the database

02-12-2005, 05:29 PM
#4
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

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
DateinaDash is offline DateinaDash
Status: The BidMaster
Join date: Nov 2004
Location: England
Expertise:
Software:
 
Posts: 10,821
iTrader: 0 / 0%
 

DateinaDash is on a distinguished road

  Old

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
FiveInteractive is offline FiveInteractive
Status: Request a custom title
Join date: Jan 2005
Location: UK
Expertise:
Software:
 
Posts: 1,216
iTrader: 0 / 0%
 

FiveInteractive is on a distinguished road

Send a message via AIM to FiveInteractive Send a message via MSN to FiveInteractive

  Old

Yeah I wondered that, I'd use $_POST['object'] but if it works, it's cool

02-13-2005, 05:06 PM
#7
Travis is offline Travis
Status: Member
Join date: Jul 2004
Location:
Expertise:
Software:
 
Posts: 445
iTrader: 0 / 0%
 

Travis is on a distinguished road

  Old

$_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
FiveInteractive is offline FiveInteractive
Status: Request a custom title
Join date: Jan 2005
Location: UK
Expertise:
Software:
 
Posts: 1,216
iTrader: 0 / 0%
 

FiveInteractive is on a distinguished road

Send a message via AIM to FiveInteractive Send a message via MSN to FiveInteractive

  Old

Ah i see, I guess it was just personal preference of the original writer of the book.

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed