HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Help with a coding problem

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#29646 (In Topic #6808)

Non-joined user

im having problem with coding and the ocportal

basically i have coded a report system, i have created a block and uploaded the script.



The html part works fine, but the php doesnt.  It does allow the functions fine, but the rest of the codign it doesnt.



This is what I am using

<?php

 function encodestr($oldstr) {
    $oldstr=trim($oldstr);
    $oldstr=strip_tags($oldstr);
    $oldstr=sprintf("%s",$oldstr);
    addslashes($oldstr);
    return $oldstr;
  }
  function secureint($intstr) {
    if (!empty($intstr)) {
      settype($instr,'integer');
      $intint=sprintf("%d",$intstr);
      $newint=intval($intint);
    } else {$newint="";}
    if ($intstr==0) {$newint=0;}
$newint = substr($newint, 0,30);
    return $newint;
  }

#####view own reports#######
  $fetch=mysql_query("SELECT * FROM players WHERE `victim`='$username'"); 
  while ($info=mysql_fetch_array($fetch)) {
     $rid=$info[id];
  $player=$info[Player_Name];
  $playerid=$info[PID];
  $playerreason=$info[Reason];
  $playerdesc=$info[Discription];
  $pss1=$info[SS1];
  $pss2=$info[SS2];
  $pgame=$info[game];
  $status=$info[status];
  $htmllist.= "<tr><td>$rid</td><td>$player</td><td>$playerid</td><td>$sta
tus</td></tr>\n";

}
###########player report###########
 if (!isset($_POST['submit'])) {
   if ($_POST['name']) {
   $username=encodestr($_POST['name']);
  if ($_POST['playername']) {
   $playername=encodestr($_POST['playername']);
    if ($_POST['pid']) {
      $pid=secureint($_POST['pid']);
        if (empty($pid)) {$message="You need to enter a valid player name";} else if ($_POST['pid']) {
          $pid=secureint($_POST['pid']);
            if (empty($pid)) {$message="You need to enter a PID";} else if ($_POST['description']) {
              $description=encodestr($_POST['description']);
                $plreport=encodestr($_POST['Options']);
     $games=encodestr($_POST['Games']);
             $screenie=encodestr($_POST['screenshot']);
      mysql_query("INSERT INTO players (`playername`,`pid`,`reason`,`description`,`screenshot`,`scr
eenshot2`,`game`,`victim`,`status`,`dt`) VALUES ('$playername','$pid','$plreport','$description','$screenie'
,'None','$games','$username','waiting',NOW())");
             
        echo "<html>\n<head>\n  <title>Report Submission</title>\n";
                    echo "</head>\n<body bgcolor="#FFFFFF">\n  <center>\n    <br />";
                    echo "    <br />\nYou have submitted your report!<br />\n"; 
                    exit();
           
    }
   }
  }
 }
}
}
###########server report###########
 if (!isset($_POST['submit2'])) {
  if ($_POST['serverip']) {
   $serverip=encodestr($_POST['serverip']);
    if ($_POST['serverport']) {
      $serverport=secureint($_POST['serverport']);
        if (empty($serverip)) {$message="You need to enter a valid ip address";} else if ($_POST['serverport']) {
          $serverport=secureint($_POST['serverport']);
            if (empty($serverport)) {$message="You need to enter a valid Port";} else if ($_POST['description1']) {
              $description1=encodestr($_POST['description1']);
                $report=encodestr($_POST['Options1']);
     $games1=encodestr($_POST['Games1']);
       $screenie2=encodestr($_POST['screenshot2']);
      mysql_query("INSERT INTO server (`Server_IP`,`Server_Port`,`Reason`,`Dizcription`,`SS1`,`SS2
`,`game`,`victim`,`status`,`dt`) VALUES ('$serverip','$serverport','$report','$description1','$scree
nie2','None','$games1','$username','waiting',NOW())");
             
        echo "<html>\n<head>\n  <title>Report Submission</title>\n";
                    echo "</head>\n<body bgcolor="#000000">\n  <center>\n    <br />";
                    echo "    <br />\nYou have submitted your report!<br />\n"; 
                    exit();
           
    }
   }
  }
 }
}

#####view server reports###
  $fetch1=mysql_query("SELECT * FROM servers WHERE `victim`='$username'");  
  while ($info2=mysql_fetch_array($fetch1)) {
     $sid=$info2[id];
  $serverip=$info2[Server_IP];
  $serverport=$info2[Server_Port];
  $sreason=$info2[Reason];
  $sdesc=$info2[Dizcription];
  $sss1=$info2[SS1];
  $sss2=$info2[SS2];
  $svictim=$info2[victim];
  $sgame=$info2[game];
  $sstatus=$info2[status];
  $htmllist1.= "<tr><td>$sid</td><td>$serverip</td><td>$serverport</td><td>
$sstatus</td></tr>\n";

}

?>



It is come back errors with ' in my lines.  Any suggestions

Back to the top
 
Posted
Rating:
#29647
Avatar

If I quickly look one thing I can see is lines like this:

Code

  $player=$info[Player_Name];
should be:

Code

  $player=$info['Player_Name'];

ocPortal runs with all PHP errors turned on (including 'Notices'). This means that quality issues that often go unnoticed, will be noticed with ocPortal – the code is much more strict.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#29648

Non-joined user

It didnt work.



Seems really wierd it should work, but its not, any other suggestions?

Back to the top
 
Posted
Rating:
#29649
Avatar

What specific error do you get?


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#29650

Non-joined user

PHP NOTICE [8] Undefined variable: username (ocPortal version: 3.1.3, PHP version: 4.4.4, URL: /index.php?page=Submit_Reports)

Here is the stack trace:

Below is a stack trace revealing the state ocPortal was in when the error occurred. If this represents a bug in ocPortal's unmodified software, you may want to check ocportal.com for a fix, and if there isn't one, report this as a bug. Please note that merely posting a stack trace is not sufficient for us to solve your problem; the stack trace is just an aid that presents us with additional information. We still need to know the error message, the human situation, version numbers, and any other appropriate information.
We apologise for this problem and hope you will work with us so that we can fix it promptly.


File '/home/dizgame/public_html/sources/global2.php'
Line '695'
Function 'get_html_trace'
Args



File '/home/dizgame/public_html/sources/global2.php'
Line '433'
Function 'clean_exit'
Args 'PHP NOTICE [8] Undefined variable: username'



Function 'ocportal_error_handler'
Args 8

'Undefined variable: username'

'/home/dizgame/public_html/sources_custom/miniblocks/submit_
reports.php'

21

array



File '/home/dizgame/public_html/sources_custom/miniblocks/submit_
reports.php'
Line '21'
Function 'unknown'



File '/home/dizgame/public_html/sources/zones.php'
Line '868'
Args '/home/dizgame/public_html/sources_custom/miniblocks/submit_
reports.php'
Function 'require'



File '/home/dizgame/public_html/sources/zones.php'
Line '812'
Function 'do_block_hunt_file'
Args 'submit_reports'

array



File '/home/dizgame/public_html/sources/tempcode.php'
Line '725'
Function 'do_block'
Args 'submit_reports'

array



File '/home/dizgame/public_html/sources/tempcode.php'
Line '863'
Function 'handle_symbol_preprocessing'
Args array

NULL



File '/home/dizgame/public_html/sources/site.php'
Line '539'
Function 'handle_symbol_preprocessing'
Class 'ocp_tempcode'
Type '->'
Args



File '/home/dizgame/public_html/index.php'
Line '104'
Function 'do_site'
Args

Back to the top
 
Posted
Rating:
#29652
Avatar

Right… that stack dump says it's happening on line 21, which is the first line of code that is executed, and is:

Code

$fetch=mysql_query("SELECT * FROM players WHERE `victim`='$username'");  

It's saying $username doesn't exist, which is true. If we are looking to use the username of the logged in ocPortal user then it should be:

Code

$fetch=mysql_query("SELECT * FROM players WHERE `victim`='".addslashes($GLOBALS['FORUM_DRIVER']->get_username(get_member()))."'");  

However, I'm sure there will be similar issues throughout the code unfortunately - transplanting code without reviewing it typically causes issues like this. It's not operating in the context it was written for.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#29653
Avatar

Fan in training

is there a particular way to code php into ocportal and it work.

I have looked and looked and your tutorials and my coding is practically the same.

But the system wont accept it.  Can my coding be inserted into functions and still work?
Back to the top
 
Posted
Rating:
#29654
Avatar

ocPortal is all standard PHP, with errors turned on full, so you can put in any valid code.

But each individual line of the code has to be correct for what it's doing and where it is put. So for example, the $username problem was inevitable - because a line of code assumed there was a '$username' variable defined at that point, and there wasn't.

There's no trick, it's just normal coding. And, normal debugging. However, I get the feeling this code was not written for ocPortal, but rather largely written by someone else and pasted in. I'd expect the author would have a fuller understanding of the assumptions he/she made, and know if or if not those assumptions hold true for the new context the code is running in - and how to change them.

Here's an example line:

Code

        echo "<html>\n<head>\n  <title>Report Submission</title>\n";
This line assumes that an HTML document is being outputted by the script. However, this is not the case as the output is to go within a larger HTML document - so the code would need adjusting for that. This particular example wouldn't cause an error, but it would cause the page HTML to be invalid (because it would contain two <html> tags).


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
There are too many online users to list.
Control functions:

Quick reply   Contract

Your name:
Your message: