Jump to content

Archived

This topic is now archived and is closed to further replies.

alarik149

is this script ok?

Recommended Posts

$sql=mysql_query("CREATE TABLE `round` (`username` CHAR( 20 ) NOT NULL ,`status` CHAR( 20 ) NOT NULL ) TYPE = MYISAM ;");
if ($sql) echo "report successful!";
else echo "ERROR";

this is part of a bigger script but i think the error is here.

Share this post


Link to post
Share on other sites
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]this is part of a bigger script but i think the error is here.[/quote]
If there is an error then the answer to your question would be NO.

Mind telling us what the error might be?

Share this post


Link to post
Share on other sites
Please post your code and tell us what error you're getting.

Ken

Share this post


Link to post
Share on other sites
:) 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:).

Share this post


Link to post
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..

Share this post


Link to post
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?

Share this post


Link to post
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]

Share this post


Link to post
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:)

Share this post


Link to post
Share on other sites
On first glance, I see this line:[code]<?php if ($table[0] = "$table") ?>[/code]
I believe you want "==" not "=" here
[code]<?php if ($table[0] == "$table") ?>[/code]

Ken

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.