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
https://forums.phpfreaks.com/topic/252922-some-help-with-this-would-be-great/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.