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
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 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"
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 needs debugging details. It is not currently accepting answers.
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.
Closed 8 years ago.
Improve this question
I have been reading many different pieces of code an I am confused as to why the $echo row[0] at the bottom of my code here does not return anything.
$dbhost = 'localhost';
$uname = $_POST["uname"];
//***create connection object
$connection = mysql_connect($dbhost, "bc572fsdf", "abcdfsds") or die(mysql_error());
$dbname = "bc57db";
mysql_select_db($dbname) or die(mysql_error());
//***select a random security question
//*** need this to import session variables
session_start();
echo ($_SESSION["ValidUser"] . "\n");
$rq = array('q1', 'q2', 'q3');
$rand_key = array_rand($rq, 1);
echo $rq[$rand_key];
$question = $rq[$rand_key];
$qtoanswer = mysql_query("select '$question' from users where uname = '$uname'");
if (!$qtoanswer) {
echo "Could not run query:" . mysql_error();
exit;
}
echo $qtoanswer;
$row = mysql_fetch_row($qtoanswer);
echo $row[0];
?>
The fault is in this line:
$qtoanswer = mysql_query("select '$question' from users where uname = '$uname'");
You should be using grave marks for the column name, such as:
$qtoanswer = mysql_query("select `$question` from users where uname = '$uname'");
^ ^
Also, you should be using MySQLi/PDO, so you can prepare this, or at the very least, escape $uname.
Because you cannot echo a array....try var_dump or print_r, or use a loop:
foreach($row[] as $result) {
echo $row[], '<br>';
}
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 tried to copy How to Check if value exists in a MySQL database and make my own, but for some reason it wont work...
This is what I got:
<?php
$host = '127.0.0.1';
$username = 'root';
$password = '';
$dbname = 'multiplayer';
$con=mysqli_connect($host, $username, $password, $dbname);
$check_player_ip=mysqli_query($con, 'SELECT `player_ip` FROM `playerdata` WHERE username = "remco" AND active = 0');
if (mysqli_num_rows($check_player_ip) == 0) {
//didnt find anything
} else{
//found something
}
?>
I get this error:
Parse error: syntax error, unexpected '$check_player_ip' (T_VARIABLE) in C:\xampp\htdocs\test.php on line 1
Solution
If you get the T_VARIABLE error, check the varriable before this rule. You may forgot the place the ';' xD
Thanks for all support!
You are mixing MySQL APIs, they do not mix together. mysql_num_rows
Use mysqli_num_rows()
Also make sure your DB connection is also mysqli_* and not mysql_*
EDIT after you've edited your question.
You need to pass DB connection to your query:
$check_player_ip=mysqli_query($con,'SELECT...`
$con being your DB connection. Change accordingly.
Plus WHERE username = remco - the word remco needs to be wrapped in quotes, it's a string and not an int.
WHERE username = 'remco'
Sidenote:
Your present code is open to SQL injection.
Use prepared statements, or PDO with prepared statements.
Edit 2:
Try inverting the quotes:
$check_player_ip=mysqli_query($con, "SELECT `player_ip` FROM `playerdata` WHERE username = 'remco' AND active = 0");
if (mysqli_num_rows($check_player_ip) == 0) {
//didnt find anything
}
Try this:
<?php
$host = '127.0.0.1';
$username = 'root';
$password = '';
$dbname = 'multiplayer';
$con = new mysqli( $host, $username, $password, $dbname );
/* Check Connection */
if ( $con->connect_error ) {
printf( "Connect failed: %s\n", $con->connect_error );
exit();
}
/* Query - Returns a resultset */
if ( $result = $con->query('SELECT `player_ip` FROM `playerdata` WHERE username = "remco" AND active = 0 ') ) {
if ( $result->num_rows <= 0 ) {
//didnt find anything
printf("No player");
} else {
//found something
printf("Select returned %d rows.\n", $result->num_rows);
}
/* free result set */
$result->close();
}
/* close connection */
$con->close();
?>
you should execute that mysqli query...
while($rows = mysql_arrayAssoc($ursql)){
$data[]=$rows;
}
if($something== $data['attribute']) //attribute(id,name...)
echo "ok some data is in"
else
echo "no matching data"
I hope it help you :)
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'm new at PHP and just learning.
<?php
// database connection
$dbhost = "localhost";
$dbname = "pdo";
$dbuser = "root";
$dbpass = "7777777";
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass)
// echo from database
$select = $conn->query('SELECT username FROM users');
while($row = $select->fetch(PDO::FETCH_ASSOC))
{
$username = $_GET['username'];
echo $username;
}
?>
This gives error:
Parse error: syntax error, unexpected T_PUBLIC in line : $select = $conn->query('SELECT username FROM users');
The connection needs to be changed
From:
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass)
To:
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
The connection is missing a ;