Jump to content

How to make this a variable in my form script


chrisidas

Recommended Posts

Ok, so my form looks like this (the form will be on the page transferform.php?pid=(playerID from a previous page)

<div id="transferrequestform">
<form action="transferrequest-script.php" method="post">
<table width="600" border="0" cellspacing="10" cellpadding="5">
  <tr>
    <td width='200' align='centre'> 
<?php
$pid=$_GET['pid'];
$result = mysql_query("SELECT * FROM transferlist WHERE playerID= '$pid'");
while($row = mysql_fetch_array($result))
  {
echo $row['playername']; 
  }
?>
    </td>
<td width='200' align='centre'><p><input type="text" name="amount" value="Amount (millions)" /></p> 
    </td>
    <td width='200' align='centre'>
    <select name="transfertype" id="transfertype">
    <option value="sale" selected="selected">Sale</option>
    <option value="loan">Loan</option>
    </select>
    </td>
    <td width='200' align='centre'><input type="submit" value="Submit" /></td>
  </tr>
</table>
</form>
</div>

And my script currently looks like this.

<?php
include("members_system/include/constants.php");
include("members_system/include/session.php");


$con = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
      mysql_select_db(DB_NAME, $con) or die(mysql_error());
?>

<?php
if($session->isManchesterUnited()){
      $userTeam = (('Manchester United'));
}
if($session->isChelsea()){
      $userTeam = (('Chelsea'));
}

$playername = mysql_real_escape_string($_POST['playername']);
$transfertype = mysql_real_escape_string($_POST['transfertype']);
$amount = mysql_real_escape_string($_POST['amount']);


mysql_query("INSERT INTO transferbids (playername, offer, transfertype, biddingteam)
VALUES ('$playername', '$amount', '$transfertype', '$userTeam')");


mysql_close($con);
?> 

How would i go about getting the 'playername' from the page with the form on, so i can insert it into the database.

 

Thanks :)

Ah right, helps a little yeah. Which part of this would go in the $_SESSION part then?

<?php $pid=$_GET['pid'];
$result = mysql_query("SELECT * FROM transferlist WHERE playerID= '$pid'");
while($row = mysql_fetch_array($result))
  {
echo $row['playername']; 
  } ?> 

 

 

 

you could just use:

 

$_SESSION['playerName'] = $row['playername'];

 

again: you pages need to have session_start(); at the beginning tor the session variable to work.

 

Also, I'm assuming there will be only 1 player name (as opposed to many different names) since the query is based on a playerID.

 

then on any other page, you can get it with:

<?php
session_start();
echo $_SESSION['playerName'];
?>

hang on... if you're using the hidden field, you do not need to store the value in a SESSION variable....

if you've already got the hidden field, just grab it's value with  $_POST['hiddenFieldName'] or $_REQUEST['hiddenFieldName']

You won't need to use a hidden input fields if you store the id in a session, session data is carried between pages.

 

 

Normally you would use it like this:

 

 

login.php

session_start();
//user logs in succesfully


$_SESSION['pid'] = $userdata['player_id'];
header('location: logged_in.php');

 

 

logincheck.php

session_start();
if ( !isset($_SESSION['pid']) )
{
   header('location: index.php');
   exit;

}
$playerID = (int)$_SESSION['pid'];

 

 

logged_in.php

include 'logincheck.php';
//use $playerID for stuff...

Confused now lol

 

I cant just put the player name in the hidden field because its a result from a query, well thats probs possible i just dont know how to do it :P

 

On my script page i have these variables, so i can just put them straight into the query

<?php $playername = mysql_real_escape_string($_POST['playername']);
$transfertype = mysql_real_escape_string($_POST['transfertype']);
$amount = mysql_real_escape_string($_POST['amount']); ?>

 

If i added

<?php
session_start();
$playername = $_SESSION['playerName'];
?>

to the end of that, would that be correct, or am i way off?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.