I get following Error:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in......
Here is my query:
$result = mysql_query("SELECT * FROM users WHERE username = $user' AND password = '$pass'");
while($row = mysql_fetch_array($result))
{
$expire = time()+60*60*24*30;
setcookie("id", $row['id'], $expire);
echo "Logged in. as <b>.".$row['username']."</b>";
}
Seems you are missing a ' on the left side of $user in this (I have added it here):
$result = mysql_query("SELECT * FROM users WHERE username = '$user' AND password = '$pass'");
Related
I've been receiving this error.
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 'schoolPass = '300570'' at line 1.
please help here is my code for login.php.
<?php
session_start();
require_once '../cn.php';
require_once '../functions.php';
if (isset($_POST['email']) && ($_POST['password'])){
$email = sanitizeString($_POST['email']);
$pass = sanitizeString($_POST['password']);
$query = "SELECT schoolEmail,schoolPass FROM schools WHERE schoolEmail =
'$email' schoolPass = '$pass'";
$result = mysqli_query ($conn, $query) or die (mysqli_error($conn));
$count = mysqli_num_rows ($result);
if ($count == 1) {
echo "pwede na";
} else {
$err = "Invalid Log in Credentials";
};
if (isset($_SESSION['email'])){
$email = $_SESSION['email'];
echo ("hello.$email.");
};
} else {
echo "email/ password not set";
};
$conn->close();
?>
Replace your code line:
$query = "SELECT schoolEmail,schoolPass FROM schools WHERE schoolEmail =
'$email' schoolPass = '$pass'";
BY
$query = "SELECT schoolEmail,schoolPass FROM schools WHERE schoolEmail =
'$email' AND schoolPass = '$pass'";
$query = "
SELECT schoolEmail
, schoolPass
FROM schools
WHERE schoolEmail = '$email'
AND schoolPass = '$pass'
";
In between your two conditions on WHERE, it should be separated by an AND or an OR or a NOT.
This is with php , PDO on MS Access .mdb with linux drivers , have this code :
$sql = "SELECT * FROM F_ART WHERE CODART = :id";
$result = $this->cache->get($sql . $id);
if(!$result){
$stm = $this->db->prepare($sql);
$stm->bindParam(':id',$id);
$stm->execute();
$result = $stm->fetchAll();
$this->cache->set($sql.$id,$result);
}
return $result;
which output this:
Error at Line : syntax error near ?
syntax error near ?
Got no result for 'SELECT * FROM F_ART WHERE CODART = ?' command
with normal query string it works :
$sql = "SELECT * FROM F_ART WHERE CODART ='" . $id . "'";
$result = $this->cache->get($sql . $id);
if (!$result) {
$result = $this->db->query($sql)->fetchAll();
$this->cache->set($sql.$id,$result);
}
return $result;
where is the problem?
I want to add record to a table which contain a picture. when i try to add, it shows me this error
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 ' masalah = 'dsd' AND gambar = 'kerusi.JPG'' at line 1
so, here are the code
<?php
session_start();
include("Connections/connection.php");
$date = $_POST['date'];
$masalah = $_POST ['masalah'];
$gambar = $_POST ['gambar'];
$student_id = $_POST['student_id'];
$status = 'pending';
/*session yg di call tok lecturer tu*/
$student_id = "SELECT * FROM student WHERE student_id ='".$_SESSION['student_id']."'" ;
$result=mysql_query($student_id);
$getstudentid = mysql_fetch_assoc($result);
$student_id = $getstudentid['student_id'];
/*take 3 data from rc */
$sql = "SELECT * FROM aduan WHERE date = '$date', masalah = '$masalah' AND gambar = '$gambar' ";
$rr = mysql_query($sql) or die(mysql_error());
$tt = mysql_num_rows($rr);
if($tt > 0) {
header("Location: borang_aduan2.php?error=2");
} else { /*to check tarikh*/
$tarikh_user = strtotime($date);
$tarikh_harini = strtotime(date('Y-m-d'));
if($tarikh_user < $tarikh_harini) {
//error
header("Location: borang_aduan2.php?error=1");
} else {
//$No = $num_rows+1;
/*$sql_const = mysql_query ("Select MAX(user_name)as id from lecturer")or die (mysql_error());
$rows = mysql_fetch_array ($sql_const);
$id = $rows ['id'];*/
/*insert data*/
mysql_query("INSERT INTO aduan (date, masalah, gambar, student_id )
VALUES('$date','$masalah', '$gambar','$student_id')")
or die('Error: ' .mysql_error($conn));
echo "<script type='text/javascript'>
alert('Thanks make a report!')
location.href='borang_aduan2.php'
</script>";
}
//Freeing all memory associated with it
mysql_free_result($result);
//Closes specified connection
mysql_close($conn);
}
?>
Dont use "," in between two field selection criteria. So instead of:
SELECT * FROM aduan WHERE date = '$date',
^^
Use
SELECT * FROM aduan WHERE date = '$date' AND
If I use id = 2, which is the Primary Key - this succeeds.
If I use usr = admin, which is just a username - this fails: it returns false.
Database image: http://i.imgur.com/ZOabVGz.jpg
$result = mysqli_query($con, "SELECT * FROM members WHERE id = 10");
while ($row = mysqli_fetch_array($result)) {
echo $row['usr']; }
usr, in your case, is a string with value "admin". You need to let SQL know it's a string, so you need to escape it - Like so
$result = mysqli_query($con, "SELECT * FROM members WHERE usr = 'admin' ");
while ($row = mysqli_fetch_array($result)) {
echo $row['usr'];
}
You need to quote it
usr = 'admin'
Will work
I want to add two table totals together, and then place it on my website here's the code I tried.
<?php
$host = "localhost";
$username = "runerebe_online";
$password = "***";
$db_name = "runerebe_online";
mysql_connect("$host", "$username", "$password") or die (mysql_error ());
mysql_select_db("$db_name") or die(mysql_error());
$host = "localhost";
$username = "runerebe_online2";
$password = "***";
$db_name = "runerebe_online2";
mysql_connect("$host", "$username", "$password") or die (mysql_error ());
mysql_select_db("$db_name") or die(mysql_error());
$total = "SELECT (online + online2)";
$rs = mysql_query($total);
while($row = mysql_fetch_array($rs)) {
echo $row['total'];
}
mysql_close();
?>
This is the error printing when I use this
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/runerebe/public_html/home/index.php on line 63
This is line 63, and what it contains
63: while($row = mysql_fetch_array($rs)) {
64: echo $row['total'];
65: }
Your query is invalid. That is why mysql_query() fails and returns FALSE instead of a resource that is needed for mysql_fetch_array() to succeed.
If you need to read two values from two different databases and if a user has permissions granted to do select on both databases and is currently connected to the database online you can do that with a statement like this
SELECT
(SELECT SUM(o2.columnname) FROM runerebe_online2.tablename o2) +
(SELECT SUM(columnname) FROM tablename) TOTAL
Otherwise you need to retrieve two values separately in php like this
//Connect and get a value from db 'runerebe_online'
...
$db_name = "runerebe_online";
$link1 = mysql_connect("$host", "$username", "$password") or die (mysql_error ());
mysql_select_db($db_name, $link1) or die(mysql_error());
$sql = "SELECT SUM(columnname) subtotal FROM tablename"
$result = mysql_query($total, $link1);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$subtotal1 = $row['subtotal'];
mysql_free_result($result);
mysql_close($link1);
//Connect and get a value from db 'runerebe_online2'
...
$db_name = "runerebe_online2";
$link2 = mysql_connect("$host", "$username", "$password") or die (mysql_error ());
mysql_select_db("$db_name", $link2) or die(mysql_error());
$sql = "SELECT SUM(columnname) subtotal FROM tablename"
$result = mysql_query($total, $link2);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$subtotal2 = $row['subtotal']
mysql_free_result($result);
mysql_close($link1);
$total = $subtotal1 + $subtotal2;
echo $total;
...