Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-11-2010, 02:15 PM   PM User | #1
1337hovie
New Coder

 
Join Date: Feb 2010
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
1337hovie is an unknown quantity at this point
HELP PLZ! new to php. Drop Down SORT by

Hi i need to have a drop down menu choose how to sort my tagboard.
Tagboard works fine.
I want to sort by either tag_date, tag_cid, or tag_name.
idk what is wrong with it.
i have error reporting and still dont understand, can someone just please point out to me what the problem is and HOW TO FIX IT!.

it has something to do with the variables, i dont think im calling the right ones? can someone jujst please fix this?

Thank you guys so much, i jsut want to get this damn project done with.
*note- i have two drop downs in there, for testing, you can remove one, just need one functional drop down*
the code:
PHP Code:
<?php   
error_reporting
(E_ALL);
 
$selected = array();
 
$orderby $_GET[orderby];
if(!
$orderby) { $orderby 'tag_date'; }
 
if(
$orderby == 'tag_date'
{
    
$orderby_query "order by tag_date";
}
else if(
$orderby == 'tag_cid')
{
    
$orderby_query "order by tag_cid";
}
else if(
$orderby == 'tag_name')
{
    
$orderby_query "order by tag_name";
}
else { unset(
$orderby); }
 
// If $orderby was valid set the selected sort option for the form.
 
if($orderby)
{
    
$selected[$orderby] = 'selected';
}
 
// Now run your SQL query with the $orderby_query variable.  Ex:
 
$query "select * from tagboard $orderby_query";
 
// SQL code goes here..
 
?>

<?

define
('HOST'"xxxx");
define('USER'"xxxx");
define('PASS'"xx");
define('DB'"xxx");

function 
doTags()
{
$conx mysql_connect(HOSTUSERPASS) or die("Unable to connect to MySQL Server");
mysql_select_db(DB) or die("Unable to select Database");

$stSql "SELECT tag_name, tag_cid, tag_entry, tag_date FROM tagboard $orderby";
$arrResult = @mysql_query($stSql);
if (!
$arrResult) { echo "Query Failed - Unable to Retrieve tags - ".mysql_error()." – Action Aborted"; exit(); }

if (
mysql_num_rows($arrResult) >= 1)
{

while (
$arrRow mysql_fetch_assoc($arrResult))
{
?>

<table width="100%" height="47" border="0" align="center" bgcolor="#FFFFFF">
<tr>
<td width="30%" height="30"><span style="font-family: verdana,arial,helvetica,sans-serif; font-size: 9px; color: #666666">  [<? echo date("F j, Y, g:i a"$arrRow['tag_date']); ?>]  </span></td>
<td width="15%"><span style="font-family: verdana,arial,helvetica,sans-serif; font-size: 12px; font-weight: bold; color: #000000"><? echo stripslashes($arrRow['tag_name']); ?></span></td>
<td width="10%"><span style="font-family: verdana,arial,helvetica,sans-serif; font-size: 9px; color: #686868"><? echo stripslashes($arrRow['tag_cid']); ?></span></td>
<td width="45%"><span style="font-family: verdana,arial,helvetica,sans-serif; font-size: 9px; color: #000000"><? echo nl2br(stripslashes($arrRow['tag_entry'])); ?></span></td>
</tr>
<tr>
  <td height="11" >  </td>
  <td></td>
  <td></td>
  <td></td>
</tr>
</table>
<?
}
} else {
?>
<p style="font-family: verdana,arial,helvetica,sans-serif; font-size: 11px; background-color: #FFFFFF">No entries to display</p>
<?
}
}

function 
doBoard()
{
?>
<html>
<head>
<title>Control Center Tag board</title>
<style>
body {
font-family: verdana,arial,helvetica,sans-serif; font-size: 11px; background-color: #FFFFFF; 
}
td {
font-family: verdana,arial,helvetica,sans-serif; font-size: 11px; color: #666666;
}
.inputform {
BORDER-RIGHT: #efefef 1px solid; BORDER-TOP: #000000 1px solid; FONT: 11px Verdana; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #efefef 1px solid; BACKGROUND-COLOR: #efefef
}
.inputformsub {
BORDER-RIGHT: 1px outset; PADDING-RIGHT: 2px; BORDER-TOP: 1px outset; PADDING-LEFT: 2px; PADDING-BOTTOM: 2px; FONT: 11px Verdana; BORDER-LEFT: 1px outset; PADDING-TOP: 2px; BORDER-BOTTOM: 1px outset; BACKGROUND-COLOR: #dedede
}
</style>
</head>
<body>
Sort by
<form method=get style="display: inline;" name='orderby_form'>
<input type=hidden name='param1' value="<?php print $param1?>">
<input type=hidden name='param2' value="<?php print $param2?>">
<select name=orderby onChange="orderby_form.submit();">
<option value='name' <?php print $selected[$orderby]; ?>>Name</option>
<option value='price_asc' <?php print $selected[$orderby]; ?>>Price (Low - High)</option>
<option value='price_desc' <?php print $selected[$orderby]; ?>>Price (High - Low)</option>
</select>
</form>
<div><div align="center">
<br>Sort by
<form method=get style="display: inline;" name='orderby_form'>
</form></td>
</tr>

</form><br>
<form action="board.php?do=Insert" target="tag_box" method="POST">
<table width="757" height="250" bgcolor="#FFFFFF" style="border: 1px solid #000000">
<tr>
<td width="501" height="150"><IFRAME name="tag_box" height="350" width="751" src="board.php?do=Tags" frameborder="0"></IFRAME></td>
</tr>
<tr>
<td height="100" align="center"><br>
  <table width="326" border="0">
    <tr>
      <td width="39">Name:</td>
      <td width="251"><input type="text" name="__name" size="20" maxlength="55" class="inputform"></td>
      <td width="22">&nbsp;</td>
    </tr>
    <tr>
      <td>CID:</td>
      <td><input type="text" name="__cid" size="6" maxlength="255" class="inputform"></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Entry:</td>
      <td><textarea name="__entry" cols="35" rows="4" class="inputform"></textarea></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Sort by:</td>
      <td><a href="sort"><span style="display: inline;">
        <select name=orderby onChange="orderby_form.submit();">
          <option value='name' <?php print $selected[$orderby]; ?>>Name</option>
          <option value="cid">CID</option>
          <option value="date">Date</option>
        </select>
      </span></a></td>
      <td><input type="submit" value="Submit Entry" class="inputformsub"></td>
    </tr>
  </table>
  </td></tr></table></form></div>
</body>
</html>
<?
}

function 
doInsert($__name$__entry$__cid)
{
$conx mysql_connect(HOSTUSERPASS) or die("Unable to connect to MySQL Server");
mysql_select_db(DB) or die("Unable to select Database");

$__name addslashes($__name);
$__url addslashes($__cid); 
$__entry addslashes($__entry);

if (empty(
$__name))
{
?>
<p style="font-family: verdana,arial,helvetica,sans-serif; font-size: 11px; background-color: #FFFFFF">Name Field Is Required</p>
<meta http-equiv="refresh" content="5;url='board.php?do=Tags'">
<?
} elseif (empty($__entry))
{
?>
<p style="font-family: verdana,arial,helvetica,sans-serif; font-size: 11px; background-color: #FFFFFF">Entry Field Is Required</p>
<meta http-equiv="refresh" content="5;url='board.php?do=Tags'">
<?
} else {

$stSql "INSERT INTO tagboard(tagId, tag_name, tag_cid, tag_entry, tag_date) values('', '$__name', '$__cid', '$__entry', ".time().")";
$arrResult = @mysql_query($stSql);
if (!
$arrResult) { echo "Query Failed - Unable to Retrieve tags - ".mysql_error()." – Action Aborted"; exit(); }

if (
mysql_affected_rows() == 1)
{
?>
<meta http-equiv="refresh" content="3;url='board.php?do=Tags'">
<?
} else {
echo 
"Unable to Add Entry to Database";
?>
<meta http-equiv="refresh" content="5;url='board.php?do=Tags'">
<?
}
}


$do = (isset($_GET['do']) ? $_GET['do'] : FALSE);

switch (
$do) {
case 
"Board":
doBoard();
break;
case 
"Tags":
doTags();
break;
case 
"Insert":
doInsert($_POST['__name'], $_POST['__entry'], $_POST['__cid']);
break;
default:
doBoard();
}
?>
1337hovie is offline   Reply With Quote
Old 02-11-2010, 02:49 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Is this thread directly related to this one?
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 02-11-2010, 02:53 PM   PM User | #3
1337hovie
New Coder

 
Join Date: Feb 2010
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
1337hovie is an unknown quantity at this point
yeah, ive posted on many forums, i guess i lost track of that one. My apologies, you can delete that one. i'm just looking for a proper solution.
fou, you've helped me before and you were a total lifesaver. Could you possibly help me find out why my code isnt working?

this is my updated code:
PHP Code:
<?php
 ini_set
('display_errors',1); 
error_reporting(E_ALL|E_STRICT); 
$selected = array();
$orderby          = (isset($_GET["orderby"])) ? strip_tags($_GET["orderby"]) : 'default';
$orderby_query    null;
switch (
$orderby) {
    case 
'cid':      
        
$orderby_query "order by tag_cid asc";
        break;
    case 
'name':
        
$orderby_query "order by tag_name";
        break;
    case 
'default':
        break;       
    case 
'date':      
        
$orderby_query "order by tag_date DESC";      
        break;
    }
    
// If $orderby was valid set the selected sort option for the form.
    
if($orderby) { 
        
$selected[$orderby] = 'selected';} 
        
// Now run your SQL query with the $orderby_query variable.  Ex:
        
$query 'SELECT tag_name, tag_cid, tag_entry, tag_date FROM tagboard SORT by tag_cid';
 
// SQL code goes here..

define('HOST'"xx");
define('USER'"xx");
define('PASS'"xx");
define('DB'"xx");

function 
doTags()
{
global 
$orderby_query;
$conx mysql_connect(HOSTUSERPASS) or die("Unable to connect to MySQL Server");
mysql_select_db(DB) or die("Unable to select Database");

$stSql "SELECT tag_name, tag_cid, tag_entry, tag_date FROM tagboard $orderby_query";
$arrResult = @mysql_query($stSql);
if (!
$arrResult) { echo "Query Failed - Unable to Retrieve tags - ".mysql_error()." – Action Aborted"; exit(); }

if (
mysql_num_rows($arrResult) >= 1)
{

while (
$arrRow mysql_fetch_assoc($arrResult))
{
?>

<table width="100%" height="47" border="0" align="center" bgcolor="#FFFFFF">
<tr>
<td width="30%" height="30"><span style="font-family: verdana,arial,helvetica,sans-serif; font-size: 9px; color: #666666">  [<? echo date("F j, Y, g:i a"$arrRow['tag_date']); ?>]  </span></td>
<td width="15%"><span style="font-family: verdana,arial,helvetica,sans-serif; font-size: 12px; font-weight: bold; color: #000000"><? echo stripslashes($arrRow['tag_name']); ?></span></td>
<td width="10%"><span style="font-family: verdana,arial,helvetica,sans-serif; font-size: 9px; color: #686868"><? echo stripslashes($arrRow['tag_cid']); ?></span></td>
<td width="45%"><span style="font-family: verdana,arial,helvetica,sans-serif; font-size: 9px; color: #000000"><? echo nl2br(stripslashes($arrRow['tag_entry'])); ?></span></td>
</tr>
<tr>
  <td height="11" >  </td>
  <td></td>
  <td></td>
  <td></td>
</tr>
</table>
<?
}
} else {
?>
<p style="font-family: verdana,arial,helvetica,sans-serif; font-size: 11px; background-color: #FFFFFF">No entries to display</p>
<?
}
}

function 
doBoard()
{
?>
<html>
<head>
<title>Control Center Tag board</title>
<style>
body {
font-family: verdana,arial,helvetica,sans-serif; font-size: 11px; background-color: #FFFFFF; 
}
td {
font-family: verdana,arial,helvetica,sans-serif; font-size: 11px; color: #666666;
}
.inputform {
BORDER-RIGHT: #efefef 1px solid; BORDER-TOP: #000000 1px solid; FONT: 11px Verdana; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #efefef 1px solid; BACKGROUND-COLOR: #efefef
}
.inputformsub {
BORDER-RIGHT: 1px outset; PADDING-RIGHT: 2px; BORDER-TOP: 1px outset; PADDING-LEFT: 2px; PADDING-BOTTOM: 2px; FONT: 11px Verdana; BORDER-LEFT: 1px outset; PADDING-TOP: 2px; BORDER-BOTTOM: 1px outset; BACKGROUND-COLOR: #dedede
}
</style>
</head>
<body>
<div><div align="center"><br>
<form action="board.php?do=Insert" target="tag_box" method="POST">
<table width="757" height="250" bgcolor="#FFFFFF" style="border: 1px solid #000000">
<tr>
<td width="501" height="150"><IFRAME name="tag_box" height="350" width="751" src="board.php?do=Tags" frameborder="0"></IFRAME></td>
</tr>
<tr>
<td height="100" align="center"><br>
  <table width="326" border="0">
    <tr>
      <td width="39">Name:</td>
      <td width="251"><input type="text" name="__name" size="20" maxlength="55" class="inputform"></td>
      <td width="22">&nbsp;</td>
    </tr>
    <tr>
      <td>CID:</td>
      <td><input type="text" name="__cid" size="6" maxlength="255" class="inputform"></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Entry:</td>
      <td><textarea name="__entry" cols="35" rows="4" class="inputform"></textarea></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Sort by:</td>
      <td><a href="sort"><span style="display: inline;">
        <select name=orderby onChange="orderby_form.submit();">
          <option value='tag_name' <?php print $selected[$orderby]; ?>>Name</option>
          <option value="tag_cid">CID</option>
          <option value="tag_date">Date</option>
        </select>
      </span></a></td>
      <td><input type="submit" value="Submit Entry" class="inputformsub"></td>
    </tr>
  </table>
  <br>
  <div id="cid" style="display: block"></div>
<div id="date" style="display: none"></td></tr></table></form></div>
</body>
</html>
<?
}

function 
doInsert($__name$__entry$__cid)
{
$conx mysql_connect(HOSTUSERPASS) or die("Unable to connect to MySQL Server");
mysql_select_db(DB) or die("Unable to select Database");

$__name addslashes($__name);
$__url addslashes($__cid); 
$__entry addslashes($__entry);

if (empty(
$__name))
{
?>
<p style="font-family: verdana,arial,helvetica,sans-serif; font-size: 11px; background-color: #FFFFFF">Name Field Is Required</p>
<meta http-equiv="refresh" content="5;url='board.php?do=Tags'">
<?
} elseif (empty($__entry))
{
?>
<p style="font-family: verdana,arial,helvetica,sans-serif; font-size: 11px; background-color: #FFFFFF">Entry Field Is Required</p>
<meta http-equiv="refresh" content="5;url='board.php?do=Tags'">
<?
} else {

$stSql "INSERT INTO tagboard(tagId, tag_name, tag_cid, tag_entry, tag_date) values('', '$__name', '$__cid', '$__entry', ".time().")";
$arrResult = @mysql_query($stSql);
if (!
$arrResult) { echo "Query Failed - Unable to Retrieve tags - ".mysql_error()." – Action Aborted"; exit(); }

if (
mysql_affected_rows() == 1)
{
?>
<meta http-equiv="refresh" content="3;url='board.php?do=Tags'">
<?
} else {
echo 
"Unable to Add Entry to Database";
?>
<meta http-equiv="refresh" content="5;url='board.php?do=Tags'">
<?
}
}


$do = (isset($_GET['do']) ? $_GET['do'] : FALSE);

switch (
$do) {
case 
"Board":
doBoard();
break;
case 
"Tags":
doTags();
break;
case 
"Insert":
doInsert($_POST['__name'], $_POST['__entry'], $_POST['__cid']);
break;
default:
doBoard();
}
?>
errors im getting:
Notice: Use of undefined constant orderby - assumed 'orderby' in /home/content/t/m/s/tmsolutions/html/board.php on line 6

Notice: Undefined index: orderby in /home/content/t/m/s/tmsolutions/html/board.php on line 6

Notice: Undefined variable: orderby in /home/content/t/m/s/tmsolutions/html/board.php on line 7

Notice: Undefined variable: orderby in /home/content/t/m/s/tmsolutions/html/board.php on line 50


Fou, Thank you my friend.
1337hovie is offline   Reply With Quote
Old 02-11-2010, 03:11 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
These two code blocks do not match. The second one will also have notices though.

As for the first block:
- Constant here is $orderby = $_GET[orderby]; , use $_GET['orderby']
- Index doesn't exist, ensure that you're defaulting it with: $orderby = isset($_GET['orderby']) ? $_GET['orderby'] : 'tag_date';

The remaining ones occur because you're else statement is unsetting the $orderby variable. That should happen as long as you don't have a valid match: if (!$orderby) should be false, so it will never default with that code.

Also, as you start executing you're functions, you will find that more and more notices will pop up. You'll need to look at properly handling scope.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 02-11-2010, 03:18 PM   PM User | #5
1337hovie
New Coder

 
Join Date: Feb 2010
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
1337hovie is an unknown quantity at this point
I changed the first block you said, and im still getting errors. i dont know what the issue is?

if you can jsut alter the code, so i know what the issue is? i;ve psoted many places, googled the heck out of this thing, and even got a book. i am just trying to move onto the next project and leave this one done and over with.

Fou Lou, can u like copy my code into your software, and just fix this please? i know im asking alot, but ive been on this for over 8 hours and im just looking to resolve this issue.

you can change names to whatever u want.
aslong as it sorts by the tag_date,tag_cid,tag_name.

or if you want to just leave the tagbaord,and just add a drop down option that will work - thatd be amazing.

Thanks in advance, Fou-Lou you are a god among men.

joey
1337hovie is offline   Reply With Quote
Old 02-11-2010, 04:50 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
PHP Code:
$selected = array(); 
  
$orderby = isset($_GET['orderby']) ? $_GET['orderby'] : 'tag_date';
// Looks to me like tag_date should be the default, this is beter of using either an else with the tag_date or a switch
$orderby_query 'ORDER BY ';
switch(
$orderby)
{
    case 
'tag_cid':
        
$orderby_query .= 'tag_cid';
        break;
    case 
'tag_name':
        
$orderby_query .= 'tag_name';
        break;
    default:
        
$orderby_query .= 'tag_date';

That replaces this
PHP Code:
$selected = array(); 
  
$orderby $_GET[orderby]; 
if(!
$orderby) { $orderby 'tag_date'; } 
  
if(
$orderby == 'tag_date')  

    
$orderby_query "order by tag_date"

else if(
$orderby == 'tag_cid'

    
$orderby_query "order by tag_cid"

else if(
$orderby == 'tag_name'

    
$orderby_query "order by tag_name"

else { unset(
$orderby); } 
Post back with the errors after thats been corrected. You'll have more once you start trying you're functions because of the scope issues.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 02-11-2010, 04:59 PM   PM User | #7
1337hovie
New Coder

 
Join Date: Feb 2010
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
1337hovie is an unknown quantity at this point
Parse error: syntax error, unexpected '{' in /home/content/t/m/s/tmsolutions/html/board2.php on line 10


this is my current code:

is it possible for you just copy it into your software and fix and post back? i think the issues are with the scope, how do i put it into a variable or function or wahteveR? im so new at php, its not even funny, i just need this project done to get it over with! :d ha thanks.

PHP Code:
 <?php
 error_reporting
(E_ALL);// Allowed Order Bys, Map these keys to these field names
 
$orderMap = array(    'date'     => 'tag_date',
                   
'cid'     => 'tag_cid',
                   
'name'    => 'tag_name',
                   );
 
 
$orderBy 'date';    // Default Key
 
 
if (array_key_exists($_GET['orderby'], $orderMap) {
    
$orderBy $_GET['orderby'];
}
    
$query "select * from tagboard ORDER BY " $orderMap[$orderBy]; /* No SQL injection is possible, because we verified it was in our array */
     
if($orderby == 'date') {    
     
$orderby_query "order by tag_date";
     }else if(
$orderby == 'cid') {    
     
$orderby_query "order by tag_cid";
     }else if(
$orderby == 'name') {    $orderby_query "order by tag_name";
     }else {    
$orderby null;} 
 
// SQL code goes here..

define('HOST'"xx");
define('USER'"xx");
define('PASS'"xx
define('DB', "
xx");

function doTags()
{
global $orderby_query;
$conx = mysql_connect(HOST, USER, PASS) or die("
Unable to connect to MySQL Server");
mysql_select_db(DB) or die("
Unable to select Database");

$stSql = "
SELECT tag_nametag_cidtag_entrytag_date FROM tagboard $orderby_query";
$arrResult = @mysql_query($stSql);
if (!$arrResult) { echo "
Query Failed Unable to Retrieve tags ".mysql_error()." – Action Aborted"; exit(); }

if (mysql_num_rows($arrResult) >= 1)
{

while ($arrRow = mysql_fetch_assoc($arrResult))
{
?>

<table width="
100%" height="47" border="0" align="center" bgcolor="#FFFFFF">
<tr>
<
td width="30%" height="30"><span style="font-family: verdana,arial,helvetica,sans-serif; font-size: 9px; color: #666666">  [<? echo date("F j, Y, g:i a"$arrRow['tag_date']); ?>]  </span></td>
<td width="15%"><span style="font-family: verdana,arial,helvetica,sans-serif; font-size: 12px; font-weight: bold; color: #000000"><? echo stripslashes($arrRow['tag_name']); ?></span></td>
<td width="10%"><span style="font-family: verdana,arial,helvetica,sans-serif; font-size: 9px; color: #686868"><? echo stripslashes($arrRow['tag_cid']); ?></span></td>
<td width="45%"><span style="font-family: verdana,arial,helvetica,sans-serif; font-size: 9px; color: #000000"><? echo nl2br(stripslashes($arrRow['tag_entry'])); ?></span></td>
</tr>
<tr>
  <td height="11" >  </td>
  <td></td>
  <td></td>
  <td></td>
</tr>
</table>
<?
}
} else {
?>
<p style="font-family: verdana,arial,helvetica,sans-serif; font-size: 11px; background-color: #FFFFFF">No entries to display</p>
<?
}
}

function 
doBoard()
{
?>
<html>
<head>
<title>Control Center Tag board</title>
<style>
body {
font-family: verdana,arial,helvetica,sans-serif; font-size: 11px; background-color: #FFFFFF; 
}
td {
font-family: verdana,arial,helvetica,sans-serif; font-size: 11px; color: #666666;
}
.inputform {
BORDER-RIGHT: #efefef 1px solid; BORDER-TOP: #000000 1px solid; FONT: 11px Verdana; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #efefef 1px solid; BACKGROUND-COLOR: #efefef
}
.inputformsub {
BORDER-RIGHT: 1px outset; PADDING-RIGHT: 2px; BORDER-TOP: 1px outset; PADDING-LEFT: 2px; PADDING-BOTTOM: 2px; FONT: 11px Verdana; BORDER-LEFT: 1px outset; PADDING-TOP: 2px; BORDER-BOTTOM: 1px outset; BACKGROUND-COLOR: #dedede
}
</style>
</head>
<body>
<div><div align="center"><br>
<form action="board.php?do=Insert" target="tag_box" method="POST">
<table width="757" height="250" bgcolor="#FFFFFF" style="border: 1px solid #000000">
<tr>
<td width="501" height="150"><IFRAME name="tag_box" height="350" width="751" src="board.php?do=Tags" frameborder="0"></IFRAME></td>
</tr>
<tr>
<td height="100" align="center"><br>
  <table width="326" border="0">
    <tr>
      <td width="39">Name:</td>
      <td width="251"><input type="text" name="__name" size="20" maxlength="55" class="inputform"></td>
      <td width="22">&nbsp;</td>
    </tr>
    <tr>
      <td>CID:</td>
      <td><input type="text" name="__cid" size="6" maxlength="255" class="inputform"></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Entry:</td>
      <td><textarea name="__entry" cols="35" rows="4" class="inputform"></textarea></td>
      <td><select name="orderby" onChange="orderby_form.submit();">          <option value="name">Name</option>          <option value="cid" <?php if ($orderBy == 'cid') { echo 'selected'; } ?>>CID</option>          <option value="date" <?php if ($orderBy == 'date') { echo 'selected'; } ?>>Date</option>        </select> </td>
    </tr>
    <tr>
      <td>Sort by:</td>
      <td><a href="sort"><span style="display: inline;">
        <select name=orderby onChange="orderby_form.submit();">
          <option value='tag_name' <?php print $selected[$orderby]; ?>>Name</option>
          <option value="tag_cid">CID</option>
          <option value="tag_date">Date</option>
        </select>
      </span></a></td>
      <td><input type="submit" value="Submit Entry" class="inputformsub"></td>
    </tr>
  </table>
  <br>
  <div id="cid" style="display: block"></div>
<div id="date" style="display: none"></td></tr></table></form></div>
</body>
</html>
<?
}

function 
doInsert($__name$__entry$__cid)
{
$conx mysql_connect(HOSTUSERPASS) or die("Unable to connect to MySQL Server");
mysql_select_db(DB) or die("Unable to select Database");

$__name addslashes($__name);
$__url addslashes($__cid); 
$__entry addslashes($__entry);

if (empty(
$__name))
{
?>
<p style="font-family: verdana,arial,helvetica,sans-serif; font-size: 11px; background-color: #FFFFFF">Name Field Is Required</p>
<meta http-equiv="refresh" content="5;url='board.php?do=Tags'">
<?
} elseif (empty($__entry))
{
?>
<p style="font-family: verdana,arial,helvetica,sans-serif; font-size: 11px; background-color: #FFFFFF">Entry Field Is Required</p>
<meta http-equiv="refresh" content="5;url='board.php?do=Tags'">
<?
} else {

$stSql "INSERT INTO tagboard(tagId, tag_name, tag_cid, tag_entry, tag_date) values('', '$__name', '$__cid', '$__entry', ".time().")";
$arrResult = @mysql_query($stSql);
if (!
$arrResult) { echo "Query Failed - Unable to Retrieve tags - ".mysql_error()." – Action Aborted"; exit(); }

if (
mysql_affected_rows() == 1)
{
?>
<meta http-equiv="refresh" content="3;url='board.php?do=Tags'">
<?
} else {
echo 
"Unable to Add Entry to Database";
?>
<meta http-equiv="refresh" content="5;url='board.php?do=Tags'">
<?
}
}


$do = (isset($_GET['do']) ? $_GET['do'] : FALSE);

switch (
$do) {
case 
"Board":
doBoard();
break;
case 
"Tags":
doTags();
break;
case 
"Insert":
doInsert($_POST['__name'], $_POST['__entry'], $_POST['__cid']);
break;
default:
doBoard();
}
?>
1337hovie is offline   Reply With Quote
Old 02-11-2010, 05:07 PM   PM User | #8
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
No, I'm at work and can't test any php code.
PHP Code:
 if (array_key_exists($_GET['orderby'], $orderMap) { 
    
$orderBy $_GET['orderby']; 

You're missing a closing ) on that if.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 02-11-2010, 05:36 PM   PM User | #9
1337hovie
New Coder

 
Join Date: Feb 2010
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
1337hovie is an unknown quantity at this point
heh ok well..this is my most current code.
it's pieced from working codes..so
PHP Code:
<?php
 
$selected 
= array();
 
$sortby $_GET[orderby];
if(!
$orderby) { $orderby 'tag_name'; }
 
if(
$orderby == 'tag_name'
{
    
$orderby_query "order by tag_date";
}
else if(
$orderby == 'tag_date')
{
    
$orderby_query "order by tag_cid";
}
else if(
$orderby == 'tag_cid')
{
    
$orderby_query "order by tag_name";
}
else { unset(
$orderby); }
 
// If $orderby was valid set the selected sort option for the form.
 
if($orderby)
{
    
$selected[$orderby] = 'selected';
}
 
// Now run your SQL query with the $orderby_query variable.  Ex:
 
$query "select * from tagboard $orderby_query";
 
// SQL code goes here..
define('HOST'"xx");
define('USER'"xx");
define('PASS'"xxx");
define('DB'"xx");

function 
doTags()
{
global 
$orderby_query;
$conx mysql_connect(HOSTUSERPASS) or die("Unable to connect to MySQL Server");
mysql_select_db(DB) or die("Unable to select Database");

$stSql "SELECT tag_name, tag_cid, tag_entry, tag_date FROM tagboard order by $sortby";
$arrResult = @mysql_query($stSql);
if (!
$arrResult) { echo "Query Failed - Unable to Retrieve tags - ".mysql_error()." – Action Aborted"; exit(); }

if (
mysql_num_rows($arrResult) >= 1)
{

while (
$arrRow mysql_fetch_assoc($arrResult))
{
?>
<table align="center" width="100%" bgcolor="#FFFFFF">
<tr>
<td><a href="<? echo stripslashes($arrRow['tag_url']); ?>"><? echo stripslashes($arrRow['tag_name']); ?></a></td>
</tr>
<tr>
<td><? echo nl2br(stripslashes($arrRow['tag_entry'])); ?></td>
</tr>
<tr>
<td><span style="font-family: verdana,arial,helvetica,sans-serif; font-size: 9px; color: #666666"> <? echo date("F j, Y, g:i a"$arrRow['tag_date']); ?></span></td>
</tr>
</table>
<?
}
} else {
?>
<p style="font-family: verdana,arial,helvetica,sans-serif; font-size: 11px; background-color: #FFFFFF">No entries to display</p>
<?
}
}

function 
doBoard()
{
?>
<html>
<head>
<title>DevShift.com Tag Board</title>
<style>
body {
font-family: verdana,arial,helvetica,sans-serif; font-size: 11px; background-color: #FFFFFF; 
}
td {
font-family: verdana,arial,helvetica,sans-serif; font-size: 11px; color: #666666;
}
.inputform {
BORDER-RIGHT: #efefef 1px solid; BORDER-TOP: #000000 1px solid; FONT: 11px Verdana; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #efefef 1px solid; BACKGROUND-COLOR: #efefef
}
.inputformsub {
BORDER-RIGHT: 1px outset; PADDING-RIGHT: 2px; BORDER-TOP: 1px outset; PADDING-LEFT: 2px; PADDING-BOTTOM: 2px; FONT: 11px Verdana; BORDER-LEFT: 1px outset; PADDING-TOP: 2px; BORDER-BOTTOM: 1px outset; BACKGROUND-COLOR: #dedede
}
</style>
</head>
<body>
<form action="board.php?do=Insert" target="tag_box" method="POST">
<table width="802" height="250" bgcolor="#FFFFFF" style="border: 1px solid #000000">
<tr>
<td height="150"><IFRAME name="tag_box" height="450" width="850" src="board.php?do=Tags" frameborder="0"></IFRAME></td>
</tr>
<tr>
<td height="100" align="center"><p>Name:<br><input type="text" name="__name" size="20" maxlength="55" class="inputform"><br>URL:<br><input type="text" name="__url" size="20" maxlength="255" value="http://" class="inputform"><br>Your Entry:<br><input type="text" name="__entry" size="20" maxlength="400" class="inputform">
</p>
  <br><br>
    <input type="submit" value="Submit Entry" class="inputformsub">
  </p></td>
</tr>
</table>
Sort by
<input type=hidden name='param1' value="<?php print $param1?>">
<input type=hidden name='param2' value="<?php print $param2?>">
<select name=sortby onChange="orderby_form.submit();" id="sortby">
  <option value='tag_name' <?php print $selected[$orderby]; ?>>Name</option>
  <option value='tag_cid' <?php echo $orderby ?>>Price (Low - High)</option>
  <option value='tag_date' <?php echo $orderby ?>>Price (High - Low)</option>
</select>
</form>
</body>
</html>
<?
}

function 
doInsert($__name$__entry$__url)
{
$conx mysql_connect(HOSTUSERPASS) or die("Unable to connect to MySQL Server");
mysql_select_db(DB) or die("Unable to select Database");

$__name addslashes($__name);
$__url addslashes($__url); 
$__entry addslashes($__entry);

if (empty(
$__name))
{
?>
<p style="font-family: verdana,arial,helvetica,sans-serif; font-size: 11px; background-color: #FFFFFF">Name Field Is Required</p>
<meta http-equiv="refresh" content="5;url='board.php?do=Tags'">
<?
} elseif (empty($__entry))
{
?>
<p style="font-family: verdana,arial,helvetica,sans-serif; font-size: 11px; background-color: #FFFFFF">Entry Field Is Required</p>
<meta http-equiv="refresh" content="5;url='board.php?do=Tags'">
<?
} else {

$stSql "INSERT INTO tagboard(tagId, tag_name, tag_url, tag_entry, tag_date) values('', '$__name', '$__url', '$__entry', ".time().")";
$arrResult = @mysql_query($stSql);
if (!
$arrResult) { echo "Query Failed - Unable to Retrieve tags - ".mysql_error()." – Action Aborted"; exit(); }

if (
mysql_affected_rows() == 1)
{
?>
<meta http-equiv="refresh" content="3;url='board.php?do=Tags'">
<?
} else {
echo 
"Unable to Add Entry to Database";
?>
<meta http-equiv="refresh" content="5;url='board.php?do=Tags'">
<?
}
}


$do = (isset($_GET['do']) ? $_GET['do'] : FALSE);

switch (
$do) {
case 
"Board":
doBoard();
break;
case 
"Tags":
doTags();
break;
case 
"Insert":
doInsert($_POST['__name'], $_POST['__entry'], $_POST['__url']);
break;
default:
doBoard();
}
?>
the errors i am getting are:
Notice: Use of undefined constant orderby - assumed 'orderby' in /home/content/t/m/s/tmsolutions/html/board.php on line 6

Notice: Undefined index: orderby in /home/content/t/m/s/tmsolutions/html/board.php on line 6

Notice: Undefined variable: orderby in /home/content/t/m/s/tmsolutions/html/board.php on line 7

Notice: Undefined variable: orderby in /home/content/t/m/s/tmsolutions/html/board.php on line 50

so it has soemthing to do with that. what should i change those names to, so that it'll work?

thanks
1337hovie is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 06:12 PM.


Advertisement
Log in to turn off these ads.