MySQL in php problems -
what trying check if name exists in database code not work adds existing user 1 time again instead of saying "name exists". going wrong? give thanks you
$sql=mysql_query("select arms (name, email, mesurement) name = $users_name"); if(mysql_num_rows($sql)>=1) { echo"name exists"; } else { $query = " insert `arms` ( `name` , `email` , `mesurement` ) values ( '$users_name', '$users_email', '$users_mesurement' );"; mysql_query($query); }
i see 3 things wrong right away:
you're not selecting anything. need select from..., if it's select * from... or select name from... otherwise that's syntax error. (it looks set select clause after from clause reason. try: select name, email, measurement arms where...
you don't wrap single-quotes around string in where clause: where name = $users_name should where name = '$users_name'
your code wide open sql injection attacks. please prepare that.
php mysql
No comments:
Post a Comment