MoFish Posted April 20, 2006 Share Posted April 20, 2006 [!--sizeo:5--][span style=\"font-size:18pt;line-height:100%\"][!--/sizeo--][b]PROBLEM SOLVED[/b][!--sizec--][/span][!--/sizec--]hey. heres the scenario. I would like to check if a username already exists on the registration section of my website and would also like to check if a thread is created with the same name on another section. im unsure exactly how I go around looping through the rows checking for a matching value and flagging the error up if found. does anyone mind showing me how this is done with some dummy variables and i'll give it a go for myself?thanks again, mofish.[!--sizeo:5--][span style=\"font-size:18pt;line-height:100%\"][!--/sizeo--][b]PROBLEM SOLVED[/b][!--sizec--][/span][!--/sizec--] Quote Link to comment Share on other sites More sharing options...
wisewood Posted April 20, 2006 Share Posted April 20, 2006 [code]<?php// something like this...// when form is submitted// query the db for matching data$check = "SELECT * FROM your_table WHERE title = $_POST[title]";$result = mysql_query($check);// if it exists, do one thingif($result==1){ echo "An entry with this name already exists, please try something else";}// if it doesnt exist, do something else.else { echo "No entry exists, so we can continue"; }?>[/code] Quote Link to comment Share on other sites More sharing options...
predator12341 Posted April 20, 2006 Share Posted April 20, 2006 or you could do[code]<?php// something like this...// when form is submitted// query the db for matching data$check = "SELECT * FROM your_table WHERE title = $_POST[title]";$result = mysql_query($check);$num = mysql_num_rows($result);if($num >=1){ do your first thing} else{ do something else}?>[/code] Quote Link to comment Share on other sites More sharing options...
wisewood Posted April 20, 2006 Share Posted April 20, 2006 thats what i said... Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 20, 2006 Share Posted April 20, 2006 No, what you said was to check the $result from the mysql_query() call which will probably not be the correct thing to do. When there are no rows to be returned by the query, the call returns a pointer to an empty set.On the other hand, [b]predator12341[/b] checks the number of rows returned by the mysql_query() call.Ken Quote Link to comment Share on other sites More sharing options...
predator12341 Posted April 20, 2006 Share Posted April 20, 2006 [!--quoteo(post=366826:date=Apr 20 2006, 03:09 PM:name=wisewood)--][div class=\'quotetop\']QUOTE(wisewood @ Apr 20 2006, 03:09 PM) [snapback]366826[/snapback][/div][div class=\'quotemain\'][!--quotec--]thats what i said...[/quote]sort of but not fullyand yep well said ken :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.