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? Quote Link to comment 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."!"; } ?> Quote Link to comment 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 Quote Link to comment 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.... Quote Link to comment 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"; } ?> Quote Link to comment 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 .. Quote Link to comment 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"; Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.