Jump to content

need help with a form code


gibigbig

Recommended Posts

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

<?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....

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.

<?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?

Archived

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

×
×
  • Create New...

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.