Jump to content

how to fix this bug


barnes

Recommended Posts

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

 

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

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

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

 

<tr colspan="2"><td align="center"><input type="submit" value="submit"></td></tr>

</table>

</body>

</html>

 

insert.php

<?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);

}

?>

Link to comment
Share on other sites

you're missing a quote and a semicolon at the end of $qry

 

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

 

if you still have problems, change it to this

 

$first = $_POST['fname'];
$last = $_POST['lname'];
$age = $_POST['age'];

$qry="INSERT INTO person(firstname,lastname,age)VALUES('$first','$last','$age');

Link to comment
Share on other sites

Also, this will not do what you want it to:

 

if(!mysql_query($qry,$con));
{
die("connection error:".mysql_error());
}

 

You must remove the ";" at the end of the first line I copied and pasted.  Otherwise the die() will execute every time, regardless of if the query succeeds or fails.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.