Adding information from one database to another
Posted: Wed Jan 19, 2011 1:55 am
Alright, I want to snag the current users name when they entering a new beer into my system. The user has to log on to even see this page. At the top I would like their username to appear, and when the code is submitted for their name to then be pushed back to my "Beer" database. The username I assume is in another database. I am using wordpress.
PHP
HTML
PHP
Code: Select all
<?php
$con = mysql_connect("localhost","UN","PASS");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("DB", $con);
$beername = mysql_real_escape_string($_POST['beername']);
$brewery = mysql_real_escape_string($_POST['brewery']);
$style = mysql_real_escape_string($_POST['style']);
$aroma = mysql_real_escape_string($_POST['aroma']);
$appearance = mysql_real_escape_string($_POST['appearance']);
$flavor = mysql_real_escape_string($_POST['flavor']);
$mouthfeel = mysql_real_escape_string($_POST['mouthfeel']);
$overallimpression = mysql_real_escape_string($_POST['overallimpression']);
$sql="INSERT INTO Beers (beername, brewery, style, aroma, appearance, flavor, mouthfeel, overallimpression)
VALUES
('$beername','$brewery','$style', '$aroma', '$appearance', '$flavor', '$mouthfeel', '$overallimpression')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>Code: Select all
<form action="/wp-content/insert.php" method="post">
//I WOULD LIKE THEIR NAME TO BE PUT IN HERE
<label for="username">User Name: </label>
<input id="username" name="username" type="text" />
<label for="beername">Beer Name: </label>
<input id="beername" name="beername" type="text" />
<label for="brewery">Brewery: </label>
<input id="brewery" name="brewery" type="text" />
<label for="style">Style: </label>
<input id="style" name="style" type="text" />
Aroma
<textarea cols="20" rows="4" name="aroma"></textarea>
Appearance
<textarea cols="20" rows="4" name="appearance"></textarea>
Flavor
<textarea cols="20" rows="4" name="flavor"></textarea>
Mouth Feel
<textarea cols="20" rows="4" name="mouthfeel"></textarea>
Overall Impression
<textarea cols="20" rows="4" name="overallimpression"></textarea>
<input name="submitbeer" type="SUBMIT" value="SUBMIT" />
</form>