Jump to content

Some help with this would be great


itzjmoco

Recommended Posts

I haven't done much php in the past few years so i am a little rusty. Please keep that in mind when helping

 

Ok so what i am trying to do is build a favorite script for part of my site so a user can favorite different things.

 

So this is the add favorite page when a user clicks the link i am trying to get it to pull some of the info from one table then add it to a different one then also adds some new data as well that is not getting pulled from a table.

 

This is the table i am trying to pull some of the data from:

CREATE TABLE IF NOT EXISTS `anime_info` (
  `id` bigint(20) NOT NULL auto_increment,
  `title` varchar(255) NOT NULL,
  `alternative_title` varchar(255) NOT NULL,
  `image` varchar(255) NOT NULL,
  `synopsis` text NOT NULL,
  `date` varchar(60) NOT NULL,
  `user_name` varchar(60) NOT NULL,
  `userid` varchar(60) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

 

i am trying to pull title and image and move it to the following table

CREATE TABLE IF NOT EXISTS `favorites` (
  `id` bigint(20) NOT NULL auto_increment,
  `anime_id` bigint(20) NOT NULL,
  `anime_title` varchar(255) NOT NULL,
  `image` varchar(255) NOT NULL,
  `user_name` varchar(60) NOT NULL,
  `userid` varchar(60) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

 

then as for the new data i need to add:

$anime_id = mysql_escape_string($_GET['anime_id']);
$user_name = mysql_escape_string($userdata['username']);
$userid = mysql_escape_string($userdata['user_id']);

 

Here is my latest php script so far i have tried so many ways.

<?PHP

// Import form information
$anime_id = mysql_escape_string($_GET['anime_id']);
$user_name = mysql_escape_string($userdata['username']);
$userid = mysql_escape_string($userdata['user_id']);

// Insert info into database
$insert_query="INSERT INTO favorites (anime_title,image) SELECT anime_info.title,anime_info.image FROM anime_info WHERE 
id='".mysql_escape_string($_GET['anime_id'])."'";

    mysql_query($insert_query);

    $update_query="UPDATE `favorites` SET `anime_id`='$anime_id',`user_name`='$user_name',`userid`='$userid' WHERE `id`='".mysql_escape_string($_GET['anime_id'])."'";

    mysql_query($update_query);

    echo "Anime added to your favorites <meta http-equiv=\"refresh\" content=\"2; url=/viewfavorites.php\" />";

?>

 

In this code i can get the insert query to work fine but not update.

the links look like favorite.php?anime_id=1

 

NOTE: $userdata is being pull else where and thats all working fine.

Link to comment
Share on other sites

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.