mysql - unexpected ')' Parse error: syntax error, unexpected ')' in C:\xampp\htdocs\login6.php on line 17 -


i making php script gets table data database, , getting following error:

unexpected ')' parse error: syntax error, unexpected ')' in c:\xampp\htdocs\login6.php on line 17

when delete it, more errors.

<?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'nemrac587'; $dbname='c';  $conn = mysqli_connect ($dbhost, $dbuser, $dbpass, $dbname);  if(! $conn ) {   die('could not connect: ' . mysqli_error()); }  $sql = 'select id, name, password users'; mysqli_select_db('test_db'); $retval = mysqli_query( $sql, $conn );  if(! $retval ) { ()   die('could not data: ' . mysqli_error()); }  while($row = mysqli_fetch_array($retval, mysql_assoc)) {   echo "emp id :{$row['id']}  <br> ".      "emp name : {$row['name']} <br> ".      "emp salary : {$row['password']} <br> ".      "--------------------------------<br>"; }  echo "fetched data successfully\n";  mysqli_close($conn); ?> 

besides other answer(s): (one deleted)

your query mysqli_select_db('test_db'); $retval = mysqli_query( $sql, $conn ); never happen.

you need pass connection mysqli_select_db (consult footnotes) , connection comes first in mysqli_

references:

then mysql_assoc should read mysqli_assoc

mysqli_error() requires connection also.

mysqli_error($conn)


edit:

as requested, following incorrect:

if(! $retval ) { ()   die('could not data: ' . mysqli_error()); } 

that should read as

if(! $retval ) {   die('could not data: ' . mysqli_error()); } 

the added () shouldn't in there , reason parse error.

however, pass connection error function:

if(! $retval ) {   die('could not data: ' . mysqli_error($conn)); } 

it required, , per manual states http://php.net/manual/en/mysqli.error.php

string mysqli_error ( mysqli $link )


footnotes:

another point though, don't need mysqli_select_db('test_db'); declared 4 parameters in (which includes variable database):

$conn = mysqli_connect ($dbhost, $dbuser, $dbpass, $dbname); 

so rid of mysqli_select_db('test_db');.


additional edit:

noticing other question https://stackoverflow.com/q/34602141/ , being bonus answer in way:

you seem storing passwords in plain text , in present question {$row['password']} suggests password-relation.

  • if intended go live, don't. will hacked.

use 1 of following:

other links:


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -