0

hi all i have been inserting records in to database using php using the below program which is saved as "insert.php".
but it is displaying the following error
Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\insert1.php on line 18

dont no what went wrong.
can u tell me how to solve it.....
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="emp"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

// Count table rows
$count=mysql_num_rows($result);

<?php
while($rows=mysql_fetch_array($result))
{
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="y" /></td>
<td align="center"><input name="empno[]" type="text" id="name" value="<? echo $rows;?>"></td>
<td align="center"><input name="empname[]" type="text" id="empname" value="<? echo $rows;?>"></td>
<td align="center"><input name="desig[]" type="text" id="desig" value="<? echo $rows;?>"></td>
</tr>

<?php
}
?>
<input type="submit" name="Submit" value="Submit">

<?php

// Get values from form
$no=$_POST;
$name=$_POST;
$desig=$_POST;

// Check if button name "Submit" is active, do this
if(array_key_exists('Submit', $_POST))
{
for($i=0;$i<count($count);$i++)
{
//protect form sql injection
$a = (int) $_POST[$i];
$b = mysql_real_escape_string( $_POST[$i] );
$c = mysql_real_escape_string( $_POST[$i] );
//read the query
$sql="INSERT INTO '$tbl_name' (empno, empname, desig) VALUES('{$a}', '{$b}', '{$c}')";
mysql_query($sql) or die(mysql_error());
}
}

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by decade
0

<?PHP tag is not required at line 18 in your file, you are already in php tag.

<?PHP
.
.
.
.
.
// Count table rows 
$count=mysql_num_rows($result);

/////*************<?php THIS TAG IS NOT REQUIRED***************

while($rows=mysql_fetch_array($result))
{

?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="y" /></td>
.
.
.
.

Edited by urtrivedi: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.