Author Topic: MySql query is not going  (Read 744 times)

Offline 133794m3r

  • Level 22
  • *
  • Posts: 265
  • Reputation: +2/-0
    • View Profile
MySql query is not going
« on: November 20, 2009, 03:00:01 AM »
Ok this is a truncated version of the code. I have truncated teh various ifs so that it'd be a bit shorter. Also i truncated the formula as it seems to be working. The only problem i'm having is apparently with the MySQL connection. I have the dbnamed, i have the host set, and i even set up a user on my own local thing for this.

If anyone can explain to me why the mysql connection's aren't going on that'd be a great deal of help. As it seems to be to me atleast that they should be infact happening. I followed the tutorial on bbgs for the mysql connection code. So i dont' see why it should be fighting me like it is.
Code: [Select]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        
If ($_POST){
       
$CL $_POST['level'];
       
$dbhost 'localhost';
       
$dbuser 'user';
       
$dbpass 'password';
       
$dbname 'various_values';
       if (
$CL<= 120){
           
$conn mysql_connect($dbhost,$dbuser,$dbpass)
       or die (
'ERROR CONNECTING');
       
$querysprintf("SELECT EXP from xp WHERE Level = ($CL-1)");
       
$PXP mysql_query($query);
   echo $PXP;
      If(
$CL>=and $CL<=10){
          
$MKXP 154
          $BXPM 
=2
      
}
      
$XP_Lvl = (($MKXP*$BXPM)+($CL*5)
  $query sprintf("INSERT INTO xp(EXP) VALUE $XP_Lvl");
      
mysql_query($query);
      
$CL $CL++;
  }
  }
        
?>

        <form method="post" action="expcalc.php">
            Level:<input type='level' name='level' /><br />
            <input type='submit' value='level!' />
        </form>
    </body>
</html>

Offline Nox

  • Level 35
  • **
  • Posts: 767
  • Reputation: +12/-2
    • View Profile
Re: MySql query is not going
« Reply #1 on: November 20, 2009, 03:17:42 AM »
So...does it output "error connecting"? We'll probably need more info then... running on local? is mysql actually running? user properties set properly?...

If not then -> you don't have the database selected (mysql_select_db())...well, that's necessary anyway

----
Again - why you use sprintf without any arguments? This way it does nothing...

I'd also suggest better variable naming... instead of $CL rather $characterLevel or $character["level"] or something.... I'm not sure you'll be able to remember purpose of dosens of variables named like BXPM (I have no idea what does it mean :) )

Echo $PXP won't output anything since mysql_query returns either boolean (true/false) or resource type (kinda collection, pack of data you got from DB)... for 1 column you can use mysql_result, for more columns take a look at mysql_fetch_array()

Code: [Select]
INSERT INTO xp(EXP) VALUE $XP_Lvlhas imho incorrect syntax
Code: [Select]
INSERT INTP xp (EXP) VALUES ($XP_Lvl)^
btw. it's better to write either camel case (someVariable) or underscore with all lower case (some_variable)...you versionis kinda more difficult to write
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline 133794m3r

  • Level 22
  • *
  • Posts: 265
  • Reputation: +2/-0
    • View Profile
Re: MySql query is not going
« Reply #2 on: November 20, 2009, 03:24:52 AM »
Now it didn't do "error connecting"
and hmm i thought that did something... i guess i'll have to do "select" and ah ok i seemed to have forgotten it. And i'm typing up my variables as i remember them. $CL=Character level. $MKXP =Mob Kill Exp, $BXPM = Bonus EXP Modifier. And i can't believe i forgot to select the db -_-. I feel like a moron.

Offline Nox

  • Level 35
  • **
  • Posts: 767
  • Reputation: +12/-2
    • View Profile
Re: MySql query is not going
« Reply #3 on: November 20, 2009, 03:42:34 AM »
You remember them now, but let's take some less obvious variables and wait several months and then should you want to modify something you'll spend a long time figuring out what the heck you wrote there :) you know...many of us been there before too :)
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: MySql query is not going
« Reply #4 on: November 20, 2009, 09:14:19 AM »
I would like to point out... it's not required that you select a database. However, if you don't do so, you must fully qualify any table names that you use:

<table> becomes <database>.<table>

**edit corrected accidental use of bbcode table tag.
Idiocy - Never underestimate the power of stupid people in large groups.


 


SimplePortal 2.3.3 © 2008-2010, SimplePortal