Reputation:
this code all works fine except for I get an undefined variable warning 'message' and I cant figure out a way to define it as it is not a post or session variable or anything that. Thanks
<?php
if (isset($_POST['submit']))
{
$newemail = $_POST['newemail'];
$repeatnewemail = $_POST['repeatnewemail'];
$email= ($_SESSION['email']);
$message="";
//open database
if (condition)
{
$message="first message";
}
}
?>
<p td class='td2'><?php echo $message;?></td>
Upvotes: 0
Views: 94
Reputation: 7247
Put the $message="";
outside the condition.
$message="";
if (isset($_POST['submit'])){
$newemail = $_POST['newemail'];
$repeatnewemail = $_POST['repeatnewemail'];
$email= ($_SESSION['email']);
//open database
if (condition){
$message="first message";
}
}
?>
<p td class='td2'><?php echo $message;?></td>
Upvotes: 6
Reputation: 1085
The error you are getting is because you have not defined $message.
$message = ""
if (isset($_POST['submit']))
{
$newemail = $_POST['newemail'];
$repeatnewemail = $_POST['repeatnewemail'];
$email= ($_SESSION['email']);
//open database
if (condition)
{
$message="first message";
}
}
?>
<p td class='td2'><?php if(isset($message)) echo $message;?></td>
Upvotes: 1
Reputation: 4578
declare $message on top :-
$message = ""
if (isset($_POST['submit']))
{
$newemail = $_POST['newemail'];
$repeatnewemail = $_POST['repeatnewemail'];
$email= ($_SESSION['email']);
//open database
if (condition)
{
$message="first message";
}
}
?>
<p td class='td2'><?php if(isset($message)) echo $message;?></td>
Upvotes: 2
Reputation: 6420
$message=null;
if (isset($_POST['submit']))
{
$newemail = $_POST['newemail'];
$repeatnewemail = $_POST['repeatnewemail'];
$email= ($_SESSION['email']);
$message="";
//open database
if (condition)
{
$message="first message";
}
}
?>
<p td class='td2'><?php if(isset($message)) echo $message;?></td>
Upvotes: 1