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 :)

Link to comment
Share on other sites

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']; 
  } ?> 

 

 

 

Link to comment
Share on other sites

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'];
?>

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.