Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Closed Thread
need help with this code
Old 03-19-2011, 07:19 PM need help with this code
Average Talker

Posts: 21
Name: Mike
Trades: 0
Trying to make this script show a image before the bio.. where it says Player Image.


---------------------
Sql Table:
this is how i got the sql table going. i added Bio2 (for image)

--
-- Table structure for table 'player'
--

CREATE TABLE 'player' (
'ID' int(11) NOT NULL default '0',
'FirstName' char(50) collate latin1_general_ci NOT NULL default '',
'LastName' char(50) collate latin1_general_ci NOT NULL default '',
'Bio' char(255) collate latin1_general_ci default NULL,
'Bio2' char(255) collate latin1_general_ci default NULL,
'EMail' char(100) collate latin1_general_ci default NULL,
'SeasonID' int(11) NOT NULL default '0',
UNIQUE KEY 'ID' ('ID','SeasonID'),
KEY 'SeasonID' ('SeasonID')
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

--------------------------
PHP Code:
Php Code for playerbio.php

<?php
require('./config/config.php');
if (isset(
$_POST['cboSeason']) && $_POST['cboSeason'] <> '' && is_numeric($_POST['cboSeason'])) {
  
$id $_POST['cboSeason'];
} else {
  
$id NULL;
}
$arr seasoninfo($id);
$season_id $arr['0'];
$season_name $arr['1'];
$TITLE=$team_name.' Players  - '.$season_name;
require(
'./config/header.php');
?>
<h1><?=$TITLE;?></h1>
<hr />
<?php
if (isset($_GET['ID'])) {
  if (!
is_numeric($_GET['ID'])) {
    print(
'<h2>Invalid ID number!</h2>');
    require(
'./config/footer.php');
    exit;
  }
}
?>
<ul class="hint">
<li><strong>[Hint]</strong> Click the player number to see that player's stats.</li>
<li><strong>[Hint]</strong> Click the player name to send that player an email.</li>
</ul>
<hr />
<form name="bios" method="post">
Switch Season:
<select name="cboSeason" size="1" onchange="document.bios.submit()">
<?php
$recSeason 
mysql_query('SELECT * FROM season ORDER BY ID') ;
if (
$recSeason) {
  while (
$rowSeason mysql_fetch_assoc($recSeason)) {
    if ((isset(
$_POST['cboSeason']) && $_POST['cboSeason'] == $rowSeason['ID']) || $rowSeason['DefaultSeason']) {
      print 
'          <option selected';
    } else {
      print 
'          <option';
    }
?>
 VALUE="<?=$rowSeason['ID']?>"><?=stripslashes($rowSeason['Description'])?></option>
<?php
  
}
}
?>
</select>
</form>
<p>
<table width="800px" border="0">
  <tr>
    <th width="5%">Number</th>
    <th width="25%">Player Name</th>
    <th width="25%">Player Image</th> // added
    <th width="70%">Bio</th>
  </tr>
<?php
if (!isset($_GET['ID'])) {
  
$recPlayer=mysql_query('SELECT * FROM player WHERE SeasonID = '.$season_id.' ORDER BY LastName, FirstName') ;
} else {
  
$recPlayer=mysql_query('SELECT * FROM player WHERE ID = '.addslashes($_GET['ID']).' AND SeasonID = '
                         
.$season_id.' ORDER BY LastName, FirstName') ;
}

$i 0;
while(
$rowPlayer=mysql_fetch_assoc($recPlayer)) {
  if (
$rowPlayer['Bio'] == NULL) {
    
$bio 'No Bio';
  }else {
    
$bio nl2br(stripslashes($rowPlayer['Bio']));
    }
  if (
$i&1) {
    
$tdbg ' class="odd"';
  } else {
    
$tdbg ' class="even"';
  }
  
$i++;
?>
    <td <?=$tdbg?> valign="top"><strong><a  href="playerstats.php?ID=<?=$rowPlayer['ID']?>"><?=  $rowPlayer['ID'?></a></strong></td>
<?php if ($rowPlayer['EMail']  == '') { ?>
    <td<?=$tdbg?> valign="top"><?=stripslashes($rowPlayer['LastName'])?>,
      <?=stripslashes($rowPlayer['FirstName']) ?></td>
<?php } else { ?>
    <td<?=$tdbg?> valign="top"><a href="mailto:<?= stripslashes($rowPlayer['EMail']) ?>">
      <?=stripslashes($rowPlayer['LastName'])?><?=stripslashes($rowPlayer['FirstName']) ?></a></td>
<?php ?>
    <td<?=$tdbg?> valign="top"><?=$bio?></td>
  </tr>
  
<?php
}
?>
 </table>
<?php
require('./config/footer.php');
?>

PHP Code:
Php Code for admin/player.php
Anything with Bio2 i added it after i copy&paste the code there.

<?php
require('../config/config.php');
$TITLE=$team_name.' Softball Player Admin Page';
if (!isset(
$_POST['cboSeason']) || $_POST['cboSeason'] == '') {
  
$BODY_CODE='onLoad="document.player.cboSeason.focus();"';
} else {
   if ((isset(
$_POST['cboPlayerNum']) && $_POST['cboPlayerNum']  <> '') && !isset($_POST['Update']) &&  !isset($_POST['Add'])&& !isset($_POST['Delete'])) { 
    
$BODY_CODE='onLoad="document.player.cboPlayerNum.focus();"';
  } else {
    
$BODY_CODE='onLoad="document.player.txtPlayerNum.focus();"';
  }
}
if  (!isset(
$HTTP_SERVER_VARS['PHP_AUTH_PW']) ||  !isset($HTTP_SERVER_VARS['PHP_AUTH_USER']) ||  $HTTP_SERVER_VARS['PHP_AUTH_PW'] <> $admin_pass ||  strtoupper($HTTP_SERVER_VARS['PHP_AUTH_USER']) <>  strtoupper($admin_user)) {
 
authorize();
}
require(
'../config/header.php');
?>

<h1><?=$TITLE;?></h1>
<hr />
<?php

// Connect to DB
opendb();
$recSeason mysql_query('SELECT * FROM season ORDER BY ID') ;

// If Add button clicked, add new player
if (isset($_POST['Add']) && $demo_mode == '0') {
  
$_POST['cboPlayerNum'] = '';
   if (!isset(
$_POST['txtPlayerNum']) ||  !isset($_POST['txtPlayerFirstName']) ||  !isset($_POST['txtPlayerLastName']) || !isset($_POST['cboSeason']) ||  $_POST['txtPlayerNum'] == '' || $_POST['txtPlayerFirstName'] == '' ||  $_POST['txtPlayerLastName'] == '' || $_POST['cboSeason'] == '') {
    print (
'<H2>Failed to add play to DB<br />There is a blank field</H2>');
    require(
'../config/footer.php');
    exit;
  }
  if (isset(
$_POST['txtPlayerEMail']) && $_POST['txtPlayerEMail'] <> '') {
    
$email addslashes($_POST['txtPlayerEMail']);
  } else {
    
$email NULL;
  }
  if (isset(
$_POST['txtPlayerBio']) && $_POST['txtPlayerBio'] <> '') {
    
$bio addslashes($_POST['txtPlayerBio']);
  } else {
    
$bio NULL;
  }
  if (isset(
$_POST['txtPlayerBio2']) && $_POST['txtPlayerBio2'] <> '') {
    
$bio2 addslashes($_POST['txtPlayerBio2']);
  } else {
    
$bio2 NULL;
  }
  
$result mysql_query('INSERT INTO player (ID,FirstName,LastName,EMail,Bio,Bio2,SeasonID)
            VALUES ('
.addslashes($_POST['txtPlayerNum']).',"'.addslashes($_POST['txtPlayerFirstName']).'","'.
              
addslashes($_POST['txtPlayerLastName']).'","'.$email.'","'.$bio.'","'.$bio2.'",'.addslashes($_POST['cboSeason']).')');
  if (!
$result) {
    print (
'<H2>Failed to add play to DB<br />'.mysql_error().'</H2>');
    require(
'../config/footer.php');
    exit;
  }
}

// If Update button clicked, edit player
if (isset($_POST['Update']) && $demo_mode == '0') {
   if (!isset(
$_POST['txtPlayerFirstNameU']) ||  !isset($_POST['txtPlayerLastNameU']) || !isset($_POST['cboSeason']) ||  $_POST['txtPlayerFirstNameU'] == '' || $_POST['txtPlayerLastNameU'] ==  '' || $_POST['cboSeason'] == '') {
    print (
'<H2>Failed to update play to DB<br />There is a blank field</H2>');
    require(
'../config/footer.php');
    exit;
  }
  if (isset(
$_POST['txtPlayerEMailU']) && $_POST['txtPlayerEMailU'] <> '') {
    
$email addslashes($_POST['txtPlayerEMailU']);
  } else {
    
$email NULL;
  }
  if (isset(
$_POST['txtPlayerBioU']) && $_POST['txtPlayerBioU'] <> '') {
    
$bio addslashes($_POST['txtPlayerBioU']);
  } else {
    
$bio NULL;
  }
  if (isset(
$_POST['txtPlayerBio2U']) && $_POST['txtPlayerBio2U'] <> '') {
    
$bio2 addslashes($_POST['txtPlayerBio2U']);
  } else {
    
$bio2 NULL;
  }
  
$result mysql_query('UPDATE player SET FirstName = "'.addslashes($_POST['txtPlayerFirstNameU'])
            .
'",LastName = "'.addslashes($_POST['txtPlayerLastNameU']).'", EMail = "'.$email.'", Bio = "'.$bio.
             
'", Bio2 = "'.$bio2.'" WHERE ID ='.addslashes($_POST['cboPlayerNum']).'  AND SeasonID = '.addslashes($_POST['cboSeason']));
  if (!
$result) {
    print (
'<H2>Failed to update play to DB<br />'.mysql_error().'</H2>');
    require(
'../config/footer.php');
    exit;
  }
  
$_POST['cboPlayerNum'] = '';
}

// If Delete button clicked, delete player
if (isset($_POST['Delete']) && $demo_mode == '0') {
  
$_POST['cboPlayerNum'] = '';
  if (!isset(
$_POST['cboPlayer']) || $_POST['cboPlayer'] == '') {
    print (
'<H2>Failed to delete play from DB<br />There is a blank field</H2>');
    require(
'../config/footer.php');
    exit;
  }
   
$result mysql_query('SELECT * FROM plays WHERE PlayerID =  '.addslashes($_POST['cboPlayer']).' AND SeasonID =  '.addslashes($_POST['cboSeason']));
  
$row mysql_fetch_assoc($result);
  if (
$row) {
       print (
'<H2>Failed to delete player from DB<br />There are  still plays for this player in the play table!</H2>');
      require(
'../config/footer.php');
      exit;
  }
  
$result mysql_query('DELETE FROM player WHERE ID = '.addslashes($_POST['cboPlayer']));
  if (
$result == False) {
      print (
'<H2>Failed to delete play from DB<br />'.mysql_error().'</H2>');
      require(
'../config/footer.php');
      exit;
  }
  
$_POST['cboPlayerNum'] = '';
}

?>
* = Required Field
<form name="player" method="POST">
  <table border="0">
    <tr>
      <td>
        <p><strong>*Season:</strong></p></td>
      <td colspan="3">
      <select name="cboSeason" size="1" onchange="document.player.submit()">
          <option value=""></option>
<?php
if ($recSeason) {
  while (
$rowSeason mysql_fetch_assoc($recSeason)) {
    if (isset(
$_POST['cboSeason']) && $_POST['cboSeason'] == $rowSeason['ID']) {
      print 
'          <option selected';
    } else {
      print 
'          <option';
    }
?>
 VALUE="<?=$rowSeason['ID']?>"><?=stripslashes($rowSeason['Description'])?></option>
<?php
  
}
}
?>
        </select></td>
    </tr>
<?php
if (!isset($_POST['cboSeason']) || $_POST['cboSeason'] == '') {
  echo 
"  </table>";
  require(
'../config/footer.php');
  exit;
}
?>
    <tr><td colspan="4"><hr /></td></tr>
    <tr valign="CENTER">
      <td><strong>Add Player:</strong></td>
      <td>
        *Player #:<br />
        <input type="TEXT" name="txtPlayerNum" maxlength="3" size="3"></td>
      <td>
        *Player First Name:<br />
        <input type="TEXT" name="txtPlayerFirstName" maxlength="50" size="20"></td>
      <td>
        *Player Last Name:<br />
        <input type="TEXT" name="txtPlayerLastName" maxlength="50" size="20">
    </tr>
    <tr valign="TOP">
      <td></td>
      <td>
        Player EMail:<br />
        <input type="TEXT" name="txtPlayerEMail" maxlength="100" size="20"></td>
      <td>
        Player Image:<br /> // added
        <textarea name="txtPlayerBio2" maxlength="255" cols="25" rows="4" wrap="VIRTUAL"></textarea></td>
      <td>
        Player Bio:<br />
        <textarea name="txtPlayerBio" maxlength="255" cols="25" rows="4" wrap="VIRTUAL"></textarea></td>
      <td>
        <br /><input type="SUBMIT" name="Add" value="Add >>"></td>
    </tr>
    <tr><td colspan="4"><hr /></td></tr>
    <tr>
      <td><font face="Arial"><strong>Remove Player:</strong></td>
      <td colspan="3">
        <select name="cboPlayer" size="1">
          <option value=""></option>
<?php
if (isset($_POST['cboSeason']) && $_POST['cboSeason'] <> '') {
   
$recPlayer mysql_query('SELECT * FROM player WHERE SeasonID =  '.addslashes($_POST['cboSeason']).' ORDER BY LastName, FirstName') ;
}
if (
$recPlayer) {
  while (
$rowPlayer mysql_fetch_assoc($recPlayer)) {
?>
           <option  value="<?=$rowPlayer['ID']?>"><?=stripslashes($rowPlayer['LastName']).',  '.stripslashes($rowPlayer['FirstName'])
          .
' ('.$rowPlayer['ID'].')'?></option>
<?php
  
}
}
?>
        </select>
        <input type="SUBMIT" name="Delete" value="Delete >>"></td>
    </tr>
    <tr><td colspan="4"><hr /></td></tr>
    <tr valign="CENTER">
      <td><strong>Update Player:</strong></td>
      <td>
        *Player #:<br />
        <select name="cboPlayerNum" onchange="document.player.submit()">
          <option value=""></option>
<?php
mysql_data_seek
($recPlayer0);
if (
mysql_num_rows($recPlayer) <> 0) {
  while (
$rowPlayer mysql_fetch_assoc($recPlayer)) {
    if (isset(
$_POST['cboPlayerNum']) && $_POST['cboPlayerNum'] == $rowPlayer['ID']) {
      
$sel ' SELECTED';
    } else {
      
$sel '';
    }
?>
           <OPTION  VALUE="<?=$rowPlayer['ID']?>"<?=$sel?>>(<?=$rowPlayer['ID']?>)  <?=$rowPlayer['LastName']?><?=
          $rowPlayer
['FirstName']?></option>
<?php
  
}
}
if (isset(
$_POST['cboPlayerNum']) && $_POST['cboPlayerNum'] <> '') {
  
$recPlayer mysql_query('SELECT * FROM player WHERE ID = '.addslashes($_POST['cboPlayerNum']).' AND SeasonID = '
               
.addslashes($_POST['cboSeason'])) ;
  
$rowPlayer mysql_fetch_assoc($recPlayer);
}
?>
        </select></td>
      <td>
        *Player First Name:<br />
         <input type="TEXT" name="txtPlayerFirstNameU" maxlength="50"  size="20"  value="<?=stripslashes($rowPlayer['FirstName'])?>"></td>
      <td>
        *Player Last Name:<br />
         <input type="TEXT" name="txtPlayerLastNameU" maxlength="50"  size="20" value="<?=stripslashes($rowPlayer['LastName'])?>">
    </tr>
    <tr valign="TOP">
      <td></td>
      <td>
        Player EMail:<br />
         <INPUT TYPE="TEXT" NAME="txtPlayerEMailU" MAXLENGTH="100" SIZE="20"  VALUE=<?=stripslashes($rowPlayer['EMail'])?>></td>
      <td>
        Player Image:<br /> // added   
        <textarea name="txtPlayerBio2U" maxlength="255" cols="25" rows="4" wrap="VIRTUAL"><?=
        stripslashes
($rowPlayer['Bio2'])?></textarea></td>
      <td>
        Player Bio:<br />
        <textarea name="txtPlayerBioU" maxlength="255" cols="25" rows="4" wrap="VIRTUAL"><?=
        stripslashes
($rowPlayer['Bio'])?></textarea></td>
      <td>
        <br /><input type="SUBMIT" name="Update" value="Update >>"></td>
  </table>
</form>
<hr />
<a  href="./">Main Admin Page</a> | <a  href="season.php">Season Admin Page</a> | <a  href="game.php">Game Admin Page</a> |
Player Admin Page | <a href="plays.php">Plays Admin Page</a>
<?php
require('../config/footer.php');
?>

Last edited by mercville; 03-19-2011 at 09:14 PM..
mercville is offline
View Public Profile
 
 
Register now for full access!
Old 03-19-2011, 07:36 PM Re: need help with this code
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
http://tycoontalk.freelancer.com/php...st-my-php.html
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
View Public Profile Visit NullPointer's homepage!
 
Old 03-19-2011, 07:56 PM Re: need help with this code
Super Spam Talker

Posts: 880
Name: Paul W
Trades: 0
Quote:
Originally Posted by NullPointer View Post
Indeed, but it won't make that code any prettier!

OP: what is the problem - you don't actually say.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is online now
View Public Profile
 
Old 03-19-2011, 09:03 PM Re: need help with this code
Average Talker

Posts: 21
Name: Mike
Trades: 0
This is the way it was

and i want to add to it

admin part for adding players



Last edited by mercville; 03-19-2011 at 09:10 PM..
mercville is offline
View Public Profile
 
Old 03-19-2011, 09:06 PM Re: need help with this code
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by PaulW View Post
Indeed, but it won't make that code any prettier!
It's not just the syntax highlighting. All of the tabbing is lost when you don't use PHP or code bbcode.

@OP repost your code using the PHP bbcode and provide a better explanation of what you want to do.

Also, this is unrelated, but everytime I see short tags (<? and <?=) I die a little inside. Don't use them. They kill the portability of your application, future versions of PHP won't support them, and it is a bad habit in general.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
View Public Profile Visit NullPointer's homepage!
 
Old 03-20-2011, 02:04 PM Re: need help with this code
Super Spam Talker

Posts: 880
Name: Paul W
Trades: 0
Alas, I wasn't referring to formatting
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is online now
View Public Profile
 
Old 03-20-2011, 07:38 PM Re: need help with this code
Average Talker

Posts: 21
Name: Mike
Trades: 0
for the admin page i added the image area ... so when i add the code <img src="j.jpg"> it will put the image to the player image before bio

mercville is offline
View Public Profile
 
Old 03-21-2011, 09:07 PM Re: need help with this code
Average Talker

Posts: 21
Name: Mike
Trades: 0
Thanks for all the help but i got it fix
mercville is offline
View Public Profile
 
Closed Thread     « Reply to need help with this code
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.22219 seconds with 12 queries