I have an error in my MySQL query that I run from PHP but cannot see it. First I'll start with the beginning of the code so you see how it starts, however query in question is in the end.
if (!isset($_GET['pageid']) and !isset($_POST['pageid']) and !isset($_GET['lang_code']) and !isset($_POST['lang_code']) and !isset($_GET['new']) and !isset($_POST['new'])) {
if(isset($_POST['submit']))
{
$pageid=$_POST['pageid2'];
$lang_code=$_POST['lang_code2'];
$id=$_POST['id2'];
$new2=$_POST['new2'];
if (empty($_POST['title']))
{
$errors[]=MSG_FORGOT_TITLE;
}
else {
$title = $_POST['title'];
}
if (empty($_POST['content'])) {
$errors[]=MSG_REQUEST_CONTENTL30;
}
else {
$content = $_POST['content'];
}
if (!empty($errors)) {
$s=MSG_ERROR . '
' . MSG_FOLLOWING_ERROR . '
';
foreach ($errors as $msg) { // Print each error.
$s .=' - ' . $msg . '
' ;
}
$s .=MSG_TRY_AGAIN;
}
else
{
This is where query is in error:
if($new2=="new"){
$q = "INSERT INTO pages (title, content, author, lang_code, page_id) VALUES ('$title', '$content', '$fusername', '$lang_code', '$pageid')";
$r = @mysqli_query ($dbc, $q); // Run the query.
if($r){
$success=true;
require_once ('includes/login_functions.inc.php');
$url = absolute_url();
$url = absolute_url("editpages.php?success=new");
header("Location: $url");
}
else{
$s ="<br />GREŠKA NEW";
}
}
else{
$q = "UPDATE pages SET title='$title', content='$content', author='$fusername' WHERE id='$id' ";
$r = @mysqli_query($dbc, $q); // Run the query.
if($r){
$success=true;
require_once ('includes/login_functions.inc.php');
$url = absolute_url();
$url = absolute_url("editpages.php?success=update");
header("Location: $url");
}
else{
$s ="<br />GREŠKA UPDATE";
}
}
}
else{
require_once ('includes/login_functions.inc.php');
$url = absolute_url("editpages.php");
header("Location: $url");
exit();
}
}
What I am doing is that on this page I have loaded content from database and then if changed it should update. If there was no content (new) than it should be inserted as a new row in table. All goes well until i click on "submit" and then i get error "GREŠKA UPDATE" which says that mysql query for update didn't run. Why? Same thing happened with "insert".
after adding echo mysqli_error();
i got this:
Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/.../editselectedpage.php on line 82
Have you set your database details in $dbc
?
Also, and this is probably a rookie question but why have you put a @ symbol before mysqli_query()
?
AAAAAAAAAAAAAAA! I just want to shoot myself! I forgot to change the order and put mysql connect before queries...