Jump to content

Running a function through html form


Drayen

Recommended Posts

Sorry if I'm wording this wrong, here's my problem:

 

The form:

 

<html>

<head>

<title>Product Update</title>

</head>

<body>

 

<form action="index.php" method="get">

Product: <input name="product" type="text" />

Starting Price: <input name="price" type="text" />

<br />

Description: <input name="description" type="text" />

<input type="submit">

</form>

 

</body>

</html>

 

Part of the php file:

 

function add()

{

 

$AAA = new AAA("Product", $_GET["product"], $_GET["price"], "images/unknown.jpg", $_GET["description"]);

 

echo '<img src="'. $AAA->GetPhoto() .'" align="left" />';

echo '<b>'. $AAA->GetName() .'</b>: '. $AAA->GetModel();

echo '<p>Starting from: '. $ipod->GetPrice() .'</p>';

echo '<p>'. $AAA->GetDescription() .'</p>';

}

 

Basically I don't want the fucntion add to execute unless it's being triggered by coming from the form page, so how would I go about doing this? Right now I just have the function add() above and it runs but that means it runs even when I'm not coming from the form site.  Any help would be appreciated.

Link to comment
https://forums.phpfreaks.com/topic/103190-running-a-function-through-html-form/
Share on other sites

basically your check to see if the buttons been pressed, i updated the submit button with a name

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

we then check to see if that element has a value *button name* i called it submit..

 

<html>
<head>
<title>Product Update</title>
</head>
<body>

<?php
//this is the key to getting it to work
if(!empty($_GET['submit']))
{
add();
}

function add()
{

$AAA = new AAA("Product", $_GET["product"], $_GET["price"], "images/unknown.jpg", $_GET["description"]);

echo '<img src="'. $AAA->GetPhoto() .'" align="left" />';
echo ''. $AAA->GetName() .': '. $AAA->GetModel();
echo '<p>Starting from: '. $ipod->GetPrice() .'</p>';
echo '<p>'. $AAA->GetDescription() .'</p>';
}
?>

<form action="index.php" method="get">
Product: <input name="product" type="text" />
Starting Price: <input name="price" type="text" />


Description: <input name="description" type="text" />
<input type="submit" name="submit" value="submit">
</form>

</body>
</html>

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.