Jump to content

Recommended Posts

:) I really really apreciate your help guys,this forum is by far the most helpful in any domains i have ever seen:) but for the moment I want to hit my brains a little more to that script,it`s about 50 lines and,long lines..but I'll come back here when I consider I'm really stuck:).
Link to comment
https://forums.phpfreaks.com/topic/4852-is-this-script-ok/#findComment-17077
Share on other sites

ok now i`m really stuck.I`ve been testing the script and trying to find the error for a few hours..just reading and testing..

<?php

$db = mysql_connect('localhost', 'username', 'password');
mysql_select_db('championships', $db);


$result = mysql_query("SELECT * from misc");
while($row=mysql_fetch_array($result)) { if($row['username']=='a')
$round=$row['round']; }
$result1 = mysql_query("SELECT * from round$round");
while($row=mysql_fetch_array($result)) { if($row['username']=='a')
$status=$row['status']; }
if($status=='pending') {
$sql = mysql_query("UPDATE round$round SET status = 'win' WHERE username = 'a' ");
$next_round=$round+1;
$sql1 = mysql_query("UPDATE misc SET round = '$next_round' WHERE username = 'a' ");

$query=mysql_query("show tables like '$table'");
$table = mysql_fetch_array($query);
if ($table[0] = "$table") {
$sq2 = mysql_query("UPDATE round$next_round SET status = 'pending' WHERE username = 'a' ");
} else {
$sql3=mysql_query("CREATE TABLE `round$next_round` (`username` CHAR( 20 ) NOT NULL ,`status` CHAR( 20 ) NOT NULL ,PRIMARY KEY ( `username` ) ) TYPE = MYISAM ;");
$sq2 = mysql_query("UPDATE round$next_round SET status = 'pending' WHERE username = 'a' "); }


}
if ($sql && $sql1 && $sql2 && $sql3) echo "report successful!";
else echo "ERROR";

if($status=='lost') { echo "sorry,you are already disqualified from this event"; }
else { echo "errrrror"; }

?>

I think the script can be understood with no dificulty.I just can`t find the problem,from my tests it starts from here : $result1 = mysql_query("SELECT * from round$round");
while($row=mysql_fetch_array($result)) { if($row['username']=='a')
$status=$row['status']; }
$status dosen`t take the value that it should.
tell me if I need to explain exacly what this script suposed to do.
Thanks in advance just for reading such a long script..
Link to comment
https://forums.phpfreaks.com/topic/4852-is-this-script-ok/#findComment-17093
Share on other sites

Alright bud we've got a few problems with this one...
[ol type=\'1\'][*]Syntax structure is a pain to read[*]No indeentation[*]Variable names aren't so meaningful[*]You didn't put code in code tabs[*]You didn't really explain what you're trying to do[/ol]
There's a possibility that, whatever you're trying to do, can be done a lot easier. Your 3 query statements are a test to that, and I am quite unsure why you would want to create tables like this.

So.. let's try again, yes?

Link to comment
https://forums.phpfreaks.com/topic/4852-is-this-script-ok/#findComment-17098
Share on other sites

Ok i have neatend your code up by indenting it and adding code blocks where i thought u wanted them to be, but there is still the other problems that keeB mentioned. Try this and see if its any closer, it should now be easier to see where you have gone if you indent and use code blocks like i have it makes the code much easier to read and understand:

[code]<?php

$db = mysql_connect('localhost', 'username', 'password');
mysql_select_db('championships', $db);


$result = mysql_query("SELECT * from misc");
while($row=mysql_fetch_array($result))
{
    if($row['username']=='a')
    {
        $round=$row['round'];
    }
}
$result1 = mysql_query("SELECT * from round$round");
while($row=mysql_fetch_array($result))
{
    if($row['username']=='a')
    {
        $status=$row['status'];
    }

    if($status=='pending')
    {
        $sql = mysql_query("UPDATE round$round SET status = 'win' WHERE username = 'a' ");
        $next_round=$round+1;
        $sql1 = mysql_query("UPDATE misc SET round = '$next_round' WHERE username = 'a' ");
        $query=mysql_query("show tables like '$table'");
        $table = mysql_fetch_array($query);
    }
    if ($table[0] = "$table")
    {
        $sq2 = mysql_query("UPDATE round$next_round SET status = 'pending' WHERE username = 'a' ");
    }
    else
    {
        $sql3=mysql_query("CREATE TABLE `round$next_round` (`username` CHAR( 20 ) NOT NULL ,`status` CHAR( 20 ) NOT NULL ,PRIMARY KEY ( `username` ) ) TYPE = MYISAM;");
        $sq2 = mysql_query("UPDATE round$next_round SET status = 'pending' WHERE username = 'a' ");
    }
}
if ($sql && $sql1 && $sql2 && $sql3)
{
    echo "report successful!";
}
else
{
    echo "ERROR";
}

if($status=='lost')
{
    echo "sorry,you are already disqualified from this event";
}
else
{
    echo "errrrror";
}

?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/4852-is-this-script-ok/#findComment-17106
Share on other sites

:) it`s part of a big script i`m working at for about 2 weeks.made it 2 times and this is the 3rd and final I hope,this time bugless.
So I am working on a script to manage a championship.Each user enteres and signes up.his username(noted in my script with variable $a) is posted into a database named championships,table "round1".the round1 table contains 2 fields : 'username' and 'status'.$a is placed into field 'username' and in field 'status' will be pending.this is done by another script.
In database championships I have another table names 'misc' that contains 2 fields.1 - 'username' and 2 - 'round'.each player has it`s name in round1 table and in misc table,under fields username.the second field of 'misc' is suposed to determine the curent round each player is in.
So now I have to make 2 scripts,report_loss and report_win.I have no knowledge of using keys so I have to do it without.In my brain it is all clear how I have to do but it`s hard to implement.
What I posted is the report_win script.each player that wins clickes that script and the script looks in 'misc',sees his current round(from field round) and places it into variable $round.then searches for the player(username is $a) into the 'round$round' table and places instead of 'pending','win'.Then the script tests if there is a table names 'round$round+1'(names in my script $next_round) and if it isn`t it creates it.after that it adds the username $a into the new table(round2 for example) and sets the status of the second round to 'pending'.
I hope I was clear enough:(.
Really thanks for your time:)
Link to comment
https://forums.phpfreaks.com/topic/4852-is-this-script-ok/#findComment-17111
Share on other sites

i made it into blocks into separate files and the mini-scripts worked:(.
anyway after typing what I`ve done there i saw a misstake
$sql2 = mysql_query("UPDATE round$next_round SET status = 'pending' WHERE username = 'a' "); is actually
$sql2 = mysql_query("INSERT INTO round$next_round (username, status) VALUES ('d','pending')");

I modified this and added the double "=" but still i get errors:(.but i think we`re on the right track :p
Link to comment
https://forums.phpfreaks.com/topic/4852-is-this-script-ok/#findComment-17117
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.