Jump to content


simple insert command gone bad (please help!)

  • Please log in to reply
3 replies to this topic

#1 Jutboy420

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 26 February 2006 - 02:50 AM

I'm trying to keep track of all the movies a person votes for via their IP address.

This script inserts the users ip address and the fact they voted for movie 1 by changing the column 1 (signifying movie one) to the number 1 (default = 0 = not voted)...I really want to make the column 1 a variable and really don't want to change using an int as as my column.

$sqlr = "INSERT INTO voters (ip,1) VALUES ('$ip',1)";
mysql_query($sqlr) or die(mysql_error());

all values confirmed....db structure checked.

Please help!! Thank you so much - Justin

#2 AndyB

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

Posted 26 February 2006 - 03:03 AM

Why not just have the two pieces of data represent an IP address and a movie number. If they haven't voted for movie x, then there won't be a record in the table with 'their' IP address and movie number x.
Legend has it that reading the manual never killed anyone.
My site

#3 wickning1

  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 26 February 2006 - 06:33 AM

You're not allowed to name a column with a number. It must start with an alphabet character. Why call it "1"? Why not 'voted' or something like that?

Also your database structure sounds ill-thought out. You have a table for every movie? So every time you add a movie, you add a table to the database? That's not good design.

Why not 3 tables:
movies (id, title, description)
users (id, ipaddress)
votes (userid, movieid)

#4 Jutboy420

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 27 February 2006 - 09:31 PM

I did it AndyB way and it worked fine....your write to columns as numbers...shame shame....

Thanks a heap - Jutboy

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users