Jump to content


Photo

Need Help With SHopping Cart


  • Please log in to reply
24 replies to this topic

#21 Clandestine

Clandestine

    * Forum Police *

  • Members
  • PipPipPip
  • 833 posts
  • Gender:Male
  • Location:Redondo Beach, CA

Posted 08 March 2006 - 12:39 AM

this is what the table code that i used for the prints table is

CREATE TABLE prints (
print_id INT(4) UNSIGNED NOT NULL AUTO INCREMENT,
artist_id INT(3) UNSIGNED NOT NULL, 
print_name VARCHAR(60) NOT NULL,
price decimal(6,2) NOT NULL,
size VARCHAR(60) defualt NULL,
description VARCHAR(225) defualt NULL,
image_name VARCHAR(30) defualt NULL,
PRIMARY KEY (print_id),
KEY artist_id (artist_id),
KEY print_name (print_name)
);

so that is what i used for the prints table, should i add AUTO_INCREMENT to the print name?

thanks again and sorry for the double post

-Devyn

#22 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 08 March 2006 - 11:16 AM

You can only have one auto_increment column per table, which is why they had it the way it was (now that i see the table, i realise that).
So, what you can do is use mysql to handle the inserting of the id for you. Just change:
$query = "INSERT INTO prints
(artist_id, print_name, price,
size, description, image_name)
VALUES ('$a', '$pn', $p, '$s',
'$d', '$i')";
if ($result = @mysql_query ($query)) {
echo '<p>The print has been added.</p>';
} else {
echo '<p><font color="red"> Your submission could not be processed due to a system error.</font></p>';
}

// To

if(mysql_query("INSERT INTO prints (print_name, price, size, description, image_name) VALUES ('$pn', $p, '$s', '$d', '$i')")){
	if(mysql_query("INSERT INTO prints (artist_id) VALUES (LAST_INSERT_ID())")){
		echo '<p>The print has been added.</p>';
	}else{
		echo '<p><span style="color:red;">Your submission could not be processed due to a system error.</span><br>'.mysql_error().'</p>';
	}
}else{
	echo '<p><span style="color:red;"> Your submission could not be processed due to a system error.</span><br>'.mysql_error().'</p>';
}
It's not the cleanest example, and i'm not 100% sure it will work (as i've never dealt with last_insert_id), but you can find more info here: http://dev.mysql.com...-unique-id.html

Edited by rc69, 08 March 2006 - 11:21 AM.


#23 Clandestine

Clandestine

    * Forum Police *

  • Members
  • PipPipPip
  • 833 posts
  • Gender:Male
  • Location:Redondo Beach, CA

Posted 08 March 2006 - 01:29 PM

thanks rc69 for all your help so far, ill give that a try once i get home,

thanks again

-Devyn

EDIT
---------------

na, it does the same thing

The file has been uploaded.
string(7) "test 01" string(3) ".99" int(0) pn:
p:
a:

Please click "back" and try again.


man, what a book that gives you error codes :)

-Devyn

Edited by Stu, 09 March 2006 - 10:22 AM.


#24 Stu

Stu

    Retired P2L Staff

  • Publishing Betazoids
  • PipPipPipPip
  • 1,761 posts
  • Gender:Male

Posted 09 March 2006 - 10:21 AM

clandestine, you have been asked once by rc69 to stop double posting and use the edit button instead, so please stop bumping your topic and just edit your previous post.

#25 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 09 March 2006 - 04:33 PM

Remove $a from the if-statement, and don't work out of books <_<
I learnt php through tutorials on this site, and php.net.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users