please correct the below query. i want to display variable value to textbox using echo command.
variable can have both null and non null values.

<td>First Party*:</td><td><input type="text" name="firstparty" value="<?php echo is_null($firstparty)? "":$firstparty;?>"/></td>

error message

error message:<br /><b>Notice</b>:  Undefined variable: firstparty in <b>C:\xampp\htdocs\claim\claimform.php</b> on line <b>134</b><br />none.      However issue is observed when the form gets loaded (first time/reset time

Note:if $firstpartyis not null then it is working fine meaning vlaue is getting displayed.

      However issue is observed when the form gets loaded (first time/reset time

$firstparty is not defined? Can I see the rest of your code? You're theory is correct as you can do this:

<?php
   $firstparty = "Enter here";
?>

<td>First Party*:</td><td><input type="text" name="firstparty" value="<?php echo is_null($firstparty)? "":$firstparty;?>"/></td>

Sure ,here you go. Thanks in advance

    <?php        
            SESSION_start();
              if(!isset($_SESSION['email']))
                {

                echo"access denied";
                exit;
                }
                else{
              $name=$_SESSION['name'];
              $email=$_SESSION['email'];


              }

              ?>


<?php

if(isset($_POST['submit']))
{

$co=$_POST['co'];
$num=$_POST['num'];
$status=$_POST['status'];
$reason=$_POST['reason'];
$firstparty=$_POST['firstparty'];
$secondparty=$_POST['secondparty'];
$partyemail=$_POST['partyemail'];
$type=$_POST['type'];
$idate=$_POST['idate'];
$pm=$_POST['pm'];

$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state'];
$pin=$_POST['pin'];
$phone=$_POST['phone'];


$con=mysqli_connect("localhost","root","","shri");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$sql=("insert into claim(num,firstparty,secondparty,partyemail,type,pm,co,status,reason,address,city,state,pin,phone,idate ) values('$num','$firstparty','$secondparty','$partyemail','$type','$pm','$co','$status','$reason','$address','$city','$state','$pin','$phone','$idate')" );

if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error($con));
  }
echo "Claim is created successfully. Please work on the same.";

mysqli_close($con);




}

elseif(isset($_POST['submitsearch']))
{
$num=$_POST['num'];

mysql_connect("localhost","root","","shri");
mysql_select_db("shri");
$sql="select * from claim where num='$num'";

                $result=mysql_query($sql)or die(mysql_error()) ;
                                               while($row = mysql_fetch_array($result))
                                                {   
                                                $firstparty= $row['firstparty'] ;
                                                $num=$row['num'];

                                                }





}else
{
}

?>





<html>

               <head>
              <link rel= "stylesheet"  type="text/css" href="claimform.css" ></link>
              </head>

            <body>
                      <div id= "head">


                      </div>


                     <div id="info" align="center">
                            <form  action=""     method="post">

                                <table>
                                <tr>
                                <td>Claim Number*:</td><td><input type="text" name="num"/></td>

                                <td>Claim Status:</td><td><input type="" name="status"/></td>
                                <td>Claim Reason:</td><td><select name="reason">
                                                                        <option>over speed</option>
                                                                        <option>careless Driving</option>
                                                                        <option>bad weather</option>
                                                                        <option selected="true">trafic rule violation</option>

                                                                </select>

                               </td>
                              </tr>

                                <tr>
                                <td>First Party*:</td><td><input type="text" name="firstparty" value="<?php echo is_null($firstparty)? "":$firstparty;?>"/></td>

                                <td>Second Party:</td><td><input type="text" name="secondparty"/></td>

                                <td>Party Email*:</td><td><input type="text" name="partyemail"/></td>
                                </tr>



                                <tr>
                                <td>Policy Type:</td><td><input type="radio" name="type" value="vehicle" checked>Vehicle </input>


                                     <input type="radio" name="type" value="health">Health</input></td>

                                <td>Created Date:</td><td><input type="text" name="idate" value="<?php echo date("Y/m/d") ;?>" readonly/></td>

                                    <td>Payment Method:*</td><td><select name="pm">
                                                                        <option>cash Payment</option>
                                                                        <option> account Pay Cheque</option>
                                                                        <option>ifsc transfer</option>
                                                                        <option selected="true">gift card</option>

                                                                </select>

                                    </td>                

                                </tr>


                                <tr>

                                <td>Claim officer:</td><td><input type="text" name="co" value="<?php echo $name;?>" readonly/></td>

                                <td>phone Number:</td><td><input type="text" name="phone"/></td>


                                <td>Address Line :</td><td><input type="text" name="address"/></td>
                                </tr>
                                <tr>
                                <td>City:</td><td> <input type="text" name="city"/></td>

                                <td>State:</td><td><input type="text" name="state"/></td>



                                 </tr>


                                 <tr>
                                 <td></td>
                                 <td>
                                 <input type="submit" name="submit" value="Submit Claim"/>
                                 <input type="submit" name="reset" value="New Claim"/>
                                 <input type="submit" name="submitsearch" value="search"/>


                                 </td>
                                 </tr>
                                 </table>    
                               </form>       

                               <form  action="list_serviceproviders.php" method="POST" >
                               <input type="submit" name="submit1" value=" ADD Service Provider"/>

                               </form>



</div>


                           <div id= "footer">
                            All rights reserved;
                           </div>





               </body>

</html>

Up to line 57 you are using mysqli, after that mysql, possible problem there?

Member Avatar for diafol

As mentioned, on page load, $firstparty does not exist, so testing it for values will throw an error.

As opposed to showing a message on page load, I'd use a zero-length string (''), so that you could use the html5 placeholder.

<?php
    $fp = (isset($firstparty) && !is_null($firstparty)) ? $firstparty : '';
?>

<td>First Party*:</td><td><input type="text" name="firstparty" value="<?php echo fp;?>" placeholder="Enter first party" /></td>

shortly:
<td>First Party*:</td><td><input type="text" name="firstparty" value="<?=(isset($firstparty)&&!is_null($firstparty))?$firstparty:"";?>"/></td>

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.