Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Error on wamp while trying to insert data from a form in php

Featured Replies

Hello friends,

 

Dont know why i see this error

 

1-5.jpg

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en">
<head>
<title><?php echo 'How are you';?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="robots" content="all" />




<link rel="stylesheet" href="/templates/uslu_/css/style.css" type="text/css" />

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script src="/links.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">

</script>

</head>
<body>

 <form action="insert.php" method="post">
   First name:<input type="text" name="firstname"/>
Last name:<input type="text" name="lastname"/>
Age:<input type="text" name="age"/>
<input type="submit"/>
 </form>

</body>
</html>


 

insert.php

 

<?php
  $con = mysql_connect("localhost","raj","123");
  if (!$con)
    {
 die('Could not connect:'.mysql_error());
 }
 mysql_select_db("my_db",$con);
 $sql="INSERT INTO Persons (FirstName,LastName,Age)
 VALUES ('$POST[firstname]','$POST[lastname]','$POST[Age]')";
 if (!mysql_query($sql,$con))
 {
 die('Error:'.mysql_error());
 }
 echo "1 record added";

 mysql_close($con)
?>

 

and when i check the persons table i see this just blank records no data?

1-6.jpg

Edited by sash_oo7

The way I do it is to define the variables near the top of the PHP code in the format

$FirstName = ($_POST['firstname']) ;
$LastName = ($_POST['lastname']) ;
$Age = ($_POST['age']) ;

and then code the VALUES differently

VALUES ('$FirstName','$LastName','$Age')";

  • Author

ok i tried this

<?php/*
  $con = mysql_connect("localhost","raj","123");
  if (!$con)
    {
 die('Could not connect:'.mysql_error());
 }
 mysql_select_db("my_db",$con);
 $sql="INSERT INTO Persons (FirstName,LastName,Age)
 VALUES ('$POST[firstname]','$POST[lastname]','$POST[age]')";
 if (!mysql_query($sql,$con))
 {
 die('Error:'.mysql_error());
 }
 echo "1 record added";

 mysql_close($con)
?>*/

<?php
 $FirstName = ($_POST['firstname']) ;
 $LastName = ($_POST['lastname']) ;
 $Age = ($_POST['age']) ;
 mysql_connect("localhost","raj","123");
 mysql_select_db("my_db");
 $query="INSERT INTO Persons (FirstName,LastName,Age)
 VALUES (' $FirstName','$LastName','$Age')";
 mysql_query($query) or die('Error adding records');
 echo "The record that is added is :" .$FirstName. " " .$LastName. " " .$Age. "
?>

 

and i still get error

 

Parse error: syntax error, unexpected $end, expecting T_VARIABLE or T_DOLLAR_OPEN_CURLY_BRACES or T_CURLY_OPEN in C:\wamp\www\php\insert.php on line 29

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.