vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Need help with form in HTML (https://vborg.vbsupport.ru/showthread.php?t=106194)

Jaynesh 01-24-2006 02:11 PM

Need help with form in HTML
 
Im lerning php and just experimenting and messing around with a few stuff.

Ive written this code in dreamweaver ( Thanx for you tutorial MindTrix, https://vborg.vbsupport.ru/showthrea...ghlight=elseif ) :)

Heres the code:

Code:

<?php

$name = "Jaynesh";

if ( $name == "Bob" )

{

print "Yes my name is $name";

}
elseif ( $name == "Johnny" )
{
print "Yes, My name is Johnny";
}
elseif ( $name == "Mark" )
{
print "Yes, My name is mark";
}
elseif { $name == "Sarah" )
{
print "Yes, My name is sarah";
}
else {
print "No, My name is $name";
}
?>

How can i make it so i can select a name from a form instead of manually putting it in the php file.

e.g Imagine there is a form on a page, and when the user types the name Mark it will say Yes, My name is mark And if a user types a name which is not coded in the form it will say No, My name is Jaynesh.

harmor19 01-24-2006 02:38 PM

let's say you had a form with the field
<input type="text" name="username" />


Use this code

PHP Code:

<?php
$names 
= array('Andrew''John''Mark');
if( 
in_array($_POST['username'], $names) )
{
    echo 
"Yes, my name is ".$_POST['username'].""

else
{
   echo 
"No, my name is ".$_POST['username']."";
}
?>


Jaynesh 01-24-2006 03:12 PM

Cheers :) worked great :)

Cole2026 01-26-2006 01:11 AM

Quote:

Originally Posted by Jaynesh
Im lerning php and just experimenting and messing around with a few stuff.

Ive written this code in dreamweaver ( Thanx for you tutorial MindTrix, https://vborg.vbsupport.ru/showthrea...ghlight=elseif ) :)

Heres the code:

Code:

<?php

$name = "Jaynesh";

if ( $name == "Bob" )

{

print "Yes my name is $name";

}
elseif ( $name == "Johnny" )
{
print "Yes, My name is Johnny";
}
elseif ( $name == "Mark" )
{
print "Yes, My name is mark";
}
elseif { $name == "Sarah" )
{
print "Yes, My name is sarah";
}
else {
print "No, My name is $name";
}
?>

How can i make it so i can select a name from a form instead of manually putting it in the php file.

e.g Imagine there is a form on a page, and when the user types the name Mark it will say Yes, My name is mark And if a user types a name which is not coded in the form it will say No, My name is Jaynesh.

I know this isn't what you asked, but for future reference you should use the case and switch commands in case of an if that long.
PHP Code:

<?php

$name 
"Jaynesh";

switch ( 
$name )
{
   case 
"Bob":
   case 
"Johnny":
   case 
"Mark":
   case 
"Sarah":
       print 
"Yes, My name is $name";
       break;
   default:
       print 
"No, My name is $name";
}
?>


Jaynesh 01-26-2006 06:43 AM

Okay thankyou :)

How will i use that with a form?


All times are GMT. The time now is 11:16 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01753 seconds
  • Memory Usage 1,729KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (2)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete