Values appear not to carry over when posted

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
SoreE yes
Forum Commoner
Posts: 32
Joined: Wed Oct 11, 2006 3:59 am

Values appear not to carry over when posted

Post by SoreE yes »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am a newbee and with little programming experience. I've just installed php and mysql and they seem to work fine. When submitting a form however, whilst mysql monitor shows that a new row is added, no values appear in the field columns. Is there a problem with the installation or am I making a simple mistake with the code below? I'm using Dreamweaver to write the code. Thanking you in advance.

[b]Enter Fruits[/b]
[syntax="html"]<html>
<head>
<title>Enter Fruits</title>
</head>
<h1>Enter Fruits</h1>

<body>
<form id="form1" name="form1" method="post" action="ActionEnterFruits.php">
  <label>name
  <input type="text" name="name" />
  </label>
  <label>colour
  <input type="text" name="colour" />
  </label>
  <p>
    <label>Submit
    <input type="submit" name="Submit" value="Submit" />
Action Enter Fruits[/syntax]

Code: Select all

<html>
<head>
<title>Add Data</title>
</head>

<body>

<?php require_once('Connections/Fruits.php');
echo "the colour is...".$colour;
$adddata = "INSERT INTO fruits(name, colour)
		VALUES('$name','$colour')";
$result = mysql_query($adddata);

?>

<h2> Thank you, we have added the data to the database</h2><BR />

<a href="enter fruits.html">click here to return to enter page


</body>
</html>
    </label>
  </p>
</form>

</body>
</html>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Try putting:

Code: Select all

$colour = $_POST['colour'];
$name = $_POST['name'];
At the top of your PHP script.

Regards,
SoreE yes
Forum Commoner
Posts: 32
Joined: Wed Oct 11, 2006 3:59 am

It's worked

Post by SoreE yes »

That's worked a treat. Many thanks.
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

All I did was create the variable.

If you ever want to pass data over from a HTML form you need to do the following:

In the PHP form, whether you're using POST or GET method:

Code: Select all

$callThisWhatYouWant = $_POST['theNameOfTheHTMLField'];
Hope this helps for the future.

Regards,
Post Reply