Pages (2):    1 2
Member
Member
Sabyre   02-09-2010, 19:05
#21

OK, cool... So I can do...

$tags = $_POST['tags']; $newtag = explode(",", $tags); foreach($newtag){
for the comma seperated tags.

and....

if (strcasecmp($newtag, $row['name']) == 0) {
for the case insensitive comparison?

Administrator
Administrator
acrylian   02-09-2010, 19:09
#22

foreach($newtag as $something) { of course.

I think it might be better to use strtolower() before checking as you otherwise might accidentally store double ones in the database later as you have still the value with the case difference.

Member
Member
kagutsuchi   02-09-2010, 19:17
#23

Good point; I didn't think of that. Whether it's faster to use strtolower() or strcasecmp() + array_unique(), I'm not sure, but strtolower() is probably easier.

Member
Member
sbillard   02-09-2010, 19:26
#24

Also you might wish to have code that will deal with user input strings that might wish to include commas in their tag. (Or you could just tell them that is not allowed.)

Administrator
Administrator
acrylian   02-09-2010, 19:31
#25

I think normally tags are used as "keywords" and rarely include a comma. Of course a more rarely used ; could be used as a delimiter as well or a |.

Member
Member
Sabyre   02-09-2010, 20:37
#26

foreach($newtag as $something)
Does that mean I have to reference $newtag as $something anywhere else in the loop? Does it change the variable?

Would it be better to use

while($newtag = >0) {

Member
Member
sbillard   02-09-2010, 20:51
#27

You probalby need to review your PHP syntax. http://www.php.net/manual/en/control-structures.foreach.php

Administrator
Administrator
acrylian   03-09-2010, 08:52
#28

Also I get a little the impression that you should learn a few more php basics before proceeding. This forum is of course not for learning these...

Member
Member
Sabyre   09-09-2010, 21:53
#29

Understood, I know enough php/mysql to get me in trouble and I have enough tenacity to get what I want. I work at something and learn as I go until it has the desired effect.

I created this on my own and it works fabulously:

`

Member
Member
Sabyre   09-09-2010, 22:52
#30

oops, for my purposes i will need to write something that checks if the folder exists....

Member
Member
Sabyre   09-09-2010, 23:02
#31

Got it...

added:
`
$sqlalbumid = mysql_query("SELECT id, folder FROM zp_albums WHERE folder ='" . $album . "'");
$albumid = mysql_fetch_array( $sqlalbumid );
if (strcasecmp($album, $albumid['folder']) 0) {
echo "Album folder " .$album. " does NOT exist, please check the spelling.";
}

else {
`

Member
Member
kagutsuchi   10-09-2010, 00:04
#32

Two notes:

The code you posted is not secure. You really should be sanitizing anything that comes through $_POST. It's probably also not safe against XSRF attacks, though I'm not too familiar with that subject.

I see a lot of mysql_query() in your code; it's probably better to compile one long query in your code and then, at the end, actually query the database. (I don't really have experience with databases, but I'm speaking from a coding standpoint.)

Pages (2):    1 2
  
Powered By MyBB, © 2002-2026 MyBB Group.
Made with by Curves UI.