0

I am trying to create a page that will look up values from a table to fill in drop down boxes, i have this working. Now when the user selects options and presses a button i would like these values to get written to a table.

This code is my form that looks up values and populates drop down fields for the user.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB"> 
<head> 
	<title>Godfather Wars</title> 
	<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" /> 
	<meta name="description" content="Godfather Wars" /> 
	<meta name="keywords" content="Godfather Wars" /> 
	<meta name="robots" content="index, follow" /> 
	<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" /> 
	<style type="text/css" media="all">@import "default.css";</style>

<script language="javascript" type="text/javascript" src="datetimepicker.js">
//Date Time Picker script- by TengYong Ng of http://www.rainforestnet.com
//Script featured on JavaScript Kit (http://www.javascriptkit.com)
//For this script, visit http://www.javascriptkit.com 
</script>

</head> 
<body> 
 
<div id="header"> 
	<p><a href="http://www.vampresearch.com" title="Godfather Wars">&laquo; Goto VAMP Research</a> by <a href="http://www.vampresearch.com">Kristopher Thomas Croteau</a></p> 
	<h1>Godfather Wars</h1> 
	<h2>Welcome to your desk</h2> 
	<ul> 
	
	<?php
	$user = $_GET['user'];
	echo "<li><a href='http://www.vampresearch.com/godfatherwars/main.php?user=$user'>Home</a></li>";
	echo "<li><a href='http://www.vampresearch.com/godfatherwars/profile.php?user=$user'>Profile</a></li>";
	echo "<li><a href='http://www.vampresearch.com/godfatherwars/family.php?user=$user'>Your Family</a></li>";
	echo "<li><a href='http://www.vampresearch.com/godfatherwars/main.html'>Hitlist</a></li>";
	echo "<li><a href='http://www.vampresearch.com/godfatherwars/main.html'>Contact Admin</a></li>";
	echo "<li><a href='http://www.vampresearch.com/godfatherwars/donsdesk/index.php?user=$user' class='active'>Dons 	Desk</a></li>";
	?>

	</ul> 
	<p id="layoutdims">Message Inbox</p> 
</div> 
<div class="colmask threecol"> 
	<div class="colmid"> 
		<div class="colleft"> 
			<div class="col1"> 
				<!-- Column 1 start --> 
	<?php
	// Connecting, selecting database
	$link = mysql_connect('HOST', 'USER', 'PASSWORD')
    or die('Could not connect: ' . mysql_error());
	mysql_select_db('DBNAME') or die('Could not select database');
	// Performing SQL query
	$user = $_GET['user'];
	$query = "SELECT `name` FROM Members where username = '$user'";
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "";foreach ($line as $value);}
	 echo "  <h2>Welcome to your desk Don $value</h2>  ";
	// Closing connection
	mysql_close($link);
	?>

				<p>This is your desk</p> 

<div class="contract">
<font size="3pt" face="Gerogia">
<div class="donname">
<?php
// Connecting, selecting database
$link = mysql_connect('HOST', 'USER 'PASSWORD')
    or die('Could not connect: ' . mysql_error());
mysql_select_db('DBNAME') or die('Could not select database');
// Performing SQL query
$user = $_GET['user'];
$query = "SELECT `name` FROM Members where username = '$user'";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "";foreach ($line as $value);}
 echo "<b>$value</b>";
// Closing connection
mysql_close($link);
?>
</div>

<div class="target">
<select name="target">
<?php
// Connecting, selecting database
$link = mysql_connect('HOST', 'USER 'PASSWORD')
    or die('Could not connect: ' . mysql_error());
//echo 'Connected successfully';
mysql_select_db('DBNAME') or die('Could not select database');
// Performing SQL query
$user = $_GET['user'];
$query = "SELECT * FROM Members where family <> (SELECT family FROM Members where username = '$user')";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$num = mysql_numrows($result);
$i=0;
do {
$Name = mysql_result($result,$i,"name");
$vname = mysql_result($result,$i,"username");
// Printing results in HTML
echo "<option value=$Name>$Name</option>";
$i++;
} while ($i < $num);
// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($link);
?>
</select>
</div>

<div class="date">
<input id="demo1" type="text" size="25"><a href="javascript:NewCal('demo1','ddmmyyyy')"><img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a contract date"></a>
</div>

<div class="assign">
<select name="assign">
<option value="open">Open</option>
<?php
// Connecting, selecting database
$link = mysql_connect('HOST', 'USER 'PASSWORD')
    or die('Could not connect: ' . mysql_error());
//echo 'Connected successfully';
mysql_select_db('DBNAME') or die('Could not select database');
// Performing SQL query
$user = $_GET['user'];
$query = "SELECT * FROM Members where family = (SELECT family FROM Members where username = '$user')";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$num = mysql_numrows($result);
$i=0;
do {
$Name = mysql_result($result,$i,"name");
$vname = mysql_result($result,$i,"username");
// Printing results in HTML
echo "<option value=$Name>$Name</option>";
$i++;
} while ($i < $num);
// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($link);

?>
</select>
</div>

<div class="sign">
<button type="button" onclick="window.location='http://www.vampresearch.com/godfatherwars/donsdesk/contractadd.php'">Signed the Don</button>
</div>
</font>
</div>
				<!-- Column 1 end --> 
			</div> 

			<div class="col2"> 
				<!-- Column 2 start --> 
				<h2>Your family members</h2> 
				<p>
<?php
// Connecting, selecting database
$link = mysql_connect('HOST', 'USER 'PASSWORD')
    or die('Could not connect: ' . mysql_error());
//echo 'Connected successfully';
mysql_select_db('DBNAME') or die('Could not select database');
// Performing SQL query
$user = $_GET['user'];
$query = "SELECT * FROM Members where family = (SELECT family FROM Members where username = '$user')";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

$num = mysql_numrows($result);
$i=0;
do {
$Name = mysql_result($result,$i,"name");
$rank = mysql_result($result,$i,"rank");

$queryrank = "SELECT `rank` FROM ranks where id = '$rank' order by rank desc";
$resultrank = mysql_query($queryrank) or die('Query failed: ' . mysql_error());
while ($line1 = mysql_fetch_array($resultrank, MYSQL_ASSOC)) { echo "";foreach ($line1 as $value1);}


// Printing results in HTML
echo "$Name - $value1<br>";
$i++;
} while ($i < $num);
// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($link);
?>
				<h2>Contracts on your family</h2> 
				<p>
<?php
// Connecting, selecting database
$link = mysql_connect('HOST', 'USER 'PASSWORD')
    or die('Could not connect: ' . mysql_error());
//echo 'Connected successfully';
mysql_select_db('DBNAME') or die('Could not select database');
// Performing SQL query
$user = $_GET['user'];
$query = "SELECT * FROM hitlist where targetfamily = (SELECT family FROM Members where username = '$user') and complete = '0' and sanctioned = '1'";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$num = mysql_numrows($result);
$i=0;
if($num==0)
{
echo "There are no contracts on your family!";
}
else
{
do {
$target = mysql_result($result,$i,"target");
$killer = mysql_result($result,$i,"contractedto");
$family = mysql_result($result,$i,"contractfamily");
$date = mysql_result($result,$i,"issuedate");
// Printing results in HTML
echo "Target: $target <br>";
//echo "Assassian: $killer<br>";
echo "Contracted by: $family <br>";
echo "Contract Date: $date<br>";
echo "------------------------------------<br>";
$i++;
} while ($i < $num);
}
// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($link);
?>
</p> 

				<h2>Contracts started by your family</h2> 
				<p>
<?php
// Connecting, selecting database
$link = mysql_connect('HOST', 'USER 'PASSWORD')
    or die('Could not connect: ' . mysql_error());
//echo 'Connected successfully';
mysql_select_db('DBNAME') or die('Could not select database');
// Performing SQL query
$user = $_GET['user'];
$query = "SELECT * FROM hitlist where contractfamily = (SELECT family FROM Members where username = '$user') and complete = '0' and sanctioned = '1'";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$num = mysql_numrows($result);
$i=0;
if ($num==0)
{echo "There are no contracts started by your family! You are the Don start one!";
}
else
{
do {
$target = mysql_result($result,$i,"target");
$killer = mysql_result($result,$i,"contractedto");
$family = mysql_result($result,$i,"contractfamily");
$date = mysql_result($result,$i,"issuedate");
// Printing results in HTML
echo "Target: $target <br>";
echo "Target family: $family <br>";
echo "Assassian: $killer<br>";
echo "Contract Date: $date<br>";
echo "------------------------------------<br>";
$i++;
} while ($i < $num);
}
// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($link);
?>
</p> 

				<h2>Requested contracts</h2> 
				<p>
<?php
// Connecting, selecting database
$link = mysql_connect('HOST', 'USER 'PASSWORD')
    or die('Could not connect: ' . mysql_error());
//echo 'Connected successfully';
mysql_select_db('DBNAME') or die('Could not select database');
// Performing SQL query
$user = $_GET['user'];
$query = "SELECT * FROM hitlist where contractfamily = (SELECT family FROM Members where username = '$user') and complete = '0' and sanctioned = '0'";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$num = mysql_numrows($result);
$i=0;
if ($num==0)
{
echo "There are not requested contracts at this time!";
}
else
{
do {
$target = mysql_result($result,$i,"target");
$killer = mysql_result($result,$i,"contractedto");
$family = mysql_result($result,$i,"contractfamily");
$date = mysql_result($result,$i,"issuedate");
// Printing results in HTML
echo "Target: $target <br>";
echo "Target family: $family <br>";
echo "Requested By: $killer<br>";
echo "Contract Date: $date<br>";
echo "------------------------------------<br>";
$i++;
} while ($i < $num);
}
// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($link);
?>
</p> 
</p> 

				<!-- Column 2 end --> 
			</div> 
			<div class="col3"> 
				<!-- Column 3 start --> 
				<h2>Family Controls</h2> 
				<p>Use the controls below to control your family:</p> 
				<h3>Contracts/Hits</h3> 
				<ul> 
					<li>View Current</li> 
					<li>Add</li> 
					<li>Cancel</li> 
					<li>Complete</li> 
				</ul> 
				<h3>Members</h3> 
				<ul> 
					<li>Add</li> 
					<li>Remove</li> 
					<li>Promote</li> 
					<li>Demote</li> 
				</ul> 
				<h3>Points</h3> 
				<ul> 
					<li>View Current</li> 
					<li>Add</li> 
					<li>Remove</li> 
				</ul> 

				<!-- Column 3 end --> 
			</div> 
		</div> 
	</div> 
</div> 
<div id="footer"> 
	<p>This page uses the <a href="http://matthewjamestaylor.com/blog/perfect-3-column.htm">Perfect 'Holy Grail' 3 Column Liquid Layout</a> by <a href="http://matthewjamestaylor.com">Matthew James Taylor</a>. Thanks for such a cool layout.</p> 
</div> 
 
 
</body> 
</html>

When the user clicks the button these variables should be passed into the database. I have this form so far:

<?php

//This section writes the user data to the table.
$target=$_POST['target'];
$date=$_POST['date'];
$assign=$_POST['assign'];
echo "Values are Target: " .$target;
$host="HOST"; // Host name 
$username1="USER"; // Mysql username 
$password1="PASSWORD"; // Mysql password 
$db_name="DBNAME"; // Database name 
$tbl_name="TABLENAME"; // Table name
// Connect to server and select databse.
$con = mysql_connect("$host", "$username1", "$password1")or die("cannot connect"); 
mysql_select_db('gfwars') or die('Could not select database');
$query  = "INSERT INTO `Members` VALUES ($target,'',$assign,'',$date,'0','','1')";
mysql_query($query);
mysql_close($con);
header('Location: family.php?user='.$user);
?>

Any idea how i can get the information in the option boxes to this second php page?

3
Contributors
5
Replies
12
Views
7 Years
Discussion Span
Last Post by venkat0904
0

if you want it to go to a second page when a user clicks a button
use

echo "<form name='input' action='".$_SERVER['php_self']."' method='POST'>

to post the data to that page or just change the .$server to what ever page you want then on the top of that page you can have a

$urthing = $_POST['urthing'];

to grab the data and then its in a variable $urthing which you can do stuff with i think this is what you are trying to do but thats alot to read through let me know if that is what you were trying to do

0

I can remove some of the code if it will make it easier. I was trying to reflect all of what the page was doing, in case something i was doing was breaking the effect i wanted.

I can not get the

echo "<form name='input' action='".$_SERVER['php_self']."' method='POST'>

to work properly, not sure where i should call it in my code.

I see it needs to be in a <?php section, i have each variable being created in its own <?php section, will this impact my results?

0

where ever you have the submitt button or the feilds for the user info

you have to put a <form> </form> and the button will submitt it

it doesnt have to be in php if your feilds are html just dont echo the <form>

0

ok here is what i have now

<form name='input' action='".$_SERVER['PHP_SELF']."' method='POST'>
<div class='sign'>
<button type='button' >Signed the Don</button>
</div>
</form>

i click the button and nothing happens, any ideas?

Edited by VAMPResearch: n/a

0

ok here is what i have now

<form name='input' action='".$_SERVER['PHP_SELF']."' method='POST'>
<div class='sign'>
<button type='button' >Signed the Don</button>
</div>
</form>

i click the button and nothing happens, any ideas?

if you are using this outside php tags it should go like this

<form name='input' action="<?php echo $_SERVER['PHP_SELF']; ?>" method='POST'>

hope this helps.. cheers

Edited by venkat0904: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.