Gossamer Forum
Home : General : Internet Technologies :

insert problem

Quote Reply
insert problem
hello, i'm new here and i suprise suprise, i'm new to Php too.

I'm havin a problem inserting some simple data into a mysql database using php.

Here is my form

<HTML>
<HEAD>
<TITLE> HTML form </TITLE>
</HEAD>
<BODY>
<FORM METHOD=POST ACTION="handleform.php">
Firstname<INPUT TYPE="text" NAME="Array[Firstname]" size=20><BR>
Lastname<INPUT TYPE="text" NAME="Array[Lastname]" size=40><BR>
EmailAddy<INPUT TYPE="text" NAME="Array[Emailaddress]" size=60><BR>
Your Comments<TEXTAREA NAME="Array[Comments]" ROWS=5 COLS="40"></TEXTAREA>
<INPUT TYPE="submit" Name="submit" value="Submit your details!">
</FORM>
</BODY>
</HTML>



and heres my php form :

<?php
/* This page recieves and handles the information from Form.html */

$Array["Firstname"] = trim
($Array["Firstname"]);
$Array["Lastname"] = trim
($Array["Lastname"]);
$Array["Emailaddress"] = trim
($Array["Emailaddress"]);
$Array["Comments"] = trim
($Array["Comments"]);

// Set the variables for the database access:
$host = "localhost";
$user = "Redeemer";
$password = "";
$dbname = "yourComments2";
$stuff = "Feedback";

$Link = mysql_connect ($host, $user, $password);

$Query = "INSERT into $stuff values ('0', '$Array[Firstname]', '$Array[Lastname]', '$Array[Emailaddress]', '$Array[Comments]')";

print ("$array[Firstname]");
print ("The query is:<BR>$Query<p>\n");

if (mysql_db_query ($dbname, $Query, $Link)) {
print ("Your information has been updated =;0)<BR>\n");
} else {
print ("Your information has not been updated<BR>\n");
}
mysql_close ($Link);
?>



heres the result:

The query is:
INSERT into Feedback values ('0', '', '', '', '')

Your information has been updated =;0)



Any ideas??

Redz^Sly
Quote Reply
Re: [Redz^] insert problem In reply to
Would help if you posted in the right forum too (Internet Technologies). Maybe a mod could move this Wink

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Redz^] insert problem In reply to
Regarding your problem. You seem to be going around it the wrong way. You should not really be using an array. Something like this would do;

Firstname<INPUT TYPE="text" NAME="Firstname" size=20><BR>

Then to grab that value, use something like;

global $_POST;

$FirstName = $_POST['Firstname'];

You may want to read up on arrays, to see why yours is not working. I don't think it is as simple as you seem to think Tongue

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] insert problem In reply to
Thanks Andy, you really helped, I'm a noov, wont post here again!