Hello, I am newb with php
I got a strange message error, that is:

Notice: Use of undefined constant y - assumed 'y' in /home/www/healthforum.uib.no/htdocs/ohcsurvey/survey/sp1.php on line 139

I am making a survey where the user , by cliking radio buttons, can choose between yes or no to a question. for example:

<u>Do you agree or not?</u><br/>
<b><input type="radio" name="c1" value="y" />I do <br/>
<input type="radio" name="c1" value="n" />I don't</b>

(the forms are not on the same page but are linked to it properly)
The yes is transformed by 1 and the no is transformed by 0 with this code:

139)  if ($a1 == y) { $a1 = 1; } 
140)  else { $a1 = 0; }
141)						
142)  if ($b1 == y) { $b1 = 1; } 
143)  else { $b1 = 0; }
144)						
145)  if ($c1 == y) { $c1 = 1; } 
146)  else { $c1 = 0; }
						
147)  if ($d1 == y) { $d1 = 1; } 
148)  else { $d1 = 0; }
						
						
													
153)  // put it in the db
				
157)  $insertInf = "UPDATE survey SET a1 = '$a1', b1 = '$b1', c1 = 158)  '$c1',d1 = '$d1'
159)  WHERE username = '$username'";
160)  $ins = mysql_query($insertInf) or die('Erreur: Vos donnees 161)  ne nous sont pas parvenues');
							
162)  header ('Location:sp2.php');

Although the error, I got the result without problem in my database.
However, It prevents me from going to the next page of the survey as this warning attests:

Warning: Cannot modify header information - headers already sent by (output started at /home/www/healthforum.uib.no/htdocs/ohcsurvey/survey/sp1.php:142) in /home/www/healthforum.uib.no/htdocs/ohcsurvey/survey/sp1.php on line 162

Could you help me with this ?

y should be in quotes, it's a string

y should be in quotes, it's a string

oh! stupid me!
Thanks

Use of undefined constant password - can someone help me

<?php
$username =@$_POST['username'];
$password = @$_POST['password'];
if($username&&password)
{
$connect = mysql_connect("localhost","root","") or ("Couldn't connect!");
mysql_select_db("phplogin") or die ("Couldn't find db");

$query = mysql_query("Select * FROM users WHERE username='$username'");

$numrow= mysql_num_rows($query);
if ($numrow!=0)
{

while($row = mysql_fetch_assoc($query))
{
$dbusername = @$row['username'];
$dbpassword = @$row['password'];
}
if($username==$dbusername&&$password==$dbpassword)

{
  echo("You are in!");
}s
else
    echo ("Incorrect password!");
}
else
     die ("That user doesn't exist!");


}
else
echo ("Please enter a username and a password!");
?>

thnx but now it show this

Parse error: syntax error, unexpected 'else' (T_ELSE) in C:\xampp\htdocs\site 2\login.php on line 33

nothing was my mistake thnx you are awesome :)

<?php
echo "<h1>Register</h1>";
$submit = @$_POST['submit'];
$fullname = strip_tags (@$_POST['fullname']);
$username = strip_tags (@$_POST["username"]);
$password = md5(strip_tags (@$_POST['password']));
$repeatpassword = md5(strip_tags (@$_POST['repeatpassword']));
$date = (Y-m-d);
if ($submit)
{
if ($fullname&&$username&&$password&&$repeatpassword)
if ($password==$repeatpassword)
{
//check char length of username and fullname
if (strlen($username)>25||strlen ($fullname)>25)
{
echo ("Length of username or fullname is too long!");
}
else
{
// check password length
if (strlen($password)>25||strlen ($password)<6)
echo ("Password must be betwwen  6 and 25 characters");
}
else
{
//register the user!

// encrypt password
$password = md5 ($password);
$repeatpassword = md5 ($repeatpassword);
echo ("Succes!!");
}
}
}
else 
echo ("Your passwords do not match!");
}
else
echo ("Please fill in<b>all</b>fields!");
// register the user!
echo ("Success!");
}
}
}
else
echo("Your password do not match!");
echo $username."<br>".$fullname;
}
?>

Parse error: syntax error, unexpected 'else' (T_ELSE) in C:\xampp\htdocs\site 2\register.php on line 33

it show me this
Parse error: syntax error, unexpected 'else' (T_ELSE) in C:\xampp\htdocs\site 2\register.php on line 33

the proper syntax for else is:

else { ... } <- you need open and closing brackets just like an if statement.

thnx but how i can fix this??

Look at your code very carefully, like lines 36, 39, and 46, and see if you formatted things correctly. Is the else followed by a {

i have done all the 3 else with {} but it show me unexpected else again

delete the closing bracket on line 35 and i think youre good.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.