ArshSingh
Members-
Posts
49 -
Joined
-
Last visited
Everything posted by ArshSingh
-
PHP PDO variable not working in query but static value works
ArshSingh replied to ArshSingh's topic in PHP Coding Help
there was nuthing to do rewrite things , noob me was using while loop . thnx to kicken now all is working good and smoothly . kicken 's answer worked -
PHP PDO variable not working in query but static value works
ArshSingh replied to ArshSingh's topic in PHP Coding Help
please see this screenshot for columns: http://prntscr.com/5l52ip -
PHP PDO variable not working in query but static value works
ArshSingh replied to ArshSingh's topic in PHP Coding Help
yes im working on localhost and also my db is on local as i'm using MAMP PRO for mac ,, and btw , i do have also other functions which are working with databse and doing their work successfully and getting the result from database expect this one. will get you the columns structure. -
PHP PDO variable not working in query but static value works
ArshSingh replied to ArshSingh's topic in PHP Coding Help
it's already integer. -
PHP PDO variable not working in query but static value works
ArshSingh replied to ArshSingh's topic in PHP Coding Help
yes i do get same value for those variables -
PHP PDO variable not working in query but static value works
ArshSingh replied to ArshSingh's topic in PHP Coding Help
i'm not getting the $_GET from an input , it's directly from url in this way : locahost/easy/u/5 also the output of $_GET is : string(1) "5" -
PHP PDO variable not working in query but static value works
ArshSingh replied to ArshSingh's topic in PHP Coding Help
as always result is "NULL" there is a user with id : 5 , but it returns NULL with variable value , and with static number in execute() it resutnr the result with user details (this is what need to come as result). -
PHP PDO variable not working in query but static value works
ArshSingh replied to ArshSingh's topic in PHP Coding Help
this is what i get on var_dump of $user_id string(1) "5" -
PHP PDO variable not working in query but static value works
ArshSingh replied to ArshSingh's topic in PHP Coding Help
this is a var_dump of query : object(stdClass)#7 (5) { ["username"]=> string(5) "admin" ["email"]=> string(15) "admin@gmail.com" ["profile_pic"]=> string(14) "1419529017.jpg" ["id"]=> string(1) "5" ["active"]=> string(3) "Yes" -
PHP PDO variable not working in query but static value works
ArshSingh replied to ArshSingh's topic in PHP Coding Help
Well sorry if i'm not able to explain the situation a bit more in detail , as i too don't have any other clue of what is happening. Anyway thanks for the help and this is a result of query after putting static number value in query : object(stdClass)#7 (5) { ["username"]=> string(5) "admin" ["email"]=> string(15) "admin@gmail.com" ["profile_pic"]=> string(14) "1419529017.jpg" ["id"]=> string(1) "5" ["active"]=> string(3) "Yes" -
PHP PDO variable not working in query but static value works
ArshSingh replied to ArshSingh's topic in PHP Coding Help
if return $user_det is not inside while loop and no result comes from query it gives me undefined $user_det variable error but with an static number value '5' it works smoothly , i'm returning this array as i'm working on different structure and i don't want to use : $row['username] something like this. i'm converting the array to object as i need the array to work in the following way : $user->username not like this : $user[0]['username'] , it's just part of my program structure , including and excluding everything we come back to the odd problem : why it is reacting in that way , and not returning and result if used variable at the place of static number value. -
PHP PDO variable not working in query but static value works
ArshSingh replied to ArshSingh's topic in PHP Coding Help
Well result of var_dump is : string 0 '5' -
PHP PDO variable not working in query but static value works
ArshSingh replied to ArshSingh's topic in PHP Coding Help
when using $user it returns "NULL" but when i put static value '5' it returns the array with all details. and what do you mean with : Did you notice the key difference in your two statements? -
PHP PDO variable not working in query but static value works
ArshSingh replied to ArshSingh's topic in PHP Coding Help
When i put a static value to : $stmt->execute(array(':user_id'=>$user)); -> $stmt->execute(array(':user_id'=>'5')); it works and returns the result , and this is what i'm submiting to the function profile_view() , and i have also done _ var_dump of $user before query and it shows me the correct vaulue of what $_GET is getting from url. -
PHP PDO variable not working in query but static value works
ArshSingh replied to ArshSingh's topic in PHP Coding Help
inside function i'm declaring that $user = $user_id; and this does not seems to be connected the problem at all -
so my situation is something like this , i'm trying to fetch user details based on `id` that isset is getting, but some how the `variable that contains the $_GET value doesn't work` in query but when i put an static value to pdo query then it works and show the result. i have checked by doing `var_dump` of variable `$user` before query and it shows the correct value but not working in query. Below is the code i'm working with: public function profile_view($user_id = null) { $user = $user_id; $stmt = $this->_db->prepare('SELECT memberID,username,email,profile_pic,active FROM members WHERE memberID = :user_id AND active="YES"'); $stmt->execute(array(':user_id'=>$user)); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $user_det = (object) array('username'=> $row['username'],'email'=>$row['email'],'profile_pic'=>$row['profile_pic'],'id'=> $row['memberID'],'active'=>$row['active']); return $user_det; } } this is how function is being called (profile_view function is child of User class so $user is class User) : $view_profile = $user->profile_view($_GET['u']); the above code returns null but when i put static value : `5` at the place of `$user` in `$stmt->execute` it returns the whole user's details which is what i need , but its not working with variable which is confusing me alot , thanks in advanced for help.
-
im using the following to get get the followers of currently viewing user, but when i run this code , it gives me over 20000 times same username which is the only one who following that user ; really need help my head is not working ,,, i have tried to use inner join but not working (or i don't know how to make it work). code : <?php $stmt = $mysqli->prepare("SELECT follow_id from follow_user WHERE id= ?"); $stmt->bind_param('s', $viewuser); // Bind "$user_id" to parameter. $stmt->execute(); // Execute the prepared query. $stmt->store_result(); $stmt->bind_result($follow_id); // get variables from result. while($stmt->fetch()) { $stmt = $mysqli->prepare("SELECT id,username,profilepic from members WHERE id= ? LIMIT 1"); $stmt->bind_param('s', $follow_id); // Bind "$user_id" to parameter. $stmt->execute(); // Execute the prepared query. $stmt->store_result(); if($stmt->num_rows == 1) { $stmt->bind_result($id,$followusername,$followpic); // get variables from result. } ?> <?php echo $followusername; ?> <?php } ?>
-
bind the rows from database with mysqli->prepare
ArshSingh replied to ArshSingh's topic in PHP Coding Help
its always from this thread , as you can see there was LIMIT 0,4 which i was using to get 4 rows from database , is there anyway to get 4 rows with prepare statement'? -
bind the rows from database with mysqli->prepare
ArshSingh replied to ArshSingh's topic in PHP Coding Help
$col was for example only , i have removed if($stmt->num_rows == 1) { , adn now its giving me only 1 result , but i want 4 first rows from databse -
so what im doing is ; im trying to get the rows from database with my following php code , and display them like ; <?php echo $col;?> , but its not working and giving me a blank result , a help would be greate thanks : <?php $stmt = $mysqli->prepare("SELECT * FROM `movies` ORDER BY `date` DESC LIMIT 0, 4"); $stmt->execute(); // Execute the prepared query. $stmt->store_result(); if($stmt->num_rows == 1) { $stmt->bind_result($id,$title,$poster,$date); // get variables from result. $stmt -> fetch(); } ?>
-
resolved , there was missing ,,, $stmt->store_result();
-
hi there , so my problem is that im trying to select rows from database with mysqli->prepare for search autosuggestion, its not giving me a error but its not displaying ; poster , title , id that i have selected from database , i have other queries also and they work , but this ome is not working , here is the full code : a help would be great. <?php include("../secure/functions.php"); if($_POST) { $q=$_POST['searchword']; $stmt = $mysqli->prepare("SELECT `id`,`title`,`poster`,`story`,`director` FROM `movies` WHERE `title` like CONCAT('%', ?, '%')"); $stmt->bind_param('s', $q); $stmt->execute(); // Execute the prepared query. if($stmt->num_rows == 1) { $stmt->bind_result($id,$title,$poster,$story,$director); // get variables from result. $stmt->fetch(); } } ?> <a href="movie?title=<?php echo $title;?>"> <div class="display_box" align="left"> <img src="<?php echo $poster; ?>" /><?php echo $title; ?><br/> <span style="font-size:9px; color:#999999"><?php echo $director; ?></span></div></a>
-
Yup thats right
-
Okay ,,, i think the error is before mysqli_query ,,, have to check it carefullg
-
can u please check if the mysqli_query is okay?