Total members 10262 | Gratitudes |It is currently Thu May 24, 2012 5:16 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 3 posts ] 
Author Question
 Question subject: error in inserting record
PostPosted: Wed Aug 17, 2011 6:11 am 
Offline
Newbie
User avatar

Joined: Tue Aug 09, 2011 12:50 pm
Posts: 7
Has thanked: 0 time
Have thanks: 0 time

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());
}
}


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: error in inserting record
PostPosted: Sat Aug 20, 2011 4:54 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time
hey ,
this file looks clear , it seems there a cache in your browser or at your server .

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: error in inserting record
PostPosted: Tue Dec 20, 2011 3:29 pm 
Offline
Newbie
User avatar

Joined: Sun Dec 12, 2010 4:37 pm
Posts: 8
Has thanked: 0 time
Have thanks: 0 time
Looks good.


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 3 posts ] 
Quick reply


  

 Similar topics
 HELP :Novel error tolerant method AES for satelite imgaes
 ERROR
 error closing file matlab save
 error in code
 AJAX SYNTAX ERROR IE
 Java download error
 inserting and deleting in php
 inserting and deleting using php
 tell the meaning of the error
 Java error

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 3 guests



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team