chrisidas Posted June 26, 2011 Share Posted June 26, 2011 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 Quote Link to comment Share on other sites More sharing options...
WebStyles Posted June 26, 2011 Share Posted June 26, 2011 use a hidden input field in your form with the player name as value, of dump the player name into a $_SESSION variable so you can grab it on the next page. Quote Link to comment Share on other sites More sharing options...
chrisidas Posted June 26, 2011 Author Share Posted June 26, 2011 Cheers, how do i go about making a hidden input field? Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted June 26, 2011 Share Posted June 26, 2011 Tutorial explaining hidden fields: http://www.echoecho.com/htmlforms07.htm Quote Link to comment Share on other sites More sharing options...
chrisidas Posted June 26, 2011 Author Share Posted June 26, 2011 Nice one, will give it a bash now Quote Link to comment Share on other sites More sharing options...
chrisidas Posted June 26, 2011 Author Share Posted June 26, 2011 One more newbie question. How would i go about putting it in a $_SESSION variable, i've read some other threads and tutorials but cant get my head around it at all Quote Link to comment Share on other sites More sharing options...
WebStyles Posted June 26, 2011 Share Posted June 26, 2011 as long as you have session_start(); at the beginning of your pages, you can use $_SESSION to store values, like: $_SESSION['myVarName'] = 'My first session test'; hope this helps Quote Link to comment Share on other sites More sharing options...
chrisidas Posted June 26, 2011 Author Share Posted June 26, 2011 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']; } ?> Quote Link to comment Share on other sites More sharing options...
WebStyles Posted June 26, 2011 Share Posted June 26, 2011 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']; ?> Quote Link to comment Share on other sites More sharing options...
chrisidas Posted June 26, 2011 Author Share Posted June 26, 2011 Ahhh, nice one! So I would just need to put that into the hidden field, then i'd be able to grab it on my script page, yeah? Quote Link to comment Share on other sites More sharing options...
WebStyles Posted June 26, 2011 Share Posted June 26, 2011 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'] Quote Link to comment Share on other sites More sharing options...
Andy-H Posted June 26, 2011 Share Posted June 26, 2011 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... Quote Link to comment Share on other sites More sharing options...
chrisidas Posted June 26, 2011 Author Share Posted June 26, 2011 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 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? Quote Link to comment Share on other sites More sharing options...
chrisidas Posted June 26, 2011 Author Share Posted June 26, 2011 Finally got it sorted. Ended up using mysql_fetch_array() to create the variable i wanted, then sent that in the hidden field. Thanks for the help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.