Jump to content

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