在home_v.php页面中单击“添加学生”按钮,打开另一个视图页面user_v.php

在home_v.php页面中单击“添加学生”按钮,打开另一个视图页面user_v.php

问题描述:

<html>
<head><head>
<title>Home Page</title>
<body>
<style>
.looks
{
border:1px solid black;
}
</style>
<center><h1>Welcome Students!</h1><br><br></center>
<span style="float: right;">
<a href="<?php echo site_url().'/user_c/logout' ?>">Logout</a>      
</span>
<h2>List of Students in system are : </h2>
<div id="list">
<table class='looks'>
<tr><th>Student Name</th>
<th></th><th></th><th></th></tr>
<?php
    foreach ($list->result() as $row)
    {
    echo "<tr>";
    echo "<td style='width:30%'>".$row->name."</td>";
    echo "<td><input type='submit' value='Add Student' style='float:left' 
    onclick="site_url().'/user_c/add'"></td>";
    echo '<td><input type="submit" value="Update Student" 
    style="float:left"></td>';
    echo '<td><input type="submit" value="Delete Student" 
    style="float:left"></td>';
    echo "</tr>";      
    }
?>
</table>
</div>
</body>
</html>

Parse Error

The foreach loop is executed and the values of student are displayed on the home_v.php page. Besides the names of these students, I have added a button (Add Student).On clicking this button I want to open another view page user_v.php, for which I have used onclick tag in the button. But it is not working and I get the error attached below. Kindly help as what is the mistake I am making.

    //controller
    function add()
    {
        $this->load->view('user_v');
    }

You are making mistake in concatenating PHP and HTML data. And to make it work on the click do following changes:

echo "<td><input type='submit' value='Add Student' style='float:left' 
onclick=window.location='". site_url("user_c/add")."'></td>";