elementz Posted June 20, 2006 Share Posted June 20, 2006 How do you check the MySql database to see if something has already been inputed. For example an email, Check if $email is in the database. Also I want to know how to use select on forms, I know the tags, but don't know how to configure it for what they choose. All help will be appreciated.Thankyou,Luke Link to comment https://forums.phpfreaks.com/topic/12448-a-few-questions/ Share on other sites More sharing options...
Orio Posted June 20, 2006 Share Posted June 20, 2006 For the MySQL question:[code]$sql="SELECT * FROM `emails` WHERE email='$email'";$result=mysql_query($sql);if(mysql_num_rows($result)==0){$continue=TRUE;}else{$continue=FALSE;};[/code]For drop downs:HTML code:[code]<form action="something.php" method="POST"><select name="something"><option value="1">1<option value="2">2<option value="3">3</select></form>[/code]PHP code (something.php):[code]$var = $_POST['something'];[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/12448-a-few-questions/#findComment-47573 Share on other sites More sharing options...
elementz Posted June 20, 2006 Author Share Posted June 20, 2006 [code]if(mysql_num_rows($result)==0){"create account"}else{account error};[/code]that would work? but change the create account and account error to PHP language lolfor the select thing, could i do this.[code]$var = $_POST['something'];if (var == 1){you chose car 1}else if (var == 2){you chose car 2}else (var == 3){you chose car 3}[/code]Would that work? Link to comment https://forums.phpfreaks.com/topic/12448-a-few-questions/#findComment-47576 Share on other sites More sharing options...
Orio Posted June 20, 2006 Share Posted June 20, 2006 Yes to both :) But you cant have "else (var == 3)". Else is executed if the if's and elseif's conditions were false. So it has no condition itself.But just a suggestion:on the drop downs, use the "Switch" statement instead of if and alot of elseif:[code]switch($var){case 1:echo("You selected option 1");break;case 2:echo("You selected option 2");break;case 3:echo("You selected option 3");break;};[/code][img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]Orio. Link to comment https://forums.phpfreaks.com/topic/12448-a-few-questions/#findComment-47578 Share on other sites More sharing options...
elementz Posted June 20, 2006 Author Share Posted June 20, 2006 [code]switch($var){case 1:echo("You selected option 1");break;case 2:echo("You selected option 2");break;case 3:echo("You selected option 3");break;};[/code]but how do I define case? example: like say that the drop down has three choice: free, paid, trial would I use the following?[code]switch($var){case free:echo("You selected free");break;case paid:echo("You selected paid");break;case trial:echo("You selected trial");break;};[/code] Link to comment https://forums.phpfreaks.com/topic/12448-a-few-questions/#findComment-47580 Share on other sites More sharing options...
Orio Posted June 20, 2006 Share Posted June 20, 2006 Yep :)Orio. Link to comment https://forums.phpfreaks.com/topic/12448-a-few-questions/#findComment-47583 Share on other sites More sharing options...
elementz Posted June 20, 2006 Author Share Posted June 20, 2006 [code]if(mysql_num_rows($result)==0){"create account"}else{account error};[/code]do I need to make this[code]if(mysql_num_rows($result)==0) then {"create account"}else{account error};[/code] Link to comment https://forums.phpfreaks.com/topic/12448-a-few-questions/#findComment-47587 Share on other sites More sharing options...
Orio Posted June 20, 2006 Share Posted June 20, 2006 if(mysql_num_rows($result)==0){echo('Great! You may register now. Click <a href="create.php">here</a> to create your account.');}else{echo("Sorry, email already in use.");};Orio. Link to comment https://forums.phpfreaks.com/topic/12448-a-few-questions/#findComment-47592 Share on other sites More sharing options...
elementz Posted June 20, 2006 Author Share Posted June 20, 2006 How do I delete something from the database? Link to comment https://forums.phpfreaks.com/topic/12448-a-few-questions/#findComment-47594 Share on other sites More sharing options...
Orio Posted June 20, 2006 Share Posted June 20, 2006 [a href=\"http://www.w3schools.com/sql/sql_delete.asp\" target=\"_blank\"]http://www.w3schools.com/sql/sql_delete.asp[/a]Orio. Link to comment https://forums.phpfreaks.com/topic/12448-a-few-questions/#findComment-47596 Share on other sites More sharing options...
elementz Posted June 20, 2006 Author Share Posted June 20, 2006 Also, how do I carry on variables. Say I had the form on one page and then on the other page I had something, but how do I get the variable on a third page without the use of mysql? Link to comment https://forums.phpfreaks.com/topic/12448-a-few-questions/#findComment-47599 Share on other sites More sharing options...
Orio Posted June 20, 2006 Share Posted June 20, 2006 First page is a normal form.Second page will have all of it's fields and everything, but add this to the form (change it as you like):[code]<form action="page3.php" method="post">....<input type="hidden" name="username" value="<?php echo $_POST['user']; ?>">etc'[/code]And then on page3.php you can get the vars from page1 who were passed to page2:[code]$user=$_POST['username'];[/code]But you can use sessions too.Orio. Link to comment https://forums.phpfreaks.com/topic/12448-a-few-questions/#findComment-47601 Share on other sites More sharing options...
elementz Posted June 20, 2006 Author Share Posted June 20, 2006 Do I need to end the form and have a submit button?Also why does this have a *?[code]SELECT * FROM contacts[/code]also would this work or are the two variables together wrong?[code]switch($var){case subd:$edmn=$domain.$udomainbreak;case dom:$edmn=$domainbreak;};[/code] Link to comment https://forums.phpfreaks.com/topic/12448-a-few-questions/#findComment-47602 Share on other sites More sharing options...
Orio Posted June 20, 2006 Share Posted June 20, 2006 1) Yes, every form needs a submit button to continue.2) * means everything/all3) Yes, it'll work.Orio. Link to comment https://forums.phpfreaks.com/topic/12448-a-few-questions/#findComment-47607 Share on other sites More sharing options...
elementz Posted June 20, 2006 Author Share Posted June 20, 2006 [code]$sql="SELECT * FROM `domain` WHERE email='$edmn'";$result=mysql_query($sql);if(mysql_num_rows($result)==0){}else{};[/code]what could I do to make the script continue if the domain wasnt found in the database? Link to comment https://forums.phpfreaks.com/topic/12448-a-few-questions/#findComment-47611 Share on other sites More sharing options...
Orio Posted June 20, 2006 Share Posted June 20, 2006 You mean there's no row where the email field is $edmn?It'll execute the if part, because the number of rows will be 0.Orio. Link to comment https://forums.phpfreaks.com/topic/12448-a-few-questions/#findComment-47613 Share on other sites More sharing options...
elementz Posted June 20, 2006 Author Share Posted June 20, 2006 can i just leave the if part blank and the else part an error in it. will it continue the script if I leave the if part blank? Link to comment https://forums.phpfreaks.com/topic/12448-a-few-questions/#findComment-47614 Share on other sites More sharing options...
elementz Posted June 20, 2006 Author Share Posted June 20, 2006 also can you do more than 1 mysql search at once like:[code][/code]$sql="SELECT * FROM `emails` WHERE email='$email'"; "SELECT * FROM `domain` WHERE email='$edmn'"; "SELECT * FROM `user` WHERE email='$user'";$result=mysql_query($sql);if(mysql_num_rows($result)==0){}else{}; Link to comment https://forums.phpfreaks.com/topic/12448-a-few-questions/#findComment-47620 Share on other sites More sharing options...
elementz Posted June 20, 2006 Author Share Posted June 20, 2006 [!--quoteo(post=385967:date=Jun 20 2006, 09:33 PM:name=elementz)--][div class=\'quotetop\']QUOTE(elementz @ Jun 20 2006, 09:33 PM) [snapback]385967[/snapback][/div][div class=\'quotemain\'][!--quotec--]also can you do more than 1 mysql search at once like:[code][/code]$sql="SELECT * FROM `emails` WHERE email='$email'"; "SELECT * FROM `domain` WHERE email='$edmn'"; "SELECT * FROM `user` WHERE email='$user'";$result=mysql_query($sql);if(mysql_num_rows($result)==0){}else{};[/quote]?? Link to comment https://forums.phpfreaks.com/topic/12448-a-few-questions/#findComment-47633 Share on other sites More sharing options...
elementz Posted June 20, 2006 Author Share Posted June 20, 2006 please help someone :D Link to comment https://forums.phpfreaks.com/topic/12448-a-few-questions/#findComment-47799 Share on other sites More sharing options...
zq29 Posted June 20, 2006 Share Posted June 20, 2006 [!--quoteo(post=385967:date=Jun 20 2006, 12:33 PM:name=elementz)--][div class=\'quotetop\']QUOTE(elementz @ Jun 20 2006, 12:33 PM) [snapback]385967[/snapback][/div][div class=\'quotemain\'][!--quotec--]also can you do more than 1 mysql search at once like:[code][/code]$sql="SELECT * FROM `emails` WHERE email='$email'"; "SELECT * FROM `domain` WHERE email='$edmn'"; "SELECT * FROM `user` WHERE email='$user'";$result=mysql_query($sql);if(mysql_num_rows($result)==0){}else{};[/quote]I'm not sure, but one thing I am sure of, it will take less than two minutes to find out [img src=\"style_emoticons/[#EMO_DIR#]/wink.gif\" style=\"vertical-align:middle\" emoid=\":wink:\" border=\"0\" alt=\"wink.gif\" /] Link to comment https://forums.phpfreaks.com/topic/12448-a-few-questions/#findComment-47805 Share on other sites More sharing options...
elementz Posted June 21, 2006 Author Share Posted June 21, 2006 what u mean by that? Link to comment https://forums.phpfreaks.com/topic/12448-a-few-questions/#findComment-47940 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.