Jump to content


Photo

is this script ok?


  • Please log in to reply
11 replies to this topic

#1 alarik149

alarik149
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 13 March 2006 - 05:11 PM

$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.
Tired of math homework ? Just visit http://www.solvemymath.com for a free online math solver and calculator.
Videochat bucuresti studio -> http://www.GirlAddicts.com
About the adult video chat business -> www.girlplan.com

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 13 March 2006 - 05:23 PM

[!--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?

#3 alarik149

alarik149
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 13 March 2006 - 05:25 PM

ok thanks,i`ll keep searching.
Tired of math homework ? Just visit http://www.solvemymath.com for a free online math solver and calculator.
Videochat bucuresti studio -> http://www.GirlAddicts.com
About the adult video chat business -> www.girlplan.com

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 13 March 2006 - 05:42 PM

Please post your code and tell us what error you're getting.

Ken

#5 alarik149

alarik149
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 13 March 2006 - 06:11 PM

:) 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:).

Tired of math homework ? Just visit http://www.solvemymath.com for a free online math solver and calculator.
Videochat bucuresti studio -> http://www.GirlAddicts.com
About the adult video chat business -> www.girlplan.com

#6 alarik149

alarik149
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 13 March 2006 - 07:19 PM

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..
Tired of math homework ? Just visit http://www.solvemymath.com for a free online math solver and calculator.
Videochat bucuresti studio -> http://www.GirlAddicts.com
About the adult video chat business -> www.girlplan.com

#7 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 13 March 2006 - 07:29 PM

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?


Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/


#8 php_b34st

php_b34st
  • Members
  • PipPipPip
  • Advanced Member
  • 168 posts

Posted 13 March 2006 - 07:40 PM

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:

<?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";
}

?>


#9 alarik149

alarik149
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 13 March 2006 - 07:42 PM

:) 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:)
Tired of math homework ? Just visit http://www.solvemymath.com for a free online math solver and calculator.
Videochat bucuresti studio -> http://www.GirlAddicts.com
About the adult video chat business -> www.girlplan.com

#10 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 13 March 2006 - 07:43 PM

On first glance, I see this line:
<?php if ($table[0] = "$table") ?>
I believe you want "==" not "=" here
<?php if ($table[0] == "$table") ?>

Ken

#11 alarik149

alarik149
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 13 March 2006 - 07:52 PM

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
Tired of math homework ? Just visit http://www.solvemymath.com for a free online math solver and calculator.
Videochat bucuresti studio -> http://www.GirlAddicts.com
About the adult video chat business -> www.girlplan.com

#12 alarik149

alarik149
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 13 March 2006 - 09:40 PM

oh..nevermind people:) i think I got it,a few little errors:).thanks anyway
Tired of math homework ? Just visit http://www.solvemymath.com for a free online math solver and calculator.
Videochat bucuresti studio -> http://www.GirlAddicts.com
About the adult video chat business -> www.girlplan.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users