mikesta707 Posted September 7, 2009 Share Posted September 7, 2009 Ok, well make sure you have to correct permissions for your mysql user (though I believe the query would throw an error if you didnt have the permissions) try either surrounding the tablename with backticks, or writing the table name directly in the query (with and without backticks). The query is valid (i just tested it in my table, but with a different table name of course) so if it isn't returning anything than the table is empty (or doesn't exist) I don't really see any other way for it to be returning nothing, and not doing any errors. and also post the data in your table (leave out info as you see fit of course) also, if you are going to have a field with 0 or 1, I believe that a boolean column would be best as those can only have either 0 or 1 as values (as opposed to varchar columns, which can be any character) EDIT: oh, well that $ character can't be right, what does your query string look like again? try concatenating the variables to the string instead of writing them in there like $query = "SELECT ".$warning1.", ".$banned1." FROM ".$table.; Link to comment Share on other sites More sharing options...
DarkShadowWing Posted September 7, 2009 Author Share Posted September 7, 2009 um, no offense, but i have NO idea what you just said... Link to comment Share on other sites More sharing options...
kratsg Posted September 7, 2009 Share Posted September 7, 2009 var_dump($query) returned: string(37) "SELECT `warning`$ FROM users0001" I believe there's your problem. The second variable (I think $banned1 appears to be null or perhaps not being set right.. ) looking at the posted code, I think you made more changes... >.< Can anyone see anything diff? Link to comment Share on other sites More sharing options...
DarkShadowWing Posted September 7, 2009 Author Share Posted September 7, 2009 code: <? $conn = "localhost"; $user = "myuser"; $pass = "mypass"; $dbname = "metaldetect01"; $tbl = "users0001"; $warning1 = "`warning`"; $banned1 = "`banned`"; $con = mysql_connect($conn,$user,$pass); if (!$con) { die('Could not connect to database: "' . $dbname . '" because ' . mysql_error()); } mysql_select_db($dbname, $con); $query = "SELECT $warning1$ FROM $tbl"; var_dump($query."<br>\n"); //$query2 = "SELECT $banned1$ FROM $tbl"; //var_dump($query2); $result = mysql_query($query) or die(mysql_error()); //$result = mysql_query($query) or mysql_query($query2) or die(mysql_error()); $rows = mysql_num_rows($result); echo "$rows rows returned!<br />"; //now lets go through every row returned. while($row = mysql_fetch_assoc($result)){ $warning = $row[$warning1]; $banned = $row[$banned1]; echo "Warning: $warning<br />"; echo "Banned: $banned<br />"; if(isset($warning)){ Link to comment Share on other sites More sharing options...
mikesta707 Posted September 7, 2009 Share Posted September 7, 2009 old well dude $query = "SELECT $warning1$ FROM $tbl"; that should be $query = "SELECT $warning1, $banned1 FROM $tbl"; shouldnt it Link to comment Share on other sites More sharing options...
DarkShadowWing Posted September 7, 2009 Author Share Posted September 7, 2009 0 rows returned! Link to comment Share on other sites More sharing options...
mikesta707 Posted September 7, 2009 Share Posted September 7, 2009 do the same query in PHPMYADMIN and see if you get the same results. If so, then your table is empty. Beyond that I don't really know what to tell you, seeing as I just did the same query and it worked perfectly Link to comment Share on other sites More sharing options...
DarkShadowWing Posted September 7, 2009 Author Share Posted September 7, 2009 $warning1 = "`warning`"; $banned1 = "`banned`"; return `warning` and `banned` not warning and banned.. i need to create a variable that pulls a value from the database for both of those. i need to make $warning and $banned use a mysql_query().. so what can i do? Link to comment Share on other sites More sharing options...
mikesta707 Posted September 7, 2009 Share Posted September 7, 2009 well of course they return `warning` and `banned`.. thats what you set them as. And you are using them in the query.. the variable that pulls the values of those columns in the database is the $row variable. However, the problem is that your query isn't returning any rows for some reason. Do a var dump on your query as it stands currently, and run that same query in PHPmyadmin or SQL itself. Link to comment Share on other sites More sharing options...
DarkShadowWing Posted September 7, 2009 Author Share Posted September 7, 2009 how EXACTLY, step-by-step, do i insert the var_dump($query) into phpmyadmin.. it returned a syntax error for me.. Link to comment Share on other sites More sharing options...
DarkShadowWing Posted September 7, 2009 Author Share Posted September 7, 2009 anyone? also, in php, " var_dump($query)" returns "string(29) "SELECT , FROM users0001" " Link to comment Share on other sites More sharing options...
kratsg Posted September 7, 2009 Share Posted September 7, 2009 You don't put var_dump($query) in mysql, it's meant to output code (mainly for debugging) to the page so you can figure out what's going wrong. Link to comment Share on other sites More sharing options...
DarkShadowWing Posted September 7, 2009 Author Share Posted September 7, 2009 ok. im gonna post my whole php file tomorrow. im too tired to do it tonight. i will even post the sql file if needed. im DESPERATE to figure this out.. Link to comment Share on other sites More sharing options...
Philip Posted September 7, 2009 Share Posted September 7, 2009 I'm still lost on exactly what you want. From what I've gathered, you just want to pull a 1 or 0 from the db, no matter what row it comes from. Link to comment Share on other sites More sharing options...
DarkShadowWing Posted September 7, 2009 Author Share Posted September 7, 2009 sort of. i dont know how i should explain since you guys cant understand me. i want to pull A value from the warning and banned rows. Link to comment Share on other sites More sharing options...
DarkShadowWing Posted September 7, 2009 Author Share Posted September 7, 2009 here's the problem.. Notice: Undefined variable: warning in C:\myxampp\htdocs\detect\index.php on line 57 Notice: Undefined variable: banned in C:\myxampp\htdocs\detect\index.php on line 57 Link to comment Share on other sites More sharing options...
DarkShadowWing Posted September 7, 2009 Author Share Posted September 7, 2009 HERE's the problem. $query = "SELECT $warning, $banned FROM $tbl"; //var_dump($query."<br>\n"); $result = mysql_query($query) or die(mysql_error()); //now lets go through every row returned. while($row = mysql_fetch_assoc($result)){ $warning = $row[$warning1]; $banned = $row[$banned1]; $rows = mysql_num_rows($result); echo "$rows rows returned!<br />"; echo "Warning: $warning<br />"; echo "Banned: $banned<br />"; if(isset($warning)){ the problem is no matter which side of "while" its located, $row is undefined, OR $warning and $banned are undefined. Link to comment Share on other sites More sharing options...
Philip Posted September 7, 2009 Share Posted September 7, 2009 I'm guessing you want a where clause, otherwise you're pulling all the rows from the table, and since you're only asking for the warning and banned and not the usernames/id/whatever. $query = "SELECT warning, banned FROM table WHERE user = 'user'"; Even though there is no real advantage to putting it this way.... heres into variable form: $select = array('warning','banned'); // get the columns you want $table = 'table'; // select the table $user = 'someuser'; // of course you would want to sanitize this $query = "SELECT ".implode(', ',$select)." FROM {$table} WHERE user = '{$user}'"; var_dump($query); echo '<br>'; $result = mysql_query($query) or die(mysql_error()); $rows = mysql_num_rows($result); echo "{$rows} rows returned!<br />"; Link to comment Share on other sites More sharing options...
DarkShadowWing Posted September 7, 2009 Author Share Posted September 7, 2009 now it returns: string(57) "SELECT warning, banned FROM users0001 WHERE user = 'root'" Unknown column 'user' in 'where clause' code: $result = mysql_query($query) or die(mysql_error()); //now lets go through every row returned. while($row = mysql_fetch_assoc($result)){ $warning = $row[$warning1]; $banned = $row[$banned1]; $rows = mysql_num_rows($result); echo "$rows rows returned!<br />"; echo "Warning: $warning<br />"; echo "Banned: $banned<br />"; */ $select = array('warning','banned'); // get the columns you want $table = $tbl; // select the table // of course you would want to sanitize this $query = "SELECT ".implode(', ',$select)." FROM {$table} WHERE user = '{$user}'"; var_dump($query); echo '<br>'; $result = mysql_query($query) or die(mysql_error()); $rows = mysql_num_rows($result); echo "{$rows} rows returned!<br />"; if(isset($warning)){ Link to comment Share on other sites More sharing options...
DarkShadowWing Posted September 7, 2009 Author Share Posted September 7, 2009 Hi all. I have a small problem w/ mysql writer i made. according to this post: You are missing a fundemental understanding of how databases work. You can build a table that has NAME, ADDRESS, CITY, STATE, and AGE. Once you do that, you have a table with ZERO records in it. It's your responsibility to put data in it. So you might add some records like this: John, Main St, Hartford, CT, 36 Betty, Route 4, Albany, NY, 40 Chris, 23 Bee Road, San Francisco, CA, 78 Now you have a table with three records. And then you can perform select statements that will extract that data from the database. Just defaulting "warning" to 0 means that whenever you add a record to the table and don't define a value for the warning field, then the system will automatically use "0" for that record. But... You have not added a record to your table yet. So there is NO data in your table. If there is no data, then there is no data to have defaulted to "0". A table by itself has no data. You need to add records to it. How can I add not only a default value to warning and banned, but a regular value of 0 as well? code: <?php $conn = "localhost"; $user = "myuser"; $pass = "mypass"; $dbname = "metaldetect01"; $tbl = "users0001"; $con = mysql_connect($conn,$user,$pass); if (!$con) { die('Could not connect to database "'.$dbname. '" because ' . mysql_error()); } // Drop database mysql_query("DROP DATABASE IF EXISTS $dbname"); // Create database if (mysql_query("CREATE DATABASE $dbname")) { echo "Database \"".$dbname."\" created"; } else { echo "Error creating database: \"".$dbname."\"\nError msg: " . mysql_error(); } // Create table mysql_select_db($dbname, $con); $sql = "CREATE TABLE $tbl ( id int(11) NOT NULL auto_increment, number varchar(16) NOT NULL default '', Firstname varchar(32) NOT NULL default '', Lastname varchar(32) NOT NULL default '', email varchar(50) NOT NULL default '', statement varchar(255) NOT NULL default '', warning varchar(1) NOT NULL default '0', banned varchar(1) NOT NULL default '0', PRIMARY KEY (id) )TYPE=MyISAM;"; // Execute query mysql_query($sql,$con); mysql_close($con); ?> ANY help is GREATLY apprciated! Link to comment Share on other sites More sharing options...
bundyxc Posted September 7, 2009 Share Posted September 7, 2009 I would suggest that you really try to work hard on your problem-describing skills. I think that the reason we're on the third page of trying to help you is solely because you haven't been able to describe your problems, or your requested solution. Obviously nothing personal, just something you should think about. Link to comment Share on other sites More sharing options...
DarkShadowWing Posted September 7, 2009 Author Share Posted September 7, 2009 anyone? Link to comment Share on other sites More sharing options...
DarkShadowWing Posted September 7, 2009 Author Share Posted September 7, 2009 well excuse me for barely being able to understand some of what YOU guys say to.. so i think im doing just fine. Link to comment Share on other sites More sharing options...
DarkShadowWing Posted September 7, 2009 Author Share Posted September 7, 2009 sheesh, u coulda been nice to me instead of all mean like that. Link to comment Share on other sites More sharing options...
bundyxc Posted September 7, 2009 Share Posted September 7, 2009 As I mentioned, it's nothing personal, and I wasn't trying to be rude.... so please don't take it personally. I'm just saying that you'll get an answer much quicker that way. If you don't understand what we're saying... ask. We would rather teach you than just give you the answer. We're volunteering to help you. As of the time of this post, we will have posted 20 replies in all. I'm shocked that you aren't more appreciative. Nobody is getting paid to help you. We could have just ignored your post (and that would have been mucheasier). Being pissy with me because I gave you advice? Sure, as I assume you don't have the mindset of being thankful for help. Being pissy with them because you're asking higher-level questions than you understand? Unacceptable. They're volunteering their time, and you're being rude. I'd be more appreciative if I were you. Just saying. Link to comment Share on other sites More sharing options...
Recommended Posts