PHP - Boolean Column Creating Problem
I am using this sql to filter records :
$query = "select * from mobileprices where range='5000'"() but i am getting this error message : mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/dracra/public_html/a.com/range.php range field contains product prices range and filled with 5000, 10000, 15000, 20000 etc. I tried the following code to update the range values from numeric to text in phpmyadmin sql area : Code: [Select] UPDATE mobileprices SET range='five' WHERE range='5000' but i am getting this error message : #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'range='five' WHERE range='5000'' at line 2 I am confused as there are thousands of records and manually updating it one by one will take so much time. Anyone could help me out as how i can change numeric with text in range. or there is any way by that sql could accept this : $query = "select * from mobileprices where range='5000'"() I need a solution, so please help me !! Similar TutorialsI'm trying to use a boolean 'true' or 'false' to tell the page that when false, he/she is logged out and send them to loggin page..other wise display the name which is taken from the session....i made the session stuff in a class and i have it as follows: Code: [Select] <?php include("includes/functions.php"); class Session{ public $logged_in = false; // the one i'm on about public $key; // $_session[$key] = $value public function set($key, $value){//setting session $_SESSION[$key] = $value; if(isset($_SESSION[$key])){ $this->logged_in = true; } } public function get($key){ //getting session if(isset($_SESSION[$key])){ return $_SESSION[$key]; } else{ return false; } } public function confirm_logged_in(){ //check if logged in if(!$this->logged_in) redirect_to("login.php"); // a tailored method } public function logout(){ session_start(); session_unset(); session_destroy(); $this->logged_in = false; } } $session = new Session(); ?> unfortunately when i set the session on one page (say after login) assuming that the $logged_in variable is now turned to TRUE, but when I go to another page (e.g. Index.php) and Get the allready set session and perform the test confirm_logged_in() it does the OPPOSITE to what I would expect as for example: redirecting me to login.php even when its "supposed to be" $logged_in=true as set in the set function above. any help would be appreciated...suggestions to change syntax or any as such...thanks This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=344739.0 Hi, I have downloads that are available for users. They can click the links to download the file. Once they do this, I have a query that updates the number of downloads that file has received. I need to create a query that adds up all the rows Total Downloads. So for example: i have 3 rows: Name - Total Downloads First - 2 Second - 23 Third - 7 Using the query for these rows would give me an amount of 32. Any idea how to do this? I don't want to have to create a new column to find the total number of downloads. Any other ways? I'm building a query that searches by database and returns matching (or almost matching) terms. That part isn't the problem- I have it up and working. The problem is that I'm trying to narrow down the search results, and it's not working. Here's the query that works: Code: [Select] $result = mysql_query("SELECT * FROM auctions WHERE name LIKE '%".$searchterm."%' OR Address LIKE '%".$searchterm."%' OR state like '%".$searchterm."%'"); Here's the query that DOESN'T works: Code: [Select] $result = mysql_query("SELECT * FROM auctions WHERE type='Cars' AND name LIKE '%".$searchterm."%' OR Address LIKE '%".$searchterm."%' OR state like '%".$searchterm."%'"); What I'm trying to do is say "give me all the results from type:Cars. Instead, it ignores the WHERE type='Cars' statement, and returns results for all types. It frustrates me because I use the same exact query in a thousand other places, and it works everywhere else. For example: Code: [Select] $sql = "SELECT * FROM auctions WHERE type='Boats' AND state='$v4' ORDER BY $v1 $v2"; works just fine. I'm not exactly an expert on any of this, but I can see no logical reason why this works, but the Search code doesn't. They appear in all ways identical, at least as far as query structure goes. Can anyone spot where I screwed up? Thanks! Kyle Hi guys, PHP advanced amateur and PHPFreaks newbie here. I have a problem with some code I've written. What the code is supposed to do, is take in 15 records in a single MySQL table column, and then print them out in a format like this: 1 2 3 4 5 6 7 8 9 so on so on. Here is the page in question: http://robbieduggan.com/strawberry-interactive/portfolio-web-design.php Now the problem is, you can see 14 images there, but it seems to be negating the first one. Its always whatever row 0 is, because if I change the SORT BY attrabute in the code below, it's a different one that is missing. Here is my code to get the data: mysql_select_db($database_strawberry, $strawberry); $query_rsProjects = "SELECT page_unique_identity, clean_title, thumbnail FROM tblprojects ORDER BY `timestamp` DESC"; $rsProjects = mysql_query($query_rsProjects, $strawberry) or die(mysql_error()); $row_rsProjects = mysql_fetch_assoc($rsProjects); $totalRows_rsProjects = mysql_num_rows($rsProjects); And here is the code to create the table: echo "<table width='100%' border='0' cellspacing='5' cellpadding='5'>"; for($i = 0; $i < $totalRows_rsProjects; $i++) { $row = mysql_fetch_array($rsProjects); if($i % $columns == 0) { echo "<tr>"; } echo "<td>"; if($row['page_unique_identity'] != NULL){ echo "<a href='website-details.php?project=".$row['page_unique_identity']."'><img src='portfolio/".$row['thumbnail']."' alt=".$row['clean_title']." width='267' height='162' /></a>"; } echo "</td>"; if(($i % $columns) == ($columns - 1) || ($i + 1) == $totalRows_rsProjects) { echo "</tr>"; } } Thanks in advance for any help Hi guys, i cannot figure out what is wrong with this and I hope you could help figure it out? This is the code I am using - Code: [Select] $create_cart_table = "CREATE TABLE `". $string ."` (cart_id int NOT NULL AUTO_INCREMENT, PRIMARY KEY(cart_id), item_name VARCHAR(1000) NOT NULL, item_id VARCHAR(30) NOT NULL, price VARCHAR(30) NOT NULL, date_time TIMESTAMP(100) NOT NULL CURRENT_TIMESTAMP, quantity VARCHAR(100) NOT NULL)"; $set_cart_table = mysql_query($create_cart_table); $string is defined above and there are no database connection warnings etc coming up and I am lost as to how the heck this isn't working? It was working for about an hour when I first made the script but now it is not. Please help? I am working on a register script for my site that will give errors when needed. I am trying to make it so that if the submitted username doesn't equal [A-Za-z0-9-\s]{3,25} then it'll make $error1 = 1. if(preg_match('/[A-Za-z0-9-\s]{3,25}/i', $_POST['username'], $matches) && strlen($matches[0]) === strlen($_POST['username'])){ $error1 = 1; } I've tried putting a ! where the three equal signs are, replaced them, and everything. this string: Code: [Select] $str2="<html> <body> <h1>lol<h1/> <p>hahaha</p> </body> </html>" note: between the tags it's "\n". that a is creating new html page, but the code of the new page is looking like that: Code: [Select] <html><body><h5>lol<h5/><p>hahaha</p></body><html/>as a code and not as html should be display. the php code that creating the html page look like that: while($i<$p) { $pattern='/\n/'; if(preg_match($pattern,substr($str2,$i,1))) { echo "yes \$str3=".$str3."<br />"; $i++; $myFile = "files/testFile.html"; $fh = fopen($myFile, 'a') or die("can't open file"); fwrite($fh,$str3); fclose($fh); $str3=""; } else { $str3.=$str2[$i]; echo $str3."<br />\$i=".$i; $i++; } } the code is fine and he don't show any error or warring and working,but he won't create for me new html document as he should be why??? Hello I've registered here last March and I'm just lurking around reading threads about php. Yesterday I've started to self studied php and today I've test some basic codes and I'm having difficulties on creating a table rows and columns. Here's my code. Code: [Select] <?php echo "<table width=\"100\" border=\"1\">"; $text = 'php'; $mac_var = 1; $mac_plus = 4; while ($mac_var < $mac_plus) { echo "<tr>"; { while ($mac_var < $mac_plus) { echo "<td>". $text . "</td>"; $mac_var++; } } echo "</tr>"; $mac_var++; } echo "</table>"; ?> what I want is, it should have 3 columns and 3 rows. But I'm getting only 3 columns and 1 row only. I wonder what is the problem? Sorry for my ignorance as I'm on the 1st basic phase of using php codes. TIA! How can I fix this error? Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given Code: [Select] function fetch_most_recent_fans($ctag) { $sql = "SELECT `company_fans`.`company_id`, `company_fans`.`user_id`, `company_fans`.`fan_date`, `companies`.`companytag`, `users`.`firstname`, `users`.`lastname`, `users`.`username` FROM `company_fans` LEFT JOIN `companies` ON `companies`.`companyid` = `company_fans`.`company_id` LEFT JOIN `users` ON `users`.`id` = `company_fans`.`user_id` WHERE `companies`.`companytag` = {ctag} ORDER BY `company_fans`.`fan_date` DESC LIMIT 10"; $query = mysql_query($sql); $return = array(); while (($row = mysql_fetch_assoc($query)) !== false) { $return[] = $row; } return $return; } Hello, I am trying to implement error proofing to a log in script. But, I cannot get it to work? I have no idea what is going on, or why it doesn't work like I expect it to. I have tried everything, please advise. This is the method I am calling: Code: [Select] public function i_exist($this_username) { //$host_array = null; //$host_array = $this->collection->findOne(array("Username" => $this_username)); //if ($host_array['Username'] = $this_username) //{ return true; //} //return false; } This is where I am calling it: Code: [Select] if (!empty($_POST['Username'])) { $host = new Host(); $event = new Event(); if ($host->i_exist($_POST['Username'])) { header("Location: http://www.drink-social.com/error.php?login=duplicate"); } It is supposed to check the database and see if that username is already in use. But it never directs to the error page? I have even tried commenting everything out and returning true, and returning 1. Nothing? Any advice? Hi, I have an image uploader here and I am trying to have a user enter their password and check a box in order to submit their image. I am having trouble validating the password. I get this error message: "Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/content/68/6372768/html/submit.php on line 58" From this section of the code: $query = "SELECT * FROM user_info WHERE password = SHA($user_password)"; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { $valid_password = true; } Anyone see what I am doing wrong? The password stored in my DB is encrypted with SHA. Code: [Select] <?php // Start the session require_once('startsession.php'); // Insert the page header $page_title = 'Submit an Image'; require_once('header.php'); require_once('appvars.php'); require_once('connectvars.php'); // Show the navigation menu require_once('navmenu.php'); // Make sure the user is logged in before going any further. if (!isset($_SESSION['user_id'])) { echo '<center><table border="0" cellspacing = "20"><tr><td>'; echo '<p class="login">Please <a href="login.php">log in</a> to access this page.</p>'; echo '</td></tr></table></center>'; // Insert the page footer echo '<div class="footer">'; require_once('footer.php'); echo '</div>'; exit(); } ?> <div class="linkrow"> <!-- end .linkrow --></div> <div class="contentBlue960"> <img src = "/IMAGES/WEBSITE/capBlue960.jpg"> <?php if (isset($_POST['submit'])) { // Connect to the DB $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Set password to false $valid_password = false; // Grab the id data from the POST $image_name = $_FILES['image_name']['name']; $image_name_type = $_FILES['image_name']['type']; $image_name_size = $_FILES['image_name']['size']; $user_password = (mysqli_real_escape_string($dbc, trim($_POST['user_password']))); $agree = mysqli_real_escape_string($dbc, trim($_POST['agree'])); // Grab the id data from the DB if (!isset($_GET['user_id'])) { $query = "SELECT user_name, password FROM user_info WHERE user_id = '" . $_SESSION['user_id'] . "'"; } else { $query = "SELECT user_name, password FROM user_info WHERE user_id = '" . $_GET['user_id'] . "'"; } $data = mysqli_query($dbc, $query); $user_name = $row['user_name']; $password = $row['password']; $query = "SELECT * FROM user_info WHERE password = SHA($user_password)"; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { $valid_password = true; } // If image and password are entered if (!empty($user_password) && !empty($image_name)) { // If the entered password matches the user's password if ($valid_password == true) { // If the copyright is agreed to if (($agree) == ('checked')) { // If the pic is valid if ((($image_name_type == 'image/gif') || ($image_name_type == 'image/jpeg') || ($image_name_type == 'image/pjpeg') || ($image_name_type == 'image/png')) && ($image_name_size > 0) && ($image_name_size <= GW_MAXFILESIZE)) { if ($_FILES['image_name']['error'] == 0) { // Move the file to the target upload folder $target = GW_UPLOADPATH . $image_name; if (move_uploaded_file($_FILES['image_name']['tmp_name'], $target)) { // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Error connecting to MySQL server.'); // Write the data to the database $query = "INSERT INTO user_images VALUES (0, '$user_name', NOW(), '$image_name')"; mysqli_query($dbc, $query); // Confirm success with the user echo '<p>Thanks for submitting an image! Under review as soon as possible.</p>'; echo '<p><strong>User Name:</strong> ' . $user_name . '<br />'; echo '<img src="' . GW_UPLOADPATH . $image_name . '" alt="Submitted Image" /></p>'; echo '<p><a href="submit.php"><< Back to submit page.</a></p>'; // Clear the id data to clear the form $user_name = ""; $image_name = ""; mysqli_close($dbc); } else { echo '<p class="error">Sorry, there was a problem uploading your screen shot image.</p>'; } } } else { echo '<p class="error">The screen shot must be a GIF, JPEG, or PNG image file no greater than ' . (GW_MAXFILESIZE / 1024) . ' KB in size.</p>'; } // Try to delete the temporary screen shot image file @unlink($_FILES['image_name']['tmp_name']); } else { echo '<p class="error">Must agree with and check copyright box.</p>'; } } else { echo '<p class="error">Password Incorrect</p>'; } } else { // echo 'Pass' . $password . ' 1'; // echo 'User pass' . $user_password . ' 2'; // echo 'Checkbox' . $agree . ' 3'; // echo 'Username' . $user_name . ' 3'; echo '<p class="error">Please enter all of the information to add your image.</p>'; } } // mysqli_close($dbc); ?> <table border="1" cellspacing = "20"> <tr><td width = 960px><h2>Submit an Image</h2></td></tr> </table> <table border="1" cellspacing = "20"> <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <tr><td width = "300"> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo GW_MAXFILESIZE; ?>" /> <label for="image_name">Image:</label></td> <td><input type="file" id="image_name" name="image_name" /> </td></tr> <tr><td width = "300"> <label for="user_password">Enter Password:</label></td> <td><input type="text" id="user_password" name="user_password" /><br /> </td></tr> <tr><td width = "300"> <label for="terms">This image is my own work and I own all copyrights to it.</label></td> <td><input type="checkbox" id="agree" name="agree" value = "checked"/><br /> </td></tr> <tr><td width = "300"> <input type="submit" value="Submit Image" name="submit" /> </td></tr> </form> </td> </tr> </table> <img src = "/IMAGES/WEBSITE/bottomBlue960.jpg"> <!-- end .contentWhite960 --></div> <div class="footer"> <?php // Insert the page footer require_once('footer.php'); ?> <!-- end .footer --></div> Thanks if you can help, Craig why does the top code work and the bottom does not? what am i missing? the only real diffrence is the query. im getting "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in " for this code $numrows = mysql_num_rows($result). the query works fine in phpmyadmin. thanks $query = "SELECT * FROM dsgi_servlist " ; $result = mysql_query($query) ; $numrows = mysql_num_rows($result) ; echo $numrows ; $sql = "SELECT COUNT(*) FROM dsgi_servlist where location = 'hdd'"; $result = mysql_query($sql) ; $numrows = mysql_num_rows($result) ; echo $numrows ; I created this function to update my tour system. The query is working and is updating one row in the table, but I get a resource boolean error in the return section of the function. Any idea why? Code: [Select] function update_tour($uid, $step) { $step = (int)$step; $uid = (int)$uid; $sql = "UPDATE `users` SET `tour_step` = ${step} WHERE `id` = '${uid}'"; $q = mysql_query($sql) or die(mysql_error()); return (mysql_num_rows($q) === 1) ? mysql_result($q, 0): false; } I have an online store that was created with PHP and it uses MySQL on the backend. There’s a boolean field in the database that either turns the store on (enabled) or it turns the store off (disabled) when it’s toggled. My question is can I write code that would automatically toggle that boolean value at specific times of the day? Hello there, I'm having a issue where when I run the following statement: $Session = $Module['MySQL']->RowCount("SELECT * FROM xhost_accounts WHERE (account_username = '{$Module['MySQL']->Escape($AccountUsername)}' OR account_email = '{$Module['MySQL']->Escape($AccountUsername)}') AND account_password = MD5('{$AccountPassword}')") == 1 ? true:false; I am proceeded by the following error: Code: [Select] Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\Backend\MySQL-Module.php on line 49 Yet when I do the following statement: echo $Module['MySQL']->RowCount("SELECT * FROM xhost_accounts WHERE (account_username = '{$Module['MySQL']->Escape($AccountUsername)}' OR account_email = '{$Module['MySQL']->Escape($AccountUsername)}') AND account_password = MD5('{$AccountPassword}')") It gives me the output of 2 (That's the correct table row count)? Does anybody have any insight into why this could be happening thanks. why is this code not working? in php i have the following...
$keywords = "+hello +world"; $query= "SELECT * FROM forums WHERE MATCH (topics) AGAINST ('$keywords' IN BOOLEAN MODE)"; $results = mysqli_query($database, $query); $row = mysqli_fetch_assoc($results); $topics = $row['topics']; echo $topics; Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given... I have a table which contains a TINY INT column. If there are images associated with the post, the TINY is 1. If not, 0.
I want to order results by images first, and earliest DATETIME first.
Basically, like using a boolean but not. Simply ordering by the TINY INT column ASC or DESC isn't working. Not sure how to solve this.
Help appreciated. Thanks!
i am having problem with this error, could you please help me Code: [Select] function cart () { foreach($_SESSION as $name => $value) { if ($value>0) { if (substr($name, 0, 5) == "cart_") { $productid = substr($name, 5, (strlen($name)-5)); $query = mysql_query("SELECT ProductID, Name, Price FROM product WHERE ProductID = '".mysql_real_escape_string((int)$productid."'")); while ($query_row = mysql_fetch_assoc($query)) { $sub = $query["Price"]*$Value; echo $query["Name"]. ' x ' .$value. ' @ '.$query["Price"]. ' = '.$sub.'<br />'; } } } else { echo "<p>Your Shopping Basket is empty</p>"; } } } |