0

i am tryimg to add new row into my table which is the combination of 2 rows i tried writing this code

<html>
    <head>
        <meta charset="UTF-8">
        <title>LoginDB</title>
    </head>
    <body>

        <?php
        $con=  mysqli_connect("localhost", "root", "", "project");

        if(!$con)
       {
           die('not connected');
       }
            $con=  mysqli_query($con, "select frstname,lastname,hello as (frstname+lastname) from registration");

       ?>
        <div>
            <td>Login Page Database</td>
         <table border="1">
            <th> First Name</th>
                    <th>Last Name</th>
                    <th>hello</th>


        <?php

             while($row=  mysqli_fetch_array($con))

             {
                 ?>
            <tr>
                <td><?php echo $row['frstname']; ?></td>
                <td><?php echo $row['lastname']; ?></td>
                <td><?php echo $row['hello']; ?></td>
            </tr>

        <?php
             }
             ?>
             </table>
            </div>
    </body>
</html>

but i am getting an error can any one can rewrite the code if possible or can tell where the error lies.

Dharman
  • 30,962
  • 25
  • 85
  • 135
raj
  • 5
  • 1
  • 6

1 Answers1

1

Your statement throws an syntax error

"select frstname,lastname,hello as (frstname+lastname) from registration"

So you don't get an result set, but false as boolean.

Correct your statement. The part hello as (frstname+lastname) is wrong. Check the mysql-syntax about string concat and using the as alias.

Should be like the following line (assuming the col and table names are correct)

select frstname,lastname, concat(frstname,lastname) as hello from registration
bish
  • 3,381
  • 9
  • 48
  • 69