gibigbig Posted June 26, 2007 Share Posted June 26, 2007 i need to input a "nickname" a "email" and a "password" if the nickname is "admin" or "gibigbig" then i want it to show a certain text "hello admin to your site" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script> <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" /> </head> <body> <form id="form1" name="form1" method="post" action="process.php"> <label> Nickname:<span id="sprytextfield3"> <input type="text" name="nickname" id="nickname" /> <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span> </label> <p>password:<label><span id="sprytextfield1"> <input type="password" name="password" id="password" /> <span class="textfieldRequiredMsg">Cannot be empty</span></span></label> </p> <p>email: <label><span id="sprytextfield2"> <input type="text" name="email" id="email" /> <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></label> </p> <input type="submit" /> </form> <script type="text/javascript"> <!-- var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "none", {validateOn:["change"]}); var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "email"); var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "custom", {validateOn:["change"]}); //--> </script> </body> </html> i have the form and it works fine but i need a "process.php" to make the code work. i tried putting a code together here: <?php $nickname = $_POST['nickname']; $password = $_POST['password']; $email = $_POST ['email']; if $nickname='admin'; { echo"hello admin"}; else{ echo "hello ".$nickname."!"}; } ?> but it doesnt work, i also want to use an array to hold the words "admin' and "gibigbig" to display the "Hello admin, welcome to your site" can anyone help me out? Link to comment https://forums.phpfreaks.com/topic/57330-need-help-with-a-form-code/ Share on other sites More sharing options...
pocobueno1388 Posted June 26, 2007 Share Posted June 26, 2007 Change this: <?php if $nickname='admin'; { echo"hello admin"}; else{ echo "hello ".$nickname."!"}; } ?> To: <?php if ($nickname == 'admin') { echo "hello admin"; }else{ echo "hello ".$nickname."!"; } ?> Link to comment https://forums.phpfreaks.com/topic/57330-need-help-with-a-form-code/#findComment-283427 Share on other sites More sharing options...
gibigbig Posted June 26, 2007 Author Share Posted June 26, 2007 sorry, still doesnt work, i dont know whats wrong Link to comment https://forums.phpfreaks.com/topic/57330-need-help-with-a-form-code/#findComment-283442 Share on other sites More sharing options...
per1os Posted June 26, 2007 Share Posted June 26, 2007 <?php $nickname = $_POST['nickname']; $password = $_POST['password']; $email = $_POST['email']; // there was an extra space here removed it. if ($nickname == 'admin') { echo"hello admin"}; else{ echo "hello ".$nickname."!" } // extra semi-colon here removed //extra } here but removed. ?> Syntax errors galore I suggest you add error_reporting(E_ALL); at the very top when debugging a script to show errors.... Link to comment https://forums.phpfreaks.com/topic/57330-need-help-with-a-form-code/#findComment-283447 Share on other sites More sharing options...
marcus Posted June 26, 2007 Share Posted June 26, 2007 <?php $nickname = $_POST['nickname']; if($nickname){ $ara = array('admin','gibigbig'); if(in_array($nickname,$ara)){ echo "Hello Admin\n"; }else { echo "Hello $nickname\n"; } }else { echo "Nickname is not defined\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/57330-need-help-with-a-form-code/#findComment-283449 Share on other sites More sharing options...
corillo181 Posted June 26, 2007 Share Posted June 26, 2007 it should work maybe you doing something else wrong the code he gave you to change makes it work .. Link to comment https://forums.phpfreaks.com/topic/57330-need-help-with-a-form-code/#findComment-283450 Share on other sites More sharing options...
pocobueno1388 Posted June 26, 2007 Share Posted June 26, 2007 Frost - You missed a bracket on this line echo"hello admin"}; Change to: echo "hello admin"; Link to comment https://forums.phpfreaks.com/topic/57330-need-help-with-a-form-code/#findComment-283451 Share on other sites More sharing options...
per1os Posted June 26, 2007 Share Posted June 26, 2007 I did, I also missed a semi-colon, try this out: <?php $nickname = $_POST['nickname']; $password = $_POST['password']; $email = $_POST['email']; // there was an extra space here removed it. if ($nickname == 'admin') { echo"hello admin"; else{ echo "hello ".$nickname."!"; } // extra semi-colon here removed //extra } here but removed. ?> Either way, basic syntax errors. Learn the basics before you dive head deep into coding. Link to comment https://forums.phpfreaks.com/topic/57330-need-help-with-a-form-code/#findComment-283456 Share on other sites More sharing options...
gibigbig Posted June 26, 2007 Author Share Posted June 26, 2007 yea sorry, i had an extra <?php tag betwwen my code and i now spotted it. yup im an noob trying to follow a tutorial. tnx for the code frost, thats exactly what i want Link to comment https://forums.phpfreaks.com/topic/57330-need-help-with-a-form-code/#findComment-283459 Share on other sites More sharing options...
pocobueno1388 Posted June 26, 2007 Share Posted June 26, 2007 Don't forget to solve the topic. -shakes head- We really need to get that button more visible, hah. Link to comment https://forums.phpfreaks.com/topic/57330-need-help-with-a-form-code/#findComment-283460 Share on other sites More sharing options...
gibigbig Posted June 26, 2007 Author Share Posted June 26, 2007 <?php $nickname = $_POST['nickname']; if($nickname){ $ara = array('admin','gibigbig'); if(in_array($nickname,$ara)){ echo "Hello Admin\n"; }else { echo "Hello $nickname\n"; } }else { echo "Nickname is not defined\n"; } ?> why did u use the \n" is this an escape fromthe quotes? Link to comment https://forums.phpfreaks.com/topic/57330-need-help-with-a-form-code/#findComment-283470 Share on other sites More sharing options...
pocobueno1388 Posted June 26, 2007 Share Posted June 26, 2007 "\n" is the new line character in PHP. Link to comment https://forums.phpfreaks.com/topic/57330-need-help-with-a-form-code/#findComment-283471 Share on other sites More sharing options...
gibigbig Posted June 26, 2007 Author Share Posted June 26, 2007 the last echo statement is not used because i made it required through a javascript text field. if i remove he echo statement, will it fudge upt he code, seeing thats its in an if() function Link to comment https://forums.phpfreaks.com/topic/57330-need-help-with-a-form-code/#findComment-283475 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.