Jump to content

hyperlink Variables


netman182

Recommended Posts

I have searched this forum and haven't found a solution to my question. please don't flame...

 

I am trying to send a table field from one page to another. the field i'm sending is id.

 

I have managed to populate the field updateplayer.php?id=*****

 

now i have a syntax error trying to get the field to show up on the update player form.

 

Parse error: syntax error, unexpected T_VARIABLE in /home/netman13/public_html/bccsl.org/managers/updateplayer.php on line 7

 

The id field is supposed to get the id variable from the previous page ?id=*****

 

Here is the update player code:

 

 

<?php 
include 'dbc.php';


$qP = "SELECT * FROM players WHERE id =  '$_GET['$id']' ";
$rsP = mysql_query($qP);
$row = mysql_fetch_array($rsP);
extract($row);
$id = trim($id);
$first = trim($first);
$last = trim($last);
$address = trim($address);
$city = trim($city);
$postal = trim($postal);
$phone = trim($phone);
$feet = trim($feet);
$inches = trim($inches);
$weight = trim($weight);
$birth = trim($birth);
$status = trim($status);
$number = trim($number);



mysql_close();

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Update Player</title>
<link href="styles.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script language="JavaScript" type="text/javascript" src="js/jquery.validate.js"></script>
<script>
  $(document).ready(function(){
    $.validator.addMethod("username", function(value, element) {
        return this.optional(element) || /^[a-z0-9\_]+$/i.test(value);
    }, "Username must contain only letters, numbers, or underscore.");

    $("#regForm").validate();
  });
  </script>

</head>

<body>

<script language="JavaScript">
<!--

/***********************************************
* Required field(s) validation v1.10- By NavSurf
* Visit Nav Surf at http://navsurf.com
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function formCheck(formobj){
// Enter name of mandatory fields
var fieldRequired = Array("first", "last", "address", "city", "postal", "phone", "hft", "hinch", "weight", "birthdate", "status");
// Enter field description to appear in the dialog box
var fieldDescription = Array("First Name", "Last Name", "Address", "City", "Postal Code", "Phone Number", "Feet", "Inches", "Weight", "Birthdate YYYY/MM/DD", "Player Status");
// dialog message
var alertMsg = "Please complete the following fields:\n";

var l_Msg = alertMsg.length;

for (var i = 0; i < fieldRequired.length; i++){
	var obj = formobj.elements[fieldRequired[i]];
	if (obj){
		switch(obj.type){
		case "select-one":
			if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
				alertMsg += " - " + fieldDescription[i] + "\n";
			}
			break;
		case "select-multiple":
			if (obj.selectedIndex == -1){
				alertMsg += " - " + fieldDescription[i] + "\n";
			}
			break;
		case "text":
		case "textarea":
			if (obj.value == "" || obj.value == null){
				alertMsg += " - " + fieldDescription[i] + "\n";
			}
			break;
		default:
		}
		if (obj.type == undefined){
			var blnchecked = false;
			for (var j = 0; j < obj.length; j++){
				if (obj[j].checked){
					blnchecked = true;
				}
			}
			if (!blnchecked){
				alertMsg += " - " + fieldDescription[i] + "\n";
			}
		}
	}
}

if (alertMsg.length == l_Msg){
	return true;
}else{
	alert(alertMsg);
	return false;
}
}
// -->
</script>

<table width="100%" border="0" cellpadding="5" cellspacing="0"class="main" >
  <tr>
    <td colspan="1"><p></p></td>
  </tr>
  <tr>
    <td width="17%"><? 
//Call Menu
include 'menu.php';

?></td>
    <td width="3%"> </td>
    <td width="80%"><p align="center">Update Player Information</p>
      <p align="center"><?	
      if (isset($_GET['msg'])) {
  echo "<div class=\"msg\">$_GET[msg]</div>";
  }
  ?></p>
      <p align="center"> </p>
      <form action="playerupdate.php" method="post" enctype="multipart/form-data" name="form" id="form" onsubmit="return formCheck(this);">
        <table width="653" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="148" height="29">First Name</td>
            <td width="153"><label>
              <input name="first" type="text" disabled="disabled" class="required" id="first" value="<?=$first ?>"  />
            </label></td>
            <td width="91" height="30">Last Name</td>
            <td width="261"><label>
              <input name="last" type="text" class="required" id="last" value="<?=$last ?>" readonly="readonly"  />
            </label></td>
          </tr>
          <tr>
            <td height="30">Address</td>
            <td><input name="address" type="text" class="required" id="address" value="<?=$address ?>"  /></td>
            <td>City</td>
            <td><label>
              <input name="city" type="text" class="required" id="city" value="<?=$city ?>"  />
            </label></td>
          </tr>
          <tr>
            <td height="28">Postal Code</td>
            <td><label>
              <input name="postal" type="text" class="required" id="postal" value="<?=$postal ?>" size="12"  />
            </label></td>
            <td>Phone Number</td>
            <td><label>
              <input name="phone" type="text" class="required" id="phone" value="<?=$phone ?>" size="13"  />
            </label></td>
          </tr>
          <tr>
            <td height="29">Height <strong>(ft / in)</strong></td>
            <td><label>
              <input name="feet" type="text" class="required" id="feet" value="<?=$feet ?>" size="3"  />
/
<input name="inches" type="text" class="required" id="inches" value="<?=$inches ?>" size="3"  />
</label></td>
            <td>Weight (lbs)</td>
            <td><input name="weight" type="text" class="required" id="weight" value="<?=$weight ?>" size="5"  /></td>
          </tr>
          <tr>
            <td height="35">Birthdate <strong>(yyyy/mm/dd)</strong></td>
            <td><label>
              <input name="birth" type="text" class="required" id="birth" value="<?=$birth ?>" size="13" readonly="readonly" />
            </label></td>
            <td><label>Player Type:</label></td>
            <td><p>
              <label>
                <input name="status" type="radio" id="type_0" value="1" checked="checked" />
                Church</label>
              <br />
              <label>
                <input type="radio" name="status" value="2" id="type_1" />
                Import</label>
              <br />
              <label>
                <input type="radio" name="status" value="3" id="type_2" />
                Witness</label>
              <br />
            </p>
              <label></label></td>
          </tr>
          <tr>
            <td height="35">Player ID:</td>
            <td><input name="id" type="text" id="id" value="<?=$id ?>" readonly="readonly" /></td>
            <td>Player Number:</td>
            <td><input name="number" type="text" class="required" id="number" value="<?=$number ?>" size="5"  /></td>
          </tr>
          <tr>
            <td height="29"> </td>
            <td><label></label></td>
            <td><p>
              <input name="teamid" type="hidden" id="teamid" value="<? echo $_SESSION['teamid'];?>" />
              <input name="division" type="hidden" id="division" value="<? echo $_SESSION['divisionid'];?>" />
              
              
  <input type="hidden" name="currentdate" size=11 >
              
              
              
  </p>
              <p>
                <input name="teamname" type="hidden" id="teamname" value="<? echo $_SESSION['team_name'];?>" />
              </p>
              <p>
                <script>

/*Current date in form credit: 
JavaScript Kit (www.javascriptkit.com)
Over 200+ free scripts here!
*/

var mydate=new Date()
var theyear=mydate.getYear()
if (theyear < 1000)
theyear+=1900
var theday=mydate.getDay()
var themonth=mydate.getMonth()+1
if (themonth<10)
themonth="0"+themonth
var theday=mydate.getDate()
if (theday<10)
theday="0"+theday

//////EDIT below three variable to customize the format of the date/////

var displayfirst=theyear
var displaysecond=themonth
var displaythird=theday

////////////////////////////////////

document.form.currentdate.value=displayfirst+"/"+displaysecond+"/"+displaythird
</script>
                
                <input name="approved" type="hidden" id="approved" value="0" />
            </p></td>
            <td> </td>
          </tr>
        </table>
<p align="center">
              <label>
              <input type="submit" name="submit2" id="submit2" value="Submit" />
              </label>
              <label>
              <input type="reset" name="reset2" id="reset2" value="Clear" />
              </label>
</p>
      </form>
      <p align="center"> </p>
      <p align="center">
        <label></label>
    </p></td>
  </tr>
  <tr>
    <td colspan="3"> </td>
  </tr>
</table>
<p> </p>
</body>
</html>

 

Thanks for your help.

 

This forum has been an awesome resource for me.

Link to comment
https://forums.phpfreaks.com/topic/256997-hyperlink-variables/
Share on other sites

that kinda worked... now i get a different syntax error...

 

Warning: extract() [function.extract]: First argument should be an array in /home/netman13/public_html/bccsl.org/managers/updateplayer.php on line 9

 

if i remove line 9 i get no syntax errors but no form data...

 

<?php 
include 'dbc.php';


$qP = "SELECT * FROM players WHERE id =  '$_GET['$id']' ";
$rsP = mysql_query($qP);
$row = mysql_fetch_array($rsP);
line 9: extract($row);
$id = trim($id);
$first = trim($first);
$last = trim($last);
$address = trim($address);
$city = trim($city);
$postal = trim($postal);
$phone = trim($phone);
$feet = trim($feet);
$inches = trim($inches);
$weight = trim($weight);
$birth = trim($birth);
$status = trim($status);
$number = trim($number);



mysql_close();

?>

Link to comment
https://forums.phpfreaks.com/topic/256997-hyperlink-variables/#findComment-1317448
Share on other sites

still getting errors:

 

 

Warning: array_map() [function.array-map]: Argument #2 should be an array in /home/netman13/public_html/bccsl.org/managers/updateplayer.php on line 10

 

Warning: extract() [function.extract]: First argument should be an array in /home/netman13/public_html/bccsl.org/managers/updateplayer.php on line 11

 

<?php 
include 'dbc.php';


$getid= $_GET[id];

$qP = "SELECT * FROM players WHERE id =  '$getid' ";
$rsP = mysql_query($qP);
$row = mysql_fetch_assoc($rsP);
$row = array_map('trim', $row);
extract($row);
$id = trim($id);
$first = trim($first);
$last = trim($last);
$address = trim($address);
$city = trim($city);
$postal = trim($postal);
$phone = trim($phone);
$feet = trim($feet);
$inches = trim($inches);
$weight = trim($weight);
$birth = trim($birth);
$status = trim($status);
$number = trim($number);



mysql_close();

?>

 

i know the form works flawlessly when i use a preset id...

Link to comment
https://forums.phpfreaks.com/topic/256997-hyperlink-variables/#findComment-1317477
Share on other sites

Then it sounds like no rows are being returned.

$qP = "SELECT * FROM players WHERE id =  '$getid' ";
$rsP = mysql_query($qP);
if (mysql_num_rows($rsP) == 1) {
$row = mysql_fetch_assoc($rsP);
$row = array_map('trim', $row);
extract($row);
} else {
echo 'no rows returned';
}

 

Also with my code, you don't need to explicitly do all that trim stuff - it is automatically done to all of the results.

Link to comment
https://forums.phpfreaks.com/topic/256997-hyperlink-variables/#findComment-1317661
Share on other sites

here is my updated mysql query. if i put in a static (preselected id) it works perfect. the problem is with the get.

 

Please help out.

 

 

thanks

 

<?php 
include 'dbc.php';



$getid = $_GET['id'];

$sql="SELECT * FROM players WHERE id = '$getid' ";
$res=mysql_query($sql) or die(mysql_error());
while($r=mysql_fetch_assoc($res))
{

$id = $r['id'];
$first = $r['first'];
$last = $r['last'];
$address = $r['address'];
$city = $r['city'];
$postal = $r['postal'];
$phone = $r['phone'];
$feet = $r['feet'];
$inches = $r['inches'];
$weight = $r['weight'];
$birth = $r['birth'];
$status = $r['status'];
$number = $r['number'];
}
?>

Link to comment
https://forums.phpfreaks.com/topic/256997-hyperlink-variables/#findComment-1318208
Share on other sites

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.