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 ...
Related
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 trying to unlink() an image from a folder while it's corresponding deleting row from database. Deleting the row from the db works great but I can't get the unlink to work.
I googled for 2 hours and tried a lot of thing but it's still not working, I think I have some small glitch but I can't figure it out.
Can you suggest what to try.
<?php
$pdo = connect();
if (isset($_GET['delete'])) {
$delete_id = $_GET['delete'];
$img = "SELECT slika FROM filmovi WHERE id = $delete_id";
$q = $pdo->prepare($img);
$q->execute();
$row = $q->fetchAll();
$sql = "DELETE FROM filmovi WHERE id = :filmID";
$query = $pdo->prepare($sql);
$query->bindParam(':filmID', $delete_id, PDO::PARAM_INT);
$query->execute();
$image = $row['slika'];
unlink("assets/img/movies/.'$image");
header("Location: index.php?movies");
die();
}
unlink("assets/img/movies/.'$image");
So say $image contains "image.jpg". The path you've constructed is
assets/img/movies/.'image.jpg
What you most likely want is
unlink("assets/img/movies/". $image);
One comment helped me but he deleted it. I removed FetchAll and left only Fetch.
It works now without any errors.
This is the code:
<?php
$pdo = connect();
if (isset($_GET['delete'])) {
$delete_id = $_GET['delete'];
$img = "SELECT * FROM filmovi WHERE id = $delete_id";
$q = $pdo->prepare($img);
$q->execute();
$row = $q->fetch();
$sql = "DELETE FROM filmovi WHERE id = :filmID";
$query = $pdo->prepare($sql);
$query->bindParam(':filmID', $delete_id, PDO::PARAM_INT);
$query->execute();
$image = $row['slika'];
unlink("assets/img/movies/$image");
header("Location: index.php?movies");
die();
}
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().
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
$username = stripslashes($username);
// check if usernames exists
$sql = "SELECT Login_Name FROM memberdirectory WHERE Login_Name = $username";
if ($result = mysqli_query($pdo,$sql)) {
$row = mysqli_num_rows($result);
// if yes, fetch the encrypted password
You are missing quotes around the string value:
$sql = "SELECT Login_Name FROM memberdirectory WHERE Login_Name = '$username'";
If you are using mysqli, why limit yourself to manually sanitizing your inputs? MysqlI has prepared statements to handle and format your query correctly.
$Conn = new mysqli("host","user","pass","database");
$Query = $Conn->prepare("SELECT Login_Name FROM memberdirectory WHERE Login_name=?");
$Query->bind_param('s',$username);
$Query->execute();
$Query->fetch();
$Row_Number = $Query->num_rows;
$Query->close(); // close the connection. Always a benefit and can save you complications later down the line
Then validate:
if ($Row_Number > 0){
} // Example only.
$username = stripslashes($username);
$sql = "SELECT Login_Name FROM memberdirectory WHERE Login_Name =".$username;
if ($result = mysqli_query($pdo,$sql)) {
$row = mysqli_num_rows($result);
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.
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
I am novice to php-mysql ...please help me to rectify the syntax error
the error is:
Parse error: syntax error, unexpected T_VARIABLE in /home/u831097172/public_html/php/update.php on line 13
line 13:
UPDATE $tbl_name SET password= '$password' WHERE email='$email';
maybe you mean something like
$query = "UPDATE $tbl_name SET password = '$password' WHERE email='$email'";
remeber to add slashes to your $password and $email variable to avoid sql-injection
I think you should learn directly with statements:
$mysqliConnection = new mysqli($SERVER, $USER, $PW, $TABLE);
$stmt = mysqliConnection->prepare("UPDATE ? SET password = ? WHERE email = ?");
$stmt->bind_param("sss", $tbl_name, $password, $email);
$stmt->execute();
Here's the doc :) http://es1.php.net/manual/en/mysqli.prepare.php
Are the variables filled?
Maybe its better you make
$query = "UPDATE " . $tbl_name . " SET password='" . $password . "'
WHERE email='" . $email . "'";
And then you can check simple if you print the String out. There you can see if your variables are filled:
print_r($query);
You have your variable $tbl_name not in quotes $tbl_name has to be '$tbl_name'