bugzy Posted March 28, 2012 Share Posted March 28, 2012 I have a table that has 5 columns player_id fname lname team email I'm trying to get all the values from that table using this sql command include_once('../database_connection.php'); $player_id = addslashes($_REQUEST['edit_player']); $sql_query = "Select * from nba_info where player_id = '$player_id'"; $result = MYSQL_QUERY($sql_query); "edit_player" above is came from a different page. They I'm fetching the data using while while($row = mysql_fetch_array($result)) { $row['player_id']; $row['fname']; $row['lname']; $row['team']; $row['email']; } Then I'm trying to pass that values to a variable here $id = $row['player_id']; $fname = $row['fname']; $fname = $row['lname']; $lname = $row['team']; $email = $row['email']; When I'm trying to put that variables in a textbox value, they are not showing up Here <table> <form name="edit_player_form" method="post" action=""> <tr> <td>Players ID</td> <td><input type="text" name="playerid" size="20" value="<?php echo $id; ?>" /></td> </tr> <tr> <td>First Name</td> <td><input type="text" name="fname" size="20" value="<?php echo $fname; ?>" /></td> </tr> <tr> <td>Last Name</td> <td><input type="text" name="lname" size="20" value="<?php echo $lname; ?>" /></td> </tr> <tr> <td>Team</td> <td><input type="text" name="team" size="20" value="<?php echo $team; ?>" /></td> </tr> <tr> <td>Email</td> <td><input type="text" name="email" size="20" value="<?php echo $email; ?>" /></td> </tr> <tr> <td><div align="center"> <input type="submit" name="Submit" value="Edit This Player"> </div></td> </tr> </form> </table> I wonder why it ain't showing up on the textbox value? tried almost everything... Anyone? Quote Link to comment Share on other sites More sharing options...
requinix Posted March 28, 2012 Share Posted March 28, 2012 Can you post the whole code without separating it into pieces? Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 28, 2012 Share Posted March 28, 2012 Look at the first example on mysql_query $result = mysql_query('SELECT * WHERE 1=1'); if (!$result) { die('Invalid query: ' . mysql_error()); } Add this, do you get an error? Quote Link to comment Share on other sites More sharing options...
bugzy Posted March 28, 2012 Author Share Posted March 28, 2012 Can you post the whole code without separating it into pieces? Hey thanks here <?php include_once('../database_connection.php'); $player_id = addslashes($_REQUEST['edit_player']); $sql_query = "Select * from nba_info where player_id = '$player_id'"; $result = MYSQL_QUERY($sql_query); $numberOfRows = MYSQL_NUM_ROWS($result); while($row = mysql_fetch_array($result)) { $row['player_id']; $row['fname']; $row['lname']; $row['team']; $row['email']; } $id = $row['player_id']; $fname = $row['fname']; $fname = $row['lname']; $lname = $row['team']; $email = $row['email']; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>This Is Where we Edit the Data!</title> </head> <body><center><br /><br /> <?php if($numberOfRows==0) { die('There\'s no Player with that player ID number'); } ?> <table> <form name="edit_player_form" method="post" action=""> <tr> <td>Players ID</td> <td><input type="text" name="playerid" size="20" value="<?php echo $id; ?>" /></td> </tr> <tr> <td>First Name</td> <td><input type="text" name="fname" size="20" value="<?php echo $fname; ?>" /></td> </tr> <tr> <td>Last Name</td> <td><input type="text" name="lname" size="20" value="<?php echo $lname; ?>" /></td> </tr> <tr> <td>Team</td> <td><input type="text" name="team" size="20" value="<?php echo $team; ?>" /></td> </tr> <tr> <td>Email</td> <td><input type="text" name="email" size="20" value="<?php echo $email; ?>" /></td> </tr> <tr> <td><div align="center"> <input type="submit" name="Submit" value="Edit This Player"> </div></td> </tr> </form> </table> <center> </body> </html> Quote Link to comment Share on other sites More sharing options...
bugzy Posted March 28, 2012 Author Share Posted March 28, 2012 Look at the first example on mysql_query $result = mysql_query('SELECT * WHERE 1=1'); if (!$result) { die('Invalid query: ' . mysql_error()); } Add this, do you get an error? Hello! I got this Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE 1=1' at line 1 what do you think? Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 28, 2012 Share Posted March 28, 2012 Well don't use the example query, for one that's not even a valid query, and it's clearly not yours. Quote Link to comment Share on other sites More sharing options...
Drummin Posted March 28, 2012 Share Posted March 28, 2012 When using mysql_fetch_array you'll need to set your variables within the array opening and closing brackets. <?php include_once('../database_connection.php'); $player_id = addslashes($_REQUEST['edit_player']); $sql_query = "Select * from nba_info where player_id = '$player_id'"; $result = MYSQL_QUERY($sql_query); $numberOfRows = MYSQL_NUM_ROWS($result); while($row = mysql_fetch_array($result)) { $id = $row['player_id']; $fname = $row['fname']; $fname = $row['lname']; $lname = $row['team']; $email = $row['email']; } ?> Quote Link to comment Share on other sites More sharing options...
bugzy Posted March 28, 2012 Author Share Posted March 28, 2012 Well don't use the example query, for one that's not even a valid query, and it's clearly not yours. Huh? I don't know what you're talking about. I'm new in php and this is not a project that I'm doing. I'm just practicing base on a sample code from a tutorial video and I encountered this issue and I can't find the solution on it. From an expert like you, I thought the code that you have given would detect why I'm having this issue Quote Link to comment Share on other sites More sharing options...
bugzy Posted March 28, 2012 Author Share Posted March 28, 2012 When using mysql_fetch_array you'll need to set your variables within the array opening and closing brackets. <?php include_once('../database_connection.php'); $player_id = addslashes($_REQUEST['edit_player']); $sql_query = "Select * from nba_info where player_id = '$player_id'"; $result = MYSQL_QUERY($sql_query); $numberOfRows = MYSQL_NUM_ROWS($result); while($row = mysql_fetch_array($result)) { $id = $row['player_id']; $fname = $row['fname']; $fname = $row['lname']; $lname = $row['team']; $email = $row['email']; } ?> Thanks Drummin This is exactly what I did and it solved the issue Thanks again! Quote Link to comment Share on other sites More sharing options...
Drummin Posted March 28, 2012 Share Posted March 28, 2012 You're probably going to want to use isset() for those variables within the form so you don't have errors when these variables are not set (before passing the form.) <input type="text" name="playerid" size="20" value="<?php if (isset($id)){ echo "$id";} ?>" /> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.