Jump to content

Recommended Posts

Ok so I've got my script that I'm working on that is basically a rating system for movies for my friends to post ratings on. Now the problem that I can't figure out is this:

 

$insert_movie = mysql_query("INSERT INTO movie (num, title) VALUES ('$num', '$title')");

$insert_movie = mysql_query("INSERT INTO members (username, movies) VALUES ('$myusername', '$num,')");

if($rate != '0') {

$insert_movie = mysql_query("INSERT INTO members (rate) VALUES ('$rate,')");

$insert_movie = mysql_query("INSERT INTO movie (rate) VALUES ('$rate,')");

}

 

Alright what I need it to do though, is when it tries to insert it into the members instead of making a new row I need it to add to the row that under the column "username" is the variable "$myusername".

Link to comment
https://forums.phpfreaks.com/topic/150027-solved-adding-to-a-mysql-row/
Share on other sites

Take a look at UPDATE in your Mysql manual

 

or consider doing just one insert to members and one insert to movies:

INSERT INTO members (username, movies,rate) VALUES ('$myusername', '$num', '$rate')");

INSERT INTO movies (num,title,rate) VALUES ('$num', '$title', '$rate')");

 

Though you should really normalise this database properly, or how will two different members rate the same movie?

Though you should really normalise this database properly, or how will two different members rate the same movie?

Umm, I'm still working on this. This is actually the first site I have ever made...ever. So I'm still learning quite a bit. This particular code is to add a new movie to the database, but when I program the page to add existing movies to your profile it will be different.

 

I'll check out update right now.

 

[EDIT]

So I read over it, and it looked like it should be set like this? but it didn't work.

$insert_movie = mysql_query("INSERT INTO movie (num, title, rate) VALUES ('$imdb', '$title', '$rate,')");
$insert_movie1 = mysql_query("UPDATE members SET rate = '$rate' WHERE username = '$myusername'");

hmmm, looks ok to me, put this at the end of your update statement like so

 

$insert_movie1 = mysql_query("UPDATE members SET rate = '$rate' WHERE username = '$myusername'") or die(mysql_error());

 

Then you should get some sort of error that will help discern the problem, post the error here if you can't figure it out yourself.

 

Another tip:

 

I notice that when you run your mysql query's, you're always putting the result into the $insert_movie variable.

 

like this:

 

$insert_movie = mysql_query("INSERT INTO movie (num, title, rate) VALUES ('$imdb', '$title', '$rate,')");

 

It's not required, you don't need to put it into a variable, it'll run just fine without like this.

 

mysql_query("INSERT INTO movie (num, title, rate) VALUES ('$imdb', '$title', '$rate,')");

 

You only ever need to put the result of a mysql_query() in a variable if you're doing a SELECT statement and want to then read through the results.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.