MySQL Forums
Forum List  »  PHP

Confusion for newbie
Posted by: BOb Vazoni
Date: July 23, 2017 02:10PM

Simple select statement where clause works when entering absolute value and does not when using a defined variable....see below

<?php

$playername = $_POST["name"];
echo "<h1>Name selected: " .$playername . "</h1>" ;

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "seniors";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}


echo $playername;

trim ($playername);
echo $playername;
$sqla = "SELECT firstname, lastname, home, age, bio FROM players
where lastname = $playername";
$resulta = mysqli_query($conn, $sqla);

$rowcount=mysqli_num_rows($resulta);
echo $rowcount;
if (mysqli_num_rows($resulta) > 0) {
// output data of each row
echo "<table><tr><th>First Name</th><th>Last Name</th><th>Home</th><th>Age </th><th>Bio</th><th>Pts-Obj</th><th>Pts-Made</th><th>Points</th><th>Team Amt</th><th>Ind Amt</th><th>Close-Up Amt</th></tr>";
while($rowa = $resulta->fetch_assoc())


// output data of each row

{echo "<tr><td>" . $rowa["firstname"]. "</td><td>" . $rowa["lastname"]. "</td><td>" .$rowa["home"]. "</td><td> " . $rowa["age"]. "</td><td>" . $rowa["bio"]. "</td></tr>";}
//else { while ($rowb = $resultb->fetch_assoc())



} else {
echo "<h1>This player---> " .$playername . " has no competitions. </h1>";
}
mysqli_close($conn);

?>
when substituting actual name for $playername query works

Help from a newbie!

Options: ReplyQuote


Subject
Written By
Posted
Confusion for newbie
July 23, 2017 02:10PM
July 23, 2017 02:21PM
July 23, 2017 06:26PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.