Use Data in feedback form after retrieving from database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vipul73
Forum Commoner
Posts: 27
Joined: Mon May 12, 2003 5:32 am

Use Data in feedback form after retrieving from database

Post by vipul73 »

I have created a page with the help of this forum only :)

Now the data is being retrieved successfully.

I would like use the data in a feedback form and it should be sent to the e-mail address specified in the feedback form i.e. I should get the name of the package etc. in the e-mail after the user orders a product from our site.

Code: Select all

<?php

$db = mysql_connect("localhost", "root");

mysql_select_db("orders",$db);

// display individual record
if (!empty($_GET['id']) && is_numeric($_GET['id'])) { 
    $sql = "SELECT package, amount, currency, duration FROM spaces WHERE id=".$_GET['id']; 
    $result = mysql_query($sql, $db) or die(mysql_error().'<p>'.$sql.'</p>'); 

    if (mysql_num_rows($result) == 1) { 
        $myrow = mysql_fetch_assoc($result); 
        echo 'Package Name: '.$myrow['package'].'<br />'; 
        echo 'Amount: '.$myrow['currency'].''; 
        echo ' '.$myrow['amount'].'<br />'; 
        echo 'Duration: '.$myrow['duration'].'<br />'; 
		
    } else { 
        // no records found 
        echo 'There is no record with an ID of '.$_GET['id']; 
    } 
} else { 
    // no records to display 
    echo 'Sorry, no records were found!'; 
}

?>
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

mail() is the function you are looking for. The code could be very much like what you already have there, put the output in a variable and then mail it to the recipient.

If you are unfamiliar with forms, have a look at W3 Form-definition or one of the many form-tutorials out there.
vipul73
Forum Commoner
Posts: 27
Joined: Mon May 12, 2003 5:32 am

Use Data in feedback form after retrieving from database

Post by vipul73 »

Yeah Mail would work but the problem I am having is that it is retrieving the data from database. Now when I use mail it is not sending the data by e-mail as it is only sending data filled by the user in the form whereas I would like to know the package etc. the user has ordered.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

If I've guessed your problem right, you need some hidden fields in the form. The values will be passed to the form processor along with the textarea input.
vipul73
Forum Commoner
Posts: 27
Joined: Mon May 12, 2003 5:32 am

Pass Values

Post by vipul73 »

Yeah, Passing the values through hidden fields would work but how do I assign values of retrieved data to hidden fields?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

<?php
 $theValue = getMeAValue();
?>
<input type="hidden" name="xyz" value="<?php echo htmlentities($theValue); ?>" />
vipul73
Forum Commoner
Posts: 27
Joined: Mon May 12, 2003 5:32 am

Post by vipul73 »

I tried volka's suggestion but frankly could not understand how do I use it.

:oops: I am a novice at Programming.

However I tried one more method but it also did not work. 8O

The code I tried is as below:

Code: Select all

<?php
$db = mysql_connect("localhost", "root");

mysql_select_db("orders",$db);

// display individual record
if (!empty($_GET['id']) && is_numeric($_GET['id'])) { 
    $sql = "SELECT package, amount, currency, duration FROM spaces WHERE id=".$_GET['id']; 
    $result = mysql_query($sql, $db) or die(mysql_error().'<p>'.$sql.'</p>'); 

if (mysql_num_rows($result) == 1) { 

$myrow = mysql_fetch_assoc($result); 
$message= "Package Name: $myrow['package']<br>
Amount: $myrow['currency'] $myrow['amount']<br>
Duration: $myrow['duration']<br>"; 
$message_email= "Package Name: $myrow['package']\n Amount: $myrow['currency'] $myrow['amount']\n
Duration: $myrow['duration']\n"; 

print $message;
mail($rec_email,$subject,$message_email,"From: $sender_email");

}

else { 
        // no records found 
        echo 'There is no record with an ID of '.$_GET['id']; 
    } 
} else { 
    // no records to display 
    echo 'Sorry, no records were found!'; 
}

?>
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Use Volka's code on the form-page - it'll create a hidden input-field which will have the value of some PHP-variable ($theValue)... :)
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

..and stick this at the top of your form processor script to check what is being returned by the form:

echo '<pre>';
print_r($_POST); // or $_GET if that's the form method
echo '</pre>';
vipul73
Forum Commoner
Posts: 27
Joined: Mon May 12, 2003 5:32 am

Post by vipul73 »

Thanks a lot to every1 who has taken his valuable time to respond to my queries and being patient with me

I have been able to complete the website niftyonline.com upto my satisfaction. I know you guys would be able to suggest a lot of better things after visiting the site and am ready for the brickbats.

Thanx once again.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Looks good - but flash urrgh.
Post Reply