Page 1 of 1

Use Data in feedback form after retrieving from database

Posted: Fri May 16, 2003 2:27 pm
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!'; 
}

?>

Posted: Sun May 18, 2003 5:20 pm
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.

Use Data in feedback form after retrieving from database

Posted: Sun May 18, 2003 5:23 pm
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.

Posted: Sun May 18, 2003 8:34 pm
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.

Pass Values

Posted: Mon May 19, 2003 1:57 am
by vipul73
Yeah, Passing the values through hidden fields would work but how do I assign values of retrieved data to hidden fields?

Posted: Mon May 19, 2003 3:59 am
by volka

Code: Select all

<?php
 $theValue = getMeAValue();
?>
<input type="hidden" name="xyz" value="<?php echo htmlentities($theValue); ?>" />

Posted: Tue May 20, 2003 4:27 pm
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!'; 
}

?>

Posted: Tue May 20, 2003 5:52 pm
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)... :)

Posted: Tue May 20, 2003 8:00 pm
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>';

Posted: Thu Jun 12, 2003 2:59 pm
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.

Posted: Thu Jun 12, 2003 5:34 pm
by McGruff
Looks good - but flash urrgh.