[Solved] Php and PDO – fetching data

The $data array contains multiple associative arrays (one for each record returned). If you want just the values for high for each record in one array and just the values for low in another the result set, you could do: <?php $high = array_column($data, ‘high’); $low = array_column($data, ‘low’); ?> 1 solved Php and PDO … Read more

[Solved] PHP PDO, request users name

please reference the user properties that you want to select the SQL queries using their post variables. something like: $username =$_POST[‘username’]; $password = password=$_POST[‘password’]; $stmt = $db->query(“SELECT * FROM users where username=”$username” and password= ‘$password'”); While this might solve your problem but Please do not use this code in production for fear of sql inject,html … Read more

[Solved] how to acces super variable $_POST in PDO

PDO is not a different language. It is a PHP extension used to connect and operate on a datasource. You can use filter_input(INPUT_POST, ‘username’) without a problem in the code you have there. $stmt = $db->prepare(‘INSERT INTO members (username,password,email,active) VALUES (:username, :password, :email, :active)’); $stmt->execute(array( ‘:username’ => filter_input(INPUT_POST, ‘username’), ‘:password’ => $hashedpassword, ‘:email’ => filter_input(INPUT_POST, … Read more

[Solved] php function is not working? [closed]

In your case there are too many unknowns. First of all you must enable a proper error reporting level and – only for development – let the errors be displayed on screen. Second, there are important error/failure situations which you are not covering with your exception handling code. Also, I would use bindValue() instead of … Read more

[Solved] Class query PDO property of non-object

PDOStatement::fetchAll() already returns an array so you’re just double-nesting the result set for no reason. In your model::find() method, change these lines… while($data = $query->fetchAll(PDO::FETCH_OBJ)){ $d[] = $data; } return($d); to return $query->fetchAll(PDO::FETCH_OBJ); You can also remove the model $d property (not that you were using it anyway). 1 solved Class query PDO property of … Read more

[Solved] PDO login.php needs help finishing [closed]

The prepare statement returns an object, you can execute that object. Thus $query->execute() – the first parameter of execute can be an array. Alternatively, you can use the bindParam function first on that same $query object instead of passing an array though. Anyways, here you are: <?php if(isset($_POST[‘username’], $_POST[‘password’])){ try{ $username=”root”; $password = ”; $conn … Read more

[Solved] How to show all DB result with PDO

The answer is as follows: <?php $sql = “SELECT * FROM database WHERE id BETWEEN 1 AND 5″; $stmt = $conn->query($sql); $stmt->execute(); while($row = $stmt->fetch(PDO::FETCH_OBJ)){ ?> <tr> <td><b><?php echo $row->hours ?></b></td> <td><a href=”#”></a></td> <td id=”dayhour-1″> <input type=”text” class=”form-control” id=”1″ value=”<?php echo $row->username ?>”> </td> </tr> <?php } ?> This code will do it’s work. Its … Read more

[Solved] How to cancel action when detect same line in MySQL [closed]

from my understanding of your question – in your php code you can do something like this <?php $con=mysqli_connect(“localhost”,”my_user”,”my_password”,”my_db”); $sqlSearch = “select everything from <table_name> where <column_name> = <value>;”; $result = mysqli_query($con,$sqlSearch ); if (mysqli_num_rows($result) > 0){ // do nothing } else{ $sqlInsert = “insert into <table_name> (column1,column2…) VALUES(value1,value2…);”; $result = mysqli_query($con,$sqlInsert); } ?> basically, … Read more

[Solved] PHP-MySQL error inserting data

You override your variable $a $a = $_POST[‘id’]; // assign here $a = $db->prepare($sql);// override here Try to give a different name $smt = $db->prepare($sql); $smt->execute(array(‘:a’=>$a,’:b’=>$b,’:c’=>$c,’:d’=>$d,’:e’=>$e)); header(“location: books.php”); solved PHP-MySQL error inserting data

[Solved] change mysql to pdo and store result in variable

Try this: <?php $games_sql = “SELECT id,col1,col2,now FROM tblname ORDER BY now ASC LIMIT 9”; $sth = $conn->query($games_sql); $sth->setFetchMode(PDO::FETCH_ASSOC); $gn=0; while ($game_get = $sth->fetch()) { $id = $game_get[‘id’]; $col1 = $game_get[‘col1’]; $col2 = $game_get[‘col2’]; $now = $game_get[‘now’]; $gametimeanddate = jdate(“l d M y time G:i”,$now); $gamedate = jdate(“l d M y”,$now); $gametime = jdate(“G:i”,$now); //SAVE … Read more

[Solved] what is it that i am doing wrong while converting [closed]

prepare() goes with execute() Prepared statements basically work like this: Prepare: An SQL statement template is created and sent to the database. Certain values are left unspecified, called parameters (labeled “?”). Example: INSERT INTO mtTable VALUES(?, ?, ?) The database parses, compiles, and performs query optimization on the SQL statement template, and stores the result … Read more

[Solved] INSERT row from another table using php PDO

Ok, so the issues you had/have were: $barCode = $GET[‘id’]); should have been $barCode = $GET[‘id’];, and possibly even $_GET[‘id’]; Your SELECT query selects the same field twice (SELECT Brand, Description, >Price<, Size, >Price<) You’re also inserting in the same field twice: INSERT INTO adstable (Brand, Description, >Price<, Size, >Price< You’re vulnerable to injection attacks, … Read more