Jump to content

Archived

This topic is now archived and is closed to further replies.

elementz

A Few Questions

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

Share this post


Link to post
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.

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
[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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[a href=\"http://www.w3schools.com/sql/sql_delete.asp\" target=\"_blank\"]http://www.w3schools.com/sql/sql_delete.asp[/a]

Orio.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
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.

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
1) Yes, every form needs a submit button to continue.
2) * means everything/all
3) Yes, it'll work.

Orio.

Share this post


Link to post
Share on other sites
[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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
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{
};

Share this post


Link to post
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]

??

Share this post


Link to post
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\" /]

Share this post


Link to post
Share on other sites

×

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.