Total members 11889 |It is currently Thu Mar 28, 2024 1:08 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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.....
Code:

<?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['empno'];?>"></td>
<td align="center"><input name="empname[]" type="text" id="empname" value="<? echo $rows['empname'];?>"></td>
<td align="center"><input name="desig[]" type="text" id="desig" value="<? echo $rows['desig'];?>"></td>
</tr>

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

<?php

// Get values from form 
$no=$_POST['empno'];
$name=$_POST['empname'];
$desig=$_POST['desig'];

// 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['empno'][$i]; 
    $b 
= mysql_real_escape_string( $_POST['empname'][$i] ); 
    $c 
= mysql_real_escape_string( $_POST['desig'][$i] ); 
 
//read the query
 $sql="INSERT INTO '$tbl_name' (empno, empname, desig) VALUES('{$a}', '{$b}', '{$c}')";
 mysql_query($sql) or die(mysql_error());
}
}





Author:
Newbie
User avatar Posts: 7
Have thanks: 0 time

hey ,
this file looks clear , it seems there a cache in your browser or at your server .

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

Looks good.


Author:
Newbie
User avatar Posts: 5
Have thanks: 0 time
Post new topic Reply to topic  [ 3 posts ] 

  Related Posts  to : error in inserting record
 Timeout error while updating record in SQLServer in ASP.NET     -  
 selecting a record randomly from table     -  
 inserting and deleting using php     -  
 inserting and deleting in php     -  
 Inserting video into the game     -  
 ERROR     -  
 Check DNS error     -  
 error in code     -  
 Java error     -  
 Deliberate Error     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com