-
Posts
2,965 -
Joined
-
Last visited
Everything posted by mikesta707
-
[SOLVED] HELP! Getting "Query was empty" error!
mikesta707 replied to DarkShadowWing's topic in PHP Coding Help
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.; -
[SOLVED] HELP! Getting "Query was empty" error!
mikesta707 replied to DarkShadowWing's topic in PHP Coding Help
are you sure you are using the right table name and connected to the right database then? -
dont put the function at the very top, put where the function is called. IE //the following call $id = "whatever"; download($id); should be at the top of the page. If in whatever script you have it can't be, then you are going to have to take the header out of the function. Besides, Having header calls in functions like that tends to lead problems like you are having. alternatively, you can put ob_start(); at the top of the page and ob_flush(); at the very bottom to get around this. However, make sure you put a die() after the header, as things can go awry if you don't. However, if you find you must take this route, you may want to rethink the design of your function. take a read of ob_start() and flush in the php manual for more info
-
this means that you have output sent beore that line. Make sure there is no output at all (even HTML output) where that function is called. preferably, put the function call at the very top of the page.
-
[SOLVED] query not returning correct number of records. please help
mikesta707 replied to debuitls's topic in PHP Coding Help
if the number of bids made is equal to the number of rows returned, than kats previous advice to use mysql_num_rows would work. I'm not entirely sure if this is true, if it is, then that would probably be the easiest solution if you are having so much trouble getting the query to return the count. to use mysql_num_rows just stick in a line like that after your query $query = mysql_query("MY QUERY"); //THE FOLLOWING LINE IS THE IMPORTANT ONE $num = mysql_num_rows($query); this is of course a very simplified version without any debug checks, but the basic logic is there. -
check if number already exists in database
mikesta707 replied to saltedm8's topic in PHP Coding Help
thats because, if(mysql_num_rows($turn = mysql_query("SELECT letable WHERE id =$id LIMIT 1"))) is incorrect syntax. $turn = mysql_query("SELECT letable WHERE id =$id LIMIT 1") is a boolean statement. It basically means if $turn is assigned the value of that query, return true. else return false I posted the fixed version one post up. change it to that -
there seems to be a square bracket in your query mysql_query("SELECT bus_id FROM businesses WHERE password='password' AND bus_id='username]here'") its not messing up anything oddly enough, but you may want to get rid of that. also, you can run into problems with mysql_result as I think the row number in the second paramter corresponds to the row number of the table, not of the returned values. use mysql_fetch_array instead $row = mysql_fetch_array($result); $num = $row['bus_id']; and also, you aren't passing your post variables into the query. try this $user = addslashes($_POST['username']); $pass = md5($_POST['password']); $result = mysql_query("SELECT bus_id FROM businesses WHERE password='$pass' AND bus_id='$user'") or die("Couldn't query the username-database.");
-
[SOLVED] HELP! Getting "Query was empty" error!
mikesta707 replied to DarkShadowWing's topic in PHP Coding Help
try $query = "SELECT * FROM $tbl"; if it still returns 0 rows, then your table is empty, or you are using the wrong table name -
[SOLVED] HELP! Getting "Query was empty" error!
mikesta707 replied to DarkShadowWing's topic in PHP Coding Help
... Return Values For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error. The returned result resource should be passed to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data. mysql query will return 0 when it fails any time (because of an error, an invalid connection, etc.) . it returns 1 when it preforms inserts, deletes, etc. (as specified on the quote) successfully. However, in this case, he wants a 0 or 1 from his database, not from the query itself. the 0 or 1 from the query are only useful during debugging, as it tells whether or not the query you did was successful or not. However, as far as the data from the actual table the query is accessing goes, the returned value is rather useless unless you use one of the functions for use with the result tables. But yes, I suppose I should have explained myself better. When the query is SUCCESSFUL, mysql_query only returns a mysql_resource -
check if number already exists in database
mikesta707 replied to saltedm8's topic in PHP Coding Help
if(mysql_num_rows(mysql_query("SELECT letable WHERE id =$id LIMIT 1"))) shorter than my example, but basically the same thing -
check if number already exists in database
mikesta707 replied to saltedm8's topic in PHP Coding Help
one, turn is a mysql resource, not the results itself. You have to use mysql_fetch_array or one of the other functions that fetches the data. also, if id is an integer column, don't surround what you are comparing it to with quotes. that denotes it as a string, which may cause problems also, since you are testing if a row is present with the id, you don't need to compare the values, since they are already the same. you should check if the query returned any results try $turn = mysql_query("SELECT letable WHERE id =$id'"); $num = mysql_num_rows($turn); if ($num > 0){ //no Edit: one last thing. what you have here if ($turn = $id){ is valid syntax. but incorrect logic. You are using the assignment operator (=) which assigns the value of the right operand to the left. You want to use the comparison operator(==) which will compare two values if ($turn == $id){ very simple mistake that is commonly made, but just watch out for it -
[SOLVED] HELP! Getting "Query was empty" error!
mikesta707 replied to DarkShadowWing's topic in PHP Coding Help
a bunch of things. $numrows1 = mysql_num_rows($warning); $numrows2 = mysql_num_rows($banned); neither of those variables are mysql resources. If you notice, when you echo $site_con1 and 2, they say mysql resource. You have to use those in the numrows functions, like $numrows1 = mysql_num_rows($site1_con); $numrows2 = mysql_num_rows($site2_con); thats whats causing these errors Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:myxampphtdocsdetectindex.php on line 55 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:myxampphtdocsdetectindex.php on line 56 second, again, mysql_query only returns a mysql resource. You have to use other mysql functions to get the data out of those resources. If you want the information, you have to use mysql_fetch_array or mysql_fetch_assoc. you can also trim your queries down to 1. Try something like $query = "SELECT $warning1, $banned1 FROM $tbl"; $result = mysql_query($query) 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 />"; } try that and see what happens -
I'm not quite sure what you want, but you said you wanted to get the data from that form, and post it into another form. Well thats easy enough, using the get variables you have, you can just set the value of the form to that variable like so <input type="text" value="<?php echo $myVar; ?>" /> thats assuming you have the variable on the same page of the form however. If not, you will have to pass the variable through a get value, or through a hidden form, or as a session, and use it in whatever page.
-
form validation with select option data + input data
mikesta707 replied to wandor's topic in PHP Coding Help
You don't set the value of selects that way. the value of a select form comes from the options tags that are its "children" if you want to it have a default option already selected, you have to add the selected attribute to that specific option. In you case you will probably have to have if statements check what the latest value was, and then either make the option selected or not. -
for some reason my if() statments arent working.
mikesta707 replied to jamesxg1's topic in PHP Coding Help
no they are not working in the way you think. when the assignment operator (=) is in an if statement, it will assign the value of the right hand operand to the left hand operand and return true IE the following if ($i = 5){ // } Will assign $i with the value of 5, and return true because it successfully assigned the value of 5 to $i. However, you want to use the comparison operator (==), which will compare values. Right now your if statements assign the value of, for example, password->new to password->conf, in the following if statement if($password->new = $password->conf) this will always run true because it will succeed in assigning the value to the password->new variable. This won't return any errors because this is valid syntax. Sometmes you want to use the assignment operator in a boolean statement, like, for example, iterating through a mysql result with mysql_fetch_array, like in the following example $sql = mysql_query("Select * From table"); while($row = mysql_fetch_array($sql)){ //do stuff with data } but in your case you want to use the comparison operator -
[SOLVED] shouldnt the echo produce the results
mikesta707 replied to bigbenbuilders's topic in PHP Coding Help
haha ok. Make sure to mark the topic as solved -
yes indeed.
-
Need help with checking value in database..
mikesta707 replied to DarkShadowWing's topic in PHP Coding Help
oh my bad I should have caught this earlier. You have to send the post variables to the function recordExists('firstname', $_POST['firstname'], 'users0001','metaldetect01') The 2nd parameter was the value of the column, and the first was the column itself right? Yeah you have to pass the post variables to the function. try it now -
[SOLVED] shouldnt the echo produce the results
mikesta707 replied to bigbenbuilders's topic in PHP Coding Help
Oh, well why didn't you say that lol change your if too <?php if (stripos($_SERVER['REQUEST_URI'],'id=1') !== false) isn't that what you were trying to do in the beginning? -
Need help with checking value in database..
mikesta707 replied to DarkShadowWing's topic in PHP Coding Help
hes probably gonna wanna use mysql_real_escape_string seeing as he is using mysql functions. but yes this is a good idea -
Need help with checking value in database..
mikesta707 replied to DarkShadowWing's topic in PHP Coding Help
OK, so if i submit test as first name and user as lastname, if both exist in a row, then I can't submit, however, if 1 row has test as first name but poop as last name, I can still submit? In that case change your or clauses (||) to and clauses (&&) -
does that table not have a primary key? just use the primary key when updating. IE if (eregi($var_code, $htmlString)) { $ver_update=("UPDATE `sit_details_tmp` SET `id_verification` = '2' WHERE `id` = '".row['id']."'") or die(mysql_error()); if (!mysql_query($ver_update,$conn)) { die('Error: ' . mysql_error()); } by the way you need to encase associative array keys with single quotes $array[key];//wrong $array['key'];//right
-
yeah that will create an array with a length of 10, with each entry holding an object of the class foo. I don't know why you need so many foo's, but that is correct
-
Need help with checking value in database..
mikesta707 replied to DarkShadowWing's topic in PHP Coding Help
um, that link doesn't work. Do you get any errors on your page? try changing mysql_num_rows to mysql_affected_rows. by the way, the code you currenly have doesn't check the right data id Firstname Lastname email 1 test user blah@blah.blah 2 test user blah@blah.blah 3 test user blah@blah.blah 4 5 6 7 test and 'firstname' (which is what you test for) are not the same so it will allow you to update the table -
Need help with checking value in database..
mikesta707 replied to DarkShadowWing's topic in PHP Coding Help
oh my bad dude. function recordExists($id,$idval,$table,$db) {//check for id=idval in table and return TRUE or FALSE $result = mysql_query("SELECT * FROM ".$table." WHERE ".$id."='".$idval."'") or die(mysql_error()); if(mysql_num_rows($result) > 0) {//if we found more than 0 return true; }//end if row return false; } change it back to that. I don't know why I wrote it that why...