inserting data into table using PHP
Posted by: Jan (---.sympatico.ca)
Date: June 22, 2006 05:29AM

----------------------- insert.htm -------------------------
<html>
<head>
<title>test</title>
</head>
<body>
<form action="insert.php" method="get">
<input type="text" name="fname">
<input type="submit" value="submit">
</form>
</body>
</html>

-------- config-sendrec.php -------------
<?php
// This is an example of config.php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'sendrec';
$table='sender'
?>
----------------insert.php------------------
<?php
include 'config-sendrec.php';
include 'opendb-sendrec.php';
$fname=$_get[fname];
mysql_select_db("sendrec"winking smiley or die(mysql_error());
$query = "INSERT INTO sender VALUES ($fname)";
mysql_query($query);
include 'closedb.php';
?>

--------------------------------------------------

After I click on Submit button, I went to check the sender table in MYSQL. I only see ID number with NULL on the FNAME column. It seems that everything that I enter has ID # created with NULL value instead of the name. How do I make this inserting data into my table work? Can you please help. Thank you very much.

Options: ReplyQuote
Re: inserting data into table using PHP
Posted by: CyberSpatium (67.170.181.---)
Date: June 24, 2006 08:35AM

change:
$fname=$_get[fname];

to
$fname=$_get['fname'];

and then change
$query = "INSERT INTO sender VALUES ($fname)";

to
$query = "INSERT INTO sender (fname) VALUES ($fname)";

Options: ReplyQuote
Re: inserting data into table using PHP
Posted by: administrator (---.sympatico.ca)
Date: June 25, 2006 05:27AM

Thanks for responding to my problem, unfortunately, I did that already and did not work.

I even tried with $_post - no luck

I even did the following just to make sure the name get passed into variable:

echo "your name is: $fname";

I got blank


Though if I change the:

$query = "INSERT INTO sender VALUES ($fname)";

into

$query = "INSERT INTO sender (fname) VALUES ('Richard')";


then check the table in MYSQL prompt, It got through.


Please help.

Thank you

Options: ReplyQuote
Re: inserting data into table using PHP
Posted by: roms (---.fbx.proxad.net)
Date: June 25, 2006 10:22AM

It's $_POST and not $_post (case sensitive).

Now since your data is a string it should be with quotes in your query so

$query = "INSERT INTO sender VALUES ('$fname')";



Romain

Options: ReplyQuote
Re: inserting data into table using PHP
Posted by: Jan (---.sympatico.ca)
Date: June 26, 2006 04:55AM

THANK YOU, THANK YOU, THANK YOU, THANK YOU. IT WORKED !!!! Thank you for spending your time in reading and resolving my problem. THANK YOU. I am a PHP beginner, what can I say. THANK YOU VERY MUCH.

Options: ReplyQuote


Sorry, only registered users may post in this forum.