I have two php pages
One is a form
The second is to post the form to a mysql database
I can get the first php page to work correctly
What that page does is create a selectable dropdown list of a column in the mysql database.
That seems to work correctly.
The second php page
This page is the one i want to use to post the data to the database.
i have managed to over the last few days get it to post to the database kind of.
I say kind of because what i can get it to do is post to the data base but all i get out of it is a single strike colon.
This is all done on a apache server on localhost
Here is the code for the dropdown list page
<code>
<?php
$user=' ';
$host='localhost';
$password=' ';
$database = 'budget';
$connection = mysql_connect($host,$user,
$password)
;
if (!$connection) {
die('Could not connect: ' . mysql_error());
}
$db = mysql_select_db($database,
$connectio
n);
if (!$db) {
die ('Can\'t use foo : ' . mysql_error());
}
$query = ('SELECT purchasecat FROM main ');
$result = mysql_query($query);
echo "<form method='POST' action='test.php'>";
echo "<select size='1' name='pt'>\n";
while ($row = mysql_fetch_array($result)
){
extract($row);
echo "<option value=$purchasecat>$purc
hasecat</o
ption>\n";
}
echo "</select>\n";
echo "<input type='submit' name='submit' value='Select Type of Purchase'>";
echo "</form>\n";
?>
</code>
Code for Second page that im using to post with
<code>
<?php
$name=$_POST['submit'];
$purchasecat = $_POST['pt'];
$link = mysql_connect('localhost',
' ', ' ');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('budget', $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
if(isset($_POST['pt']))
{
mysql_query("INSERT INTO main (purchasecat) VALUES ('$purchasecat')");
mysql_close($link);
}
header("Location:
http://x86-solutions.dyndns.org:7401/test/test1.php");
?>
</code>
Start Free Trial