Reply
PHP not displaying on screen
Old 04-29-2007, 11:16 AM PHP not displaying on screen
hamesy's Avatar
PR is NOT important!!!!

Posts: 575
Name: Steve
Location: Birmingham, England
Hi there,

I've got a little script that gets the userid from the url then displays scores for that user. I'm not sure if the script is being run, but I basically get everything apart from the echo of php script (hope that makes sense).

I've took a screenshot of what I seen.
http://www.hamesy.com/images/php_problem.JPG

This is the code:
PHP Code:
<?php
 
//connect to database
 
$conn mysql_connect("localhost""something""something")
     or die(
mysql_error());
 
mysql_select_db("something",$conn) or die(mysql_error());
  
//create the sql statement
//validate item
 
$sql "select * from highscores where userid = $_GET[userid]";
 
  
//execute the sql statement
 
$result mysql_query($sql$conn) or die(mysql_error());
  
//go through each row in result set and display data


    //echo the results on screen
     
while ($newArray mysql_fetch_array($result)) {
      
//give a name to the fields
    
$userid $newArray['userid'];
    
 
$result mysql_query($sql$conn) or die(mysql_error());
  
//go through each row in result set and display data
//echo the results on screen
    
echo "  Your scores are as follows:<br><table width=200 border=1>
    <tr>
      <td>Score</td>
    </tr> "
;
     while (
$newArray mysql_fetch_array($result)) {
      
//give a name to the fields
    
$score $newArray['score'];
    echo 
"
    <tr>
      <td>$score</td>
    </tr>"
; }
    echo 
"  </table>";
}
    
?>
Anyone have any ideas?
__________________
Hamesy
Affordable and Reliable Hosting: Pastilles Networks
Jay Jay Marine: Sail into your dreams...

Last edited by hamesy : 04-29-2007 at 11:17 AM.
hamesy is offline
Reply With Quote
View Public Profile Visit hamesy's homepage!
 
When You Register, These Ads Go Away!
Old 04-29-2007, 01:02 PM Re: PHP not displaying on screen
tripy's Avatar
Fetchez la vache!

Posts: 2,054
Name: Thierry
Location: In the void
Hmmm, just wondering, why are you running your query twice ?

You run it once, and extract the username from every rows in it. But in the while() loop, you run it again.
It's useless, remove the second mysql_query().

Appart from that, you totally mixed thing inside and outside the loop, and you where closing a block that was never opened (the last } )

Try this code:
PHP Code:
<?php
  
//connect to database
  
$conn mysql_connect("localhost""something""something") or die(mysql_error());
  
mysql_select_db("something",$conn) or die(mysql_error());
  
  
//create the sql statement
  
$sql "select * from highscores where userid = $_GET[userid]";
 
  
//execute the sql statement
  
$result mysql_query($sql$conn) or die(mysql_error());
  
  
//go through each row in result set and display data
  
  /*
  tripy
  First, output your header
  */
  
echo "  Your scores are as follows:<br><table width=200 border=1>
    <tr>
      <td>Score</td>
    </tr> "
;
  
  
/*
  tripy
  now parse the results...
  */
  
while ($newArray mysql_fetch_array($result)) {
    
$userid $newArray['userid'];
    
$score $newArray['score'];
    echo 
"
    <tr>
      <td>$score</td>
    </tr>"

  }
  
  
/*
  tripy
  And finally, close your table.
  */
  
echo "</table>";
?>
__________________
Listen to the ducky: "This is awesome!!!"

tripy is offline
Reply With Quote
View Public Profile
 
Old 04-29-2007, 02:04 PM Re: PHP not displaying on screen
kaisellgren's Avatar
Extreme Talker

Posts: 214
Name: Kai Sellgren
Location: Finland
Also, do not forget to protect against SQL injections.

show_scores.php?userid=;

Would procedure a MySQL error telling us that you are using a field named 'userid', then we can add it to our GET superglobal like:

show_scores.php?userid=userid

To get all results. Basically we can do a lot more worse than that.

To learn more about SQL injections, see my article.

Protecting Against SQL Injections
__________________
Adept Web Community
kaisellgren is offline
Reply With Quote
View Public Profile Visit kaisellgren's homepage!
 
Old 04-29-2007, 03:10 PM Re: PHP not displaying on screen
tripy's Avatar
Fetchez la vache!

Posts: 2,054
Name: Thierry
Location: In the void
True, I totally bypassed that issue, but you (hamesy) should protect your pages against such attacks.
__________________
Listen to the ducky: "This is awesome!!!"

tripy is offline
Reply With Quote
View Public Profile
 
Old 04-29-2007, 04:22 PM Re: PHP not displaying on screen
kaisellgren's Avatar
Extreme Talker

Posts: 214
Name: Kai Sellgren
Location: Finland
Quote:
Originally Posted by tripy View Post
True, I totally bypassed that issue, but you (hamesy) should protect your pages against such attacks.
No, you just answerred to his question as he wanted. You never needed to tell anything about SQL injections. I just mentioned about these kind of attacks on a side note.
__________________
Adept Web Community
kaisellgren is offline
Reply With Quote
View Public Profile Visit kaisellgren's homepage!
 
Old 04-29-2007, 08:55 PM Re: PHP not displaying on screen
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
Wireless Audio
Posts: 2,320
Name: Keith Marshall
Location: West Hartford, CT
Quote:
Originally Posted by kaisellgren View Post
Also, do not forget to protect against SQL injections.

show_scores.php?userid=;

Would procedure a MySQL error telling us that you are using a field named 'userid', then we can add it to our GET superglobal like:

show_scores.php?userid=userid

To get all results. Basically we can do a lot more worse than that.

To learn more about SQL injections, see my article.

Protecting Against SQL Injections
I personally also use type casting a lot myself, mainly when comparing integer id's
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP not displaying on screen
 

Thread Tools

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

vB 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 0.14011 seconds with 12 queries