how to fix this bug

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
barnes529
Forum Newbie
Posts: 17
Joined: Thu Apr 19, 2007 4:18 am

how to fix this bug

Post by barnes529 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


please help me.i unable to find the following error in code 
Parse error: parse error in c:\easyphp1-8\www\insert.php on line 13
my column names in mysql(db_user)(person)
firstname
lastname
age

[syntax="html"]<html>
<body>
<form name=frmname" method="post" action="insert.php" enctype="multipart/form-data">
<table border="0" wodth=200 height=200 align="center">
<tr><td>Firstname</td><td><input type="text" name="fname"></td></tr>

<tr><td>Lastname</td><td><input type="text" name="lname"></td></tr>

<tr><td>age</td><td><input type="text" name="age"></td></tr>


<tr colspan="2"><td align="center"><input type="submit" value="submit"></td></tr>
</table>
</body>
</html>
insert.php[/syntax]

Code: Select all

<?php
 $con=mysql_connect("localhost","root","");
 if(!$con)
{
 die("connection error:".mysql_error());
}
 else
{
 mysql_select_db("db_user",$con);
$qry="INSERT INTO person(firstname,lastname,age)VALUES('$_POST[fname]','$_POST[lname]','$_POST[age]')
if(!mysql_query($qry,$con));
{
 die("connection error:".mysql_error());
}

echo "record is added";
mysql_close($con);
}
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Please use the php tags provided to assist in reading code. Also it would be useful if you point out line 13.

One problem you will have is the following:

Code: Select all

$qry="INSERT INTO person(firstname,lastname,age)VALUES('$_POST[fname]','$_POST[lname]','$_POST[age]')
You have no closing quote or semicolon.
In addition to get array variables into strings you need to either concatenate them or put them in squiggly brackets...

Code: Select all

//Concatenation
$qry="INSERT INTO person(firstname,lastname,age) VALUES ('".$_POST['fname']."','".$_POST['lname']."','".$_POST['age']."')";

Code: Select all

// Squggly (My preferred)
$qry="INSERT INTO person(firstname,lastname,age) VALUES ('{$_POST['fname']}','{$_POST['lname']}','{$_POST['age']}')";
You should also note that array indexes should also be quoted (avoids a notice warning).
Post Reply