I'm working on a web app using PHP with MySQL. I have on another page successfully queried the database, and returned results to a dynamically created table. In this instance, I just need to get a name from the database.
I'm using the same basic principle and i'm attempting to assign the results to a variable, but it's bombing out on me. I know my connection is good. I run the query directly in PhpMyAdmin and it works.
Here's the code:
<?php
$con=mysqli_connect("....");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$id_num = mysqli_real_escape_string($con, $_POST['id_num']);
$username = mysqli_real_escape_string($con, $_POST['username']);
$result = mysqli_query($con,"SELECT NAME FROM users where ID ='".$id_num."' AND username='".$username."'");
$row = mysqli_fetch_array($result));
$name = $row['NAME'];
echo $name;
mysqli_close($con);
?>
The error it gives is:
Parse error: syntax error, unexpected ')' in D:\Hosting\8715276\html\delta\login.php on line 14
I'm sure this is due to my unfamiliarity with php. I've looked for specifics on how to do this but I'm not really turning much much. I investigated mysqli_fetch_array, but the examples on php.net print and do not assign to a variable. I sort of thought if (in their example) this works:
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
printf ("%s (%s)
", $row["Name"], $row["CountryCode"]);
then
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$name = $row['NAME'];
echo $name;
likewise should work. It does not. Any suggestions or links would be helpful. I've been looking at http://php.net/manual/en/mysqli-result.fetch-array.php