Welcome! Log In Create A New Profile

Advanced

Update script no extracting values

Posted by Rufus Satekge 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Update script no extracting values
April 23, 2013 02:33PM
Hi

My edit script is not extracting any value when I open it in the list script. The form pops up blank

Please Help
Language: PHP
//get value of id $player_id = $_GET['player_id']; //update data in database $query = "UPDATE playerinfo SET name = '$name', surname = '$surname', contactnumber = '$contactnumber', email = '$email', position = '$position', username = '$username', password = '$password' WHERE player_id = '$player_id'"; //retrieve data from database $query = "SELECT * FROM playerinfo WHERE player_id = '$player_id'"; $result = mysql_query($query) or die("Query failed: ".mysql_error());
avatar
Mac
Re: Update script no extracting values
April 23, 2013 03:11PM
This is not the list code.... your question does not make any sense.
Re: Update script no extracting values
April 25, 2013 01:11PM
Ok. Here is the list script
Language: PHP
$query = "SELECT * FROM playerinfo"; $result = mysql_query($query) or die("Query failed: ".mysql_error());   echo"<table border='1'><tr bground='#CCCCCC'><td>Name</td><td>Surname</td><td>Contact number</td><td>Email</td><td>Position</td><td>Username</td><td>Password</td><td colspan='2'>Action</td></tr>"; while($row = mysql_fetch_array($result)) { $phone_id=$row['player_id']; echo"<tr><td>"; echo $row['name']; echo"</td><td>"; echo $row['surname']; echo"</td><td>"; echo $row['contact number']; echo"</td><td>"; echo $row['email']; echo"</td><td>"; echo $row['position']; echo"</td><td>"; echo $row['username']; echo"</td><td>"; echo $row['password']; echo"</td><td>"; echo"<a href=edit.php?player_id=$player_id&update=yes>Edit</a>"; echo"</td><td>"; echo"<a href=delete.php?player_id=$player_id&delete=yes>Delete</a>"; echo"</tr>"; } echo"</table>";
avatar Re: Update script no extracting values
April 25, 2013 01:17PM
Your first query will never be run.

$query is a variable that you assign a value to. First you assigned the value :
Language: PHP
$query = "UPDATE playerinfo SET name = '$name', surname = '$surname', contactnumber = '$contactnumber', etc...'";

and then you write this over that value:
Language: PHP
$query = "SELECT * FROM playerinfo WHERE player_id = '$player_id'";

If you were to echo $query it would just show "SELECT * FROM playerinfo WHERE player_id = '$player_id". So go google how to run multiple queries on the same page. Hint: try moving different queries into different functions and have them return the result. smile

----------------------------------------------------------------------------------------

int get_random_number() {
return 4;
}
avatar
Mac
Re: Update script no extracting values
April 25, 2013 02:15PM
If the 2nd line does not produce an error, then I have to ask a silly question - is the data in the table?

Language: PHP
//use this to see if there are rows with data given your query $num_rows = mysql_num_rows($result); echo "Number of rows: $num_rows";
Re: Update script no extracting values
April 29, 2013 02:08PM
Mac the problem is that when I click on the edit link in the list_players page, the edit form comes up empty as if there are no records the database.
And the echo statement output "Number of rows: 0. Question is why zero rows when there is data in the database
Language: PHP
//get value of id $player_id = $_GET['player_id'];   //update data in database $query = "UPDATE playerinfo SET name = '$name', surname = '$surname', contactnumber = '$contactnumber', email = '$email', position = '$position', username = '$username', password = '$password' WHERE player_id = '$player_id'"; //retrieve data from database $query = "SELECT * FROM playerinfo WHERE player_id = '$player_id'"; $result = mysql_query($query) or die("Query failed: ".mysql_error()); $num = mysql_numrows($result); echo "Number of rows: $num"; $i = 0; while($i < $num){ $name = mysql_result($result,$i,"name"); $surname = mysql_result($result,$i,"surname"); $$contactnumber = mysql_result($result,$i,"contactnumber"); $email = mysql_result($result,$i,"email"); $position = mysql_result($result,$i,"position"); $username = mysql_result($result,$i,"username"); $password = mysql_result($result,$i,"password"); $i++;
Sorry, only registered users may post in this forum.

Click here to login