prepared statement fatal error non-object [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I got this query to insert a row in my table, but it gives this error
Fatal error: Call to a member function bindParam() on a non-object in */misc/php/process.php on line 35
Code:
$query = mysqli_query($conn, "INSERT INTO pm (van,naar,status,admin,onderwerp,tijd,bericht) VALUES(:van,:naar,:status,:admin,:onderwerp,:tijd,:bericht)");
$stmt = $conn->prepare($query);
$stmt->bindParam(':van', $van); //<-- line 35
$stmt->bindParam(':naar', $naar);
$stmt->bindParam(':status', $status);
$stmt->bindParam(':admin', $admin);
$stmt->bindParam(':onderwerp', $onderwerp);
$stmt->bindParam(':tijd', $tijd);
$stmt->bindParam(':bericht', $bericht);
$stmt->execute();
$stmt->close();

Your code should be:
$query = "INSERT INTO pm (van,naar,status,admin,onderwerp,tijd,bericht) VALUES(:van,:naar,:status,:admin,:onderwerp,:tijd,:bericht)";
$stmt = $conn->prepare($query);
This line:
$query = mysqli_query($conn, "INSERT INTO pm (van,naar,status,admin,onderwerp,tijd,bericht) VALUES(:van,:naar,:status,:admin,:onderwerp,:tijd,:bericht)");
is actually querying the database with that statement. It would make more sense as:
$result = mysqli_query($conn, "INSERT INTO pm (van,naar,status,admin,onderwerp,tijd,bericht) VALUES(:van,:naar,:status,:admin,:onderwerp,:tijd,:bericht)");
but you aren't looking for a result, but just a prepared statement, so follow my example above.

Related

How to fix oci_execute(): ORA-00957: duplicate column name...? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I'm trying to insert form value data to Oracle database But I get this error ... please help ... ?
if(isset($_POST['submit'])){
$id = $_POST['id'];
$username = $_POST['username'];
$password = $_POST['password'];
$nameen = $_POST['nameen'];
$namear = $_POST['namear'];
echo $sql = "INSERT INTO TESTTABLE (ID,USERNAME,PASSWORD,NAMEEN,NAMEEN) VALUES (:id,:username,:password,:nameen,:namear)";
$compiled = oci_parse($conn, $sql);
oci_bind_by_name($compiled, ':id', $id);
oci_bind_by_name($compiled, ':username', $username);
oci_bind_by_name($compiled, ':password', $password);
oci_bind_by_name($compiled, ':nameen', $nameen);
oci_bind_by_name($compiled, ':namear', $namear);
oci_execute($compiled);
if (! oci_execute($compiled)) {
var_dump(oci_error());
} }
You have twice the same field, called « NAMEEN », in your INSERT statement :
INSERT INTO TESTTABLE
(ID,USERNAME,PASSWORD,NAMEEN,NAMEEN) VALUES ...
You want :
INSERT INTO TESTTABLE
(ID,USERNAME,PASSWORD,NAMEEN,NAMEAR) VALUES ...

'SQLSTATE[HY093]' with my search query [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I am having some trouble getting my search query to work. I get this error:
PDOException: SQLSTATE[HY093]: Invalid parameter
$test = $_POST["test"];
$query='SELECT * FROM news WHERE name LIKE :search OR category LIKE :search';
$stmt = $dbh->prepare($query);
$stmt->bindValue(':search', '%' . $test . '%', PDO::PARAM_INT);
$stmt->execute();
foreach ($stmt as $row) {
echo $row ['id'];
echo $row ['name'];
}
it only works if i remove OR category LIKE :search
I believe it's because you are trying to re-use the same bind variable again. Try using a different one like
$query='SELECT * FROM news WHERE name LIKE :search OR category LIKE :search1';
$stmt = $dbh->prepare($query);
$stmt->bindValue(':search', '%' . $test . '%', PDO::PARAM_INT);
$stmt->bindValue(':search1', '%' . $test . '%', PDO::PARAM_INT);

php decode special entities in mysql [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am very new to PDO and I am trying to decode all the rows in my table "test" which contains special entities for instance "('L& eacute;on: The Professional')" instead of "Léon:The Professional".
So, here is what I tried:
<?php
require_once('connection.php');
$stmt = $conn->prepare("SELECT * from test");
$stmt->execute();
while ($results = $stmt->fetch()){
$b = html_entity_decode($stmt);
echo $b;
}
but I have no output printed..
Could someone kindly help me fix it?
prepare() returns a statement object ($stmt in your case)
fetch() returns associative array where the index would be the column name
$sql = "SELECT column1, column2, column3 from test";
$stmt = $conn->prepare($sql);
$stmt->execute();
$result = array()
while ($row = $stmt->fetch()){
$resutlt[] = array('column1' => html_entity_decode($row['column1']),
'column2' => html_entity_decode($row['column2']),
'column3' => html_entity_decode($row['column3'])
);
}
var_dump($result);
return $result;
EDIT: to replace the values
//prepare select
$sql = "SELECT id, column1, column2, column3 from test";
$stmt = $conn->prepare($sql);
$stmt->execute();
//prepare update
$update_sql = "UPDATE test SET column1=?,column2=?,column3=? WHERE id = ?;";
$update_stmt = $conn->prepare($update_sql);
while ($row = $stmt->fetch()){
//update
$update_stmt->execute(array(html_entity_decode($row['column1']),
html_entity_decode($row['column2']),
html_entity_decode($row['column3']),
$row['id']
);
}
You did not define $query, thus it has no execute() function. If you wish to execute your prepared statement, you should call $stmt->execute().

Cannot update MySQL Database, error in sql part [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Im trying to update a table in MySQL database, but the data cannot be updated.
the value for $id is 2 and $status is empty.
echo $id;
echo $status;
$sql="UPDATE maklumat_tempahan
SET
status = '$status',
WHERE id_tempahan = '$id' ";
mysql_select_db('psmbaru');
$retval = mysql_query( $sql, $conn );
?>
<?php if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Permohonan Anda Dalam Proses\n";
mysql_close($conn);}?>
This is the error that came out
Could not update data: 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 'WHERE id_tempahan = '2'' at line 7
remove , after $status
$sql="UPDATE maklumat_tempahan
SET
status = '$status'
WHERE id_tempahan = '$id' ";
Yes, remove comma after => status = '$status',
and are you sure not to add mysql_real_escape_string() for your input brother?

values from 2 arrays to mysql table php [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
Well please help to correct syntax fo the following code. I have to select 2 values from one table and insert them in another table. one value is taking from PHP variable.this all needs to be done using Opencart model file
$this->db->query("UPDATE " . DB_PREFIX . "rate_cost SET rate_cost = " . $this->db->escape($data['rate_cost']) );
$sql = "SELECT DISTINCT competition_rate, customer_id FROM " . DB_PREFIX . "customer WHERE competition_rate NOT LIKE 0";
$query = $this->db->query($sql);
$rates = array();
$customer_ids = array();
foreach($query->row['competition_rate'] as $result){
$rates[] = $result * $data['name'];
}
foreach($query->row['customer_id'] as $result2){
$customer_ids[] = $result2;
}
$sums = $rates;
$ids = $customer_ids;;
$sql = ("INSERT INTO 'customer_transaction'(customer_id,amount) VALUES'".$ids.",".$sums"'");
}
I am getting the folowing error:
Parse error: syntax error, unexpected '"'"' (T_CONSTANT_ENCAPSED_STRING) in C:\xampp\htdocs\sport\admin\model\competition\newsletter.php on line 18
You have some syntax errors in your $sql query, the correct syntax for INSERT query is
INSERT INTO table (columns) VALUES ('values');
So youre missing paranthesis for your values and you dind't surround correctly with quotes. So change as follow
VALUES ('".$ids."','".$sums"')");
So the complete query will look like that
("INSERT INTO 'customer_transaction'(customer_id,amount) VALUES ('".$ids."','".$sums"')");

Categories