Jump to content

need help in insert query


doforumda

Recommended Posts

hi i need help in the following code

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>Untitled Document</title>

</head>

 

<body>

<form name="form1" method="post" action="insert.php">

  <label>First Name:

  <input type="text" name="fname" id="fname">

  </label>

  <p>

    <label>Last Name:

    <input type="text" name="lname" id="lname">

    </label>

  </p>

  <p>

    <label>Address:

    <input type="text" name="address" id="address">

    </label>

  </p>

  <p>

    <label>Phone:

    <input type="text" name="phone" id="phone">

    </label>

  </p>

  <p>

    <label>

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

    </label>

</p>

</form>

</body>

</html>

 

above is my form

and below is my php code

 

<?php

$db = mysql_connect("localhost","username","password");

mysql_select_db("example",$db);

$query = "insert into example(fname, lname, address, phone) values('".$fname."','".$lname."','".$address."','".$phone."')" or die(mysql_error());

$result = mysql_query($query) or die(mysql_error());

 

echo "data entered";

?>

 

when i insert something using that form it displays following error

 

 

Notice: Undefined variable: fname in C:\wamp\www\New Folder\insert.php on line 12

 

Notice: Undefined variable: lname in C:\wamp\www\New Folder\insert.php on line 12

 

Notice: Undefined variable: address in C:\wamp\www\New Folder\insert.php on line 12

 

Notice: Undefined variable: phone in C:\wamp\www\New Folder\insert.php on line 12

data entered

 

how can i solve this problem

Link to comment
https://forums.phpfreaks.com/topic/155330-need-help-in-insert-query/
Share on other sites

ok i ll use those tags next time

can please make changes in above code

I could adjust your script so it does what it is suppose to do. However this forum is intended as help and not a "can you fix this for me" forum.  I am very willingly to point you in the right direction and say whether you are on the right track but fixing this thing is up to you.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.