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 3 years ago.
Improve this question
I am trying to load my website but i get the error message:
Parse error: syntax error, unexpected '$result' (T_VARIABLE) in
/var/www/html/dbconnect.php on line 17
Does anybody know what the problem is with line 17? I cant seem to find out
Php code:
<?php
$servername = "localhost";
$database = "db";
$username = "root";
$password = "philip123";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT id, name, lastname, email FROM Students"
$result = $conn-> query($sql);
if ($result-> num_rows > 0) {
while ($row = $result-> fetch_assoc()) {
echo "<tr><td>". $row["id"] ."</td><td>". $row["name"] ."</td><td>". $row["lastname"] ."</td><td>". $row["email"] ."</td></tr>";
}
echo "</table>";
}
else {
echo "0 results";
}
$conn-> close();
?>
Line 17 is this line:
$result = $conn-> query($sql);
You are missing a semicolon at the line:
$sql = "SELECT id, name, lastname, email FROM Students"
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 1 year ago.
Improve this question
I am facing a problem when i am try to check user and password from database while login it keep
reply an error message :
Notice: Trying to get property 'num_row' of non-object in /Applications/XAMPP/xamppfiles/htdocs/studyact/login.php on line 27
User name or Password is incorrect, please check and try again.
i type user and password correct! enter image description here
php file :
<?php
//html
$user_staff = $_POST["user_staff"];
$pass_staff = $_POST["pass_staff"];
// Create connection
$servername = "localhost";
$username = "root";
$password = "";
$db ="studyact";
$con = new mysqli($servername, $username, $password,$db);
// Check connection
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}else{
$stmt =$con-> prepare("select * from loginstaff where user_staff = ?");
$stmt->bind_param("s",$user_staff);
$stmt->execute();
$stmtresult = $stmt->get_result();
if($stmtresult-> num_row > 0){
$data = $stmtresult-> fetch_assoc();
if($data["pass_staff"] === $pass_staff){
echo "<h2>Login Successfully</h2>";
}
else{
echo "<h2> Sorry User name or Password is incorrect.</h2>";
}
}else{
echo "<h2> User name or Password is incorrect, please check and try again.</h2>";
}
}
?>
You've got a typo on line 27
if($stmtresult->num_rows > 0)
mysqli_stmt::$num_rows — Returns the number of rows fetched from the server
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
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.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
<?php
$server = "localhost";
$username = "root";
$password = "";
$database = "jaka_crud_ci";
mysqli_connect($server, $username, $password, $database);
$query = "SELECT * FROM pembeli";
$result = mysqli_query($query)
while ( $buyer = mysqli_fetch_assoc($result)){
echo $buyer ["nama_pembeli"];
echo $buyer ["nama_barang"];
echo $buyer ["nama_retribusi"];
}
?>
code above displaying syntax error, unexpected 'while' (T_WHILE). How it will be free from error? Help me
Put a semicolon at the end of
$result = mysqli_query($query);
And you got the syntax wrong for mysqli_query, the correct one is,
mysqli_query($connection_variable, $query)
So for your case it will be like,
$con = mysqli_connect($server, $username, $password, $database);
and then use it like,
$result = mysqli_query($con, $query);
Please update below line
$result = mysqli_query($query)
to
$result = mysqli_query($query);
; is missing in that line. That's why the error occurred.
You are missing ; after mysqli_query($query) . Updated code is as below.
<?php
$server = "localhost";
$username = "root";
$password = "";
$database = "jaka_crud_ci";
mysqli_connect($server, $username, $password, $database);
$query = "SELECT * FROM pembeli";
$result = mysqli_query($query);
while ( $buyer = mysqli_fetch_assoc($result)){
echo $buyer ["nama_pembeli"];
echo $buyer ["nama_barang"];
echo $buyer ["nama_retribusi"];
}
?>
its pretty simple syntax error,You are missing ; after mysqli_query($query)
You can also use the php command line options to check the sytax errors
php -l filename
-l Provides a convenient way to perform only a syntax check on the given PHP code. On success, the text No syntax errors detected in <filename> is written to standard output
it will show if there any sytax error in the give filename
More Detail :http://php.net/manual/en/features.commandline.options.php
i hope this is helpful
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
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.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I am trying to print out one column called Language1 from my Table that is called Mull, in a database called v6e.
At the moment i am getting a blank white screen.
<?php
session_start();
$servername = "localhost";
$user = "xxxx";
$password = "xxxx";
$dbname = "v6e";
// Create connection
$conn = mysqli_connect($servername, $user, $password, $dbname);
// Check connection
if (!$conn)
{
die("Connection failed: " . mysqli_connect_error());
}
else
{
$query = "SELECT Language1 FROM Mull WHERE username = 'Mull'";
$result = mysqli_query($query);
$row = mysqli_fetch_arrary($result);
echo $row['Language1'];
}
mysqli_close($conn);
?>
You have a typo issue. Change the line:
$row = mysqli_fetch_arrary($result);
With:
$row = mysqli_fetch_array($result);
Plus, you're also not connecting to DB with your query
$result = mysqli_query($conn, $query);
Reference:
http://php.net/manual/en/mysqli.query.php
You should also check for errors:
http://php.net/manual/en/mysqli.error.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 know I am doing something wrong but I really would like to know what it is. I can echo the
username of the session loggedin user using <?php echo $_SESSION['username']; ?>but I don't know why it doesn't work when I try to query database using the same technique. my codes below
I include this in the page
<?php
session_start();
$username=$_SESSION['username'];
?>
and here is the code that was suppose to display firstname and user_id of the sessions logged in user
<?php
$conn = new mysqli('localhost', 'root', 'browser', 'test');
if (mysqli_connect_errno()) {
exit('Connect failed: '. mysqli_connect_error());
}
$username = '$username';
$sql = "SELECT `user_id`, `firstname` FROM `members` WHERE `username`='$username'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo '<br /> user_id: '. $row['user_id']. ' - firstname: '. $row['firstname'];
}
}
else {
echo '0 results';
}
$conn->close();
?>
$username = '$username';
PHP variables inside single-quotes are not expanded. So now your variable is the literal string '$username', which undoubtedly won't match any user in your database.
You probably need to set $username = $_SESSION['username']; in your second PHP script.
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
EDIT/AWNSER: It was a bloody typo, dont mind me facedesking, thanks Sadikhasan
For some reason, the function mysqli_query in my code below, doesnt work, when i open the page, it returns an error.
Fatal error: Call to undefined function msqli_query() in
**/**/**/**/**db.php on line 16
I double checked the script, but couldnt find any typo's or ";" misplacements, the login part works, its purly the query that derps.
<?php
$sqlhost = '*****';
$sqlname = '*****';
$sqlpass = '*****';
$sqldbname = '*****';
$con=mysqli_connect($sqlhost,$sqlname,$sqlpass,$sqldbname);
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}else{
echo "connection successfull!";
}
$result = msqli_query($con,"SELECT * FROM PEOPLE");
while($row = mysqli_fetch_array($result)) {
echo $row['ID'] . "<br>";
echo $row['NAME'] . "<br>";
echo $row['AGE'] . "<br>";
echo $row['SEX'] . "<br>";
echo "<hr>";
}
mysqli_close($con);
?>
The names are in capitals in the database, i checked that too :)
thanks for the help in advance!
Correct spelling to mysqli in this line
$result = msqli_query($con,"SELECT * FROM PEOPLE");