Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 17th, 2011, 12:55 AM
Authorized User
Points: 223, Level: 4
Points: 223, Level: 4 Points: 223, Level: 4 Points: 223, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jul 2011
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Default error in inserting record

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.....
$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";

// Count table rows

<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>

<input type="submit" name="Submit" value="Submit">


// Get values from form

// Check if button name "Submit" is active, do this
if(array_key_exists('Submit', $_POST))
//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());
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
check existence of a record in a database before inserting a new record ibmkahm ASP.NET 4 General Discussion 1 November 15th, 2010 03:44 AM
Help with Inserting new record with detailsview gsrai31 ASP.NET 2.0 Basics 0 November 23rd, 2008 06:29 PM
How do I check a db before inserting a record? Lucy SQL Server ASP 3 April 25th, 2005 10:47 PM
Inserting A Record Set nikotromus Access VBA 3 September 14th, 2004 01:23 PM
Select record after inserting it whyulil Classic ASP Databases 13 April 26th, 2004 06:05 AM

All times are GMT -4. The time now is 05:11 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.