NameSilo

[Resolved] Very basic Php question

Spaceship Spaceship
Watch

baris22

Established Member
Impact
1
very basic php question

Hello,

I have got this code

PHP:
if($result == '0') {
// 0---
	if(!ctype_alnum($tag)) {
		$info_err_msg = '<div class="info_msg_err">Please make sure that the tags are typed properly (alfa-numeric only).</div>';
	} else {
		mysql_query("INSERT INTO pm_categories SET tag = '".$tag."', name = '".$name."'");
		$info_msg = '<div class="info_msg_ok">Category <b>'.$name.'</b> has been added to the database.</div>';
	}
// 0---
} else {
		$info_msg = '<div class="info_msg_err">The category you submitted is duplicated! The \'TAG\' field must be unique.</div>';
}

}

I do not want to use
PHP:
if(!ctype_alnum

How can i remove it without breaking the code?

thanks
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
baris22 said:
How can i remove it without breaking the code?
I'm not entirely sure what you mean by 'without breaking the code', removing that if statement changes what the code does...

Do you mean this?:
PHP:
if($result == "0")
    { 
        if(ctype_alnum($tag))
            { 
                mysql_query("INSERT INTO pm_categories SET tag = \"{$tag}\", name = \"{$name}\""); 
                $info_msg = "<div class=\"info_msg_ok\">Category <strong>{$name}</strong> has been added to the database.</div>"; 
            } 
    }
else
    { 
        $info_msg = "<div class=\"info_msg_err\">The category you submitted is duplicated! The 'TAG' field must be unique.</div>"; 
    } 

}

You also had one extra '}' at the end - I removed it.
 
Last edited:
0
•••
Thank you for your help,

I do not want to use ctype_alnum on the code. Because i want to display "-" in my tag.

I just want to disaible ctype_alnum but i still want the rest.


thanks

Mikor said:
I'm not entirely sure what you mean by 'without breaking the code', removing that if statement changes what the code does...

Do you mean this?:
PHP:
if($result == "0")
    { 
        if(ctype_alnum($tag))
            { 
                mysql_query("INSERT INTO pm_categories SET tag = \"{$tag}\", name = \"{$name}\""); 
                $info_msg = "<div class=\"info_msg_ok\">Category <strong>{$name}</strong> has been added to the database.</div>"; 
            } 
    }
else
    { 
        $info_msg = "<div class=\"info_msg_err\">The category you submitted is duplicated! The 'TAG' field must be unique.</div>"; 
    } 

}

You also had one extra '}' at the end - I removed it.
 
0
•••
This?
PHP:
if($result == "0")
    { 
        if(!ctype_alnum($tag))
            {
                //$info_err_msg = '<div class="info_msg_err">Please make sure that the tags are typed properly (alfa-numeric only).</div>';
            }
        else
            {
                mysql_query("INSERT INTO pm_categories SET tag = \"{$tag}\", name = \"{$name}\""); 
                $info_msg = "<div class=\"info_msg_ok\">Category <strong>{$name}</strong> has been added to the database.</div>"; 
            } 
    }
else
    { 
        $info_msg = "<div class=\"info_msg_err\">The category you submitted is duplicated! The 'TAG' field must be unique.</div>"; 
    } 

}

Or this?
PHP:
if($result == "0")
    { 
        /*if(!ctype_alnum($tag))
            {
                $info_err_msg = '<div class="info_msg_err">Please make sure that the tags are typed properly (alfa-numeric only).</div>';
            }
        else
            {
                mysql_query("INSERT INTO pm_categories SET tag = \"{$tag}\", name = \"{$name}\""); 
                $info_msg = "<div class=\"info_msg_ok\">Category <strong>{$name}</strong> has been added to the database.</div>"; 
            }*/
    }
else
    { 
        $info_msg = "<div class=\"info_msg_err\">The category you submitted is duplicated! The 'TAG' field must be unique.</div>"; 
    } 

}
 
0
•••
It's presume the following:
(as he probably still wants it to insert into the database.)
PHP:
if($result == "0")
    { 
                mysql_query("INSERT INTO pm_categories SET tag = \"{$tag}\", name = \"{$name}\""); 
                $info_msg = "<div class=\"info_msg_ok\">Category <strong>{$name}</strong> has been added to the database.</div>"; 
            }
    }
else
    { 
        $info_msg = "<div class=\"info_msg_err\">The category you submitted is duplicated! The 'TAG' field must be unique.</div>"; 
    } 
}
 
0
•••
I believe he means:-


PHP:
if($result == '0') {
// 0---
    if(!preg_match('/^[-a-zA-Z0-9]+$/', $tag)) {
        $info_err_msg = '<div class="info_msg_err">Please make sure that the tags are typed properly (alfa-numeric only).</div>';
    } else {
        mysql_query("INSERT INTO pm_categories SET tag = '".$tag."', name = '".$name."'");
        $info_msg = '<div class="info_msg_ok">Category <b>'.$name.'</b> has been added to the database.</div>';
    }
// 0---
} else {
        $info_msg = '<div class="info_msg_err">The category you submitted is duplicated! The \'TAG\' field must be unique.</div>';
}

}
 
Last edited:
0
•••
Waww, thank you very much.
it was exactly what i wanted.

Thank you

Thank you all for the reply.



peter@flexiwebhost said:
I believe he means:-


PHP:
if($result == '0') {
// 0---
    if(!preg_match('/^[-a-zA-Z0-9]+$/', $tag)) {
        $info_err_msg = '<div class="info_msg_err">Please make sure that the tags are typed properly (alfa-numeric only).</div>';
    } else {
        mysql_query("INSERT INTO pm_categories SET tag = '".$tag."', name = '".$name."'");
        $info_msg = '<div class="info_msg_ok">Category <b>'.$name.'</b> has been added to the database.</div>';
    }
// 0---
} else {
        $info_msg = '<div class="info_msg_err">The category you submitted is duplicated! The \'TAG\' field must be unique.</div>';
}

}
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back