1
PHP ir SQL - Klausimai ir pagalba / Ats: Klaida su Svečių knyga
« Įrašytas: 2014-03-13 19:52:16 pm »
Man kažkaip atrodo, kad tu pasirenki db lentelę, o ne patį db su "mysql_select_db"
Čia galite matyti visus šio nario pranešimus. Matote tik tuos pranešimus, kurie buvo paskelbti jums prieinamose lentose.
"group" yra mysql rezervuotas žodis. Kai nurodai lentelės arba column'o pavadinimą - nurodyk jį tarp ` (ne kabutė ', o būtent `).Ačiū už pagalbą!Kodas: [Pasirinkti]UPDATE `users` SET `group`=:group WHERE `email`=:email
<?php
$email = "kazkas@kazkas.lt";
$group = 2;
$update = $dbh->prepare("UPDATE users SET group=:group WHERE email=:email");
$update->bindParam(':group', $group, PDO::PARAM_INT);
$update->bindParam(':email', $email, PDO::PARAM_STR);
$update->execute();
?>
gaunu klaidą: nuo kada reikia dėti tarpus prieš -> ir po???Nuėmiau tarpus, bet tapati klaida...
if ($insert_user = $dbh->prepare("INSERT INTO users (username, email, pass, group) VALUES (:username, :email, :pass, :group)")) {
// Bind the variables to the parameter as strings.
$insert_user -> bindParam(':username', '$username');
$insert_user -> bindParam(':email', '$email');
$insert_user -> bindParam(':pass', '$pass');
$insert_user -> bindParam(':group', '0');
// Execute the statement.
$insert_user->execute();
// Close the prepared statement.
$insert_user->close();
}
<?php
if ($insert_user = $dbh->prepare("INSERT INTO users (username, email, pass, group) VALUES (?, ?, ?, ?)")) {
// Bind the variables to the parameter as strings.
$insert_user->bind_param($dbh, "ssss", $username, $email, $pass, 0);
// Execute the statement.
$insert_user->execute();
// Close the prepared statement.
$insert_user->close();
}
?>
Vis gaunu klaidą: Fatal error: Call to undefined method PDOStatement::bind_param() in /home/minfas/domains/minfas.us.lt/public_html/srautas/reg.php on line 67.
<?php
$name = $_GET['username'];
$password = $_GET['password'];
if ($stmt = $mysqli->prepare("INSERT INTO tbl_users (name, password) VALUES (?, ?)")) {
// Bind the variables to the parameter as strings.
$stmt->bind_param("ss", $name, $password);
// Execute the statement.
$stmt->execute();
// Close the prepared statement.
$stmt->close();
}
?>