Jump to content

A Few Questions


elementz

Recommended Posts

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
Share on other sites

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
Share on other sites

[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 lol

for 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
Share on other sites

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
Share on other sites

[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
Share on other sites

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
Share on other sites

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.$udomain
break;
case dom:
$edmn=$domain
break;
};[/code]
Link to comment
Share on other sites

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
Share on other sites

[!--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
Share on other sites

[!--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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.