Jump to content


Photo

A Few Questions


  • Please log in to reply
21 replies to this topic

#1 elementz

elementz
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 20 June 2006 - 09:10 AM

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

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 20 June 2006 - 09:19 AM

For the MySQL question:
$sql="SELECT * FROM `emails` WHERE email='$email'";
$result=mysql_query($sql);
if(mysql_num_rows($result)==0){$continue=TRUE;}
else{$continue=FALSE;};



For drop downs:
HTML code:
<form action="something.php" method="POST">
<select name="something">
<option value="1">1
<option value="2">2
<option value="3">3
</select>
</form>

PHP code (something.php):
$var = $_POST['something'];


Orio.
Think you're smarty?

(Gone until 20 to November)

#3 elementz

elementz
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 20 June 2006 - 09:23 AM

if(mysql_num_rows($result)==0){
"create account"
}
else{
account error
};

that would work? but change the create account and account error to PHP language lol

for the select thing, could i do this.

$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
}

Would that work?

#4 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 20 June 2006 - 09:27 AM

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:
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;
};

[img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

Orio.
Think you're smarty?

(Gone until 20 to November)

#5 elementz

elementz
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 20 June 2006 - 09:35 AM

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;
};

but how do I define case? example: like say that the drop down has three choice: free, paid, trial would I use the following?

switch($var){
case free:
echo("You selected free");
break;
case paid:
echo("You selected paid");
break;
case trial:
echo("You selected trial");
break;
};


#6 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 20 June 2006 - 09:38 AM

Yep :)

Orio.
Think you're smarty?

(Gone until 20 to November)

#7 elementz

elementz
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 20 June 2006 - 10:01 AM

if(mysql_num_rows($result)==0){
"create account"
}
else{
account error
};

do I need to make this

if(mysql_num_rows($result)==0) then {
"create account"
}
else{
account error
};


#8 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 20 June 2006 - 10:17 AM

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.
Think you're smarty?

(Gone until 20 to November)

#9 elementz

elementz
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 20 June 2006 - 10:22 AM

How do I delete something from the database?

#10 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 20 June 2006 - 10:25 AM

[a href=\"http://www.w3schools.com/sql/sql_delete.asp\" target=\"_blank\"]http://www.w3schools.com/sql/sql_delete.asp[/a]

Orio.
Think you're smarty?

(Gone until 20 to November)

#11 elementz

elementz
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 20 June 2006 - 10:31 AM

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?

#12 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 20 June 2006 - 10:34 AM

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):
<form action="page3.php" method="post">
....
<input type="hidden" name="username" value="<?php echo $_POST['user']; ?>">
etc'

And then on page3.php you can get the vars from page1 who were passed to page2:
$user=$_POST['username'];


But you can use sessions too.

Orio.
Think you're smarty?

(Gone until 20 to November)

#13 elementz

elementz
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 20 June 2006 - 10:46 AM

Do I need to end the form and have a submit button?

Also why does this have a *?

SELECT * FROM contacts

also would this work or are the two variables together wrong?

switch($var){
case subd:
$edmn=$domain.$udomain
break;
case dom:
$edmn=$domain
break;
};


#14 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 20 June 2006 - 10:53 AM

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

Orio.
Think you're smarty?

(Gone until 20 to November)

#15 elementz

elementz
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 20 June 2006 - 11:05 AM

$sql="SELECT * FROM `domain` WHERE email='$edmn'";
$result=mysql_query($sql);
if(mysql_num_rows($result)==0){

}
else{

};

what could I do to make the script continue if the domain wasnt found in the database?


#16 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 20 June 2006 - 11:15 AM

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.
Think you're smarty?

(Gone until 20 to November)

#17 elementz

elementz
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 20 June 2006 - 11:21 AM

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?

#18 elementz

elementz
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 20 June 2006 - 11:33 AM

also can you do more than 1 mysql search at once like:


$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{
};

#19 elementz

elementz
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 20 June 2006 - 12:34 PM

[!--quoteo(post=385967:date=Jun 20 2006, 09:33 PM:name=elementz)--][div class=\'quotetop\']QUOTE(elementz @ Jun 20 2006, 09:33 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
also can you do more than 1 mysql search at once like:


$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]

??

#20 elementz

elementz
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 20 June 2006 - 09:44 PM

please help someone :D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users