Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-15-2011, 11:25 PM   PM User | #1
zelig
New Coder

 
Join Date: Nov 2011
Posts: 20
Thanks: 1
Thanked 0 Times in 0 Posts
zelig is an unknown quantity at this point
hyperlink within a results table

Here is the scenario I'm stuck with.

I have an output of all the items within a database and they're put into a table.

How do I make it so that someone can click on the unique ID (primary key) so that they can open the create form (that was used to create the item) so that the details of that item can be changed and then resaved/modified?

Thanks!
zelig is offline   Reply With Quote
Old 11-15-2011, 11:53 PM   PM User | #2
amof
New Coder

 
Join Date: Feb 2011
Posts: 16
Thanks: 1
Thanked 0 Times in 0 Posts
amof is an unknown quantity at this point
something like this?

PHP Code:
<?php

include_once('include/config.php'); 

$Querytable mysql_query("SELECT * FROM db_users") or die (mysql_error()); 

while (
$row mysql_fetch_assoc($Querytable)) {

    
$userid $row['userid'];
    
$initials $row['initials'];
    
    echo 
"<tr>";
    echo 
"<td><a href=\"edituser.php?id=$userid\">$initials</a></td>";
    echo 
"</tr>";



?>
amof is offline   Reply With Quote
Old 11-16-2011, 05:13 PM   PM User | #3
zelig
New Coder

 
Join Date: Nov 2011
Posts: 20
Thanks: 1
Thanked 0 Times in 0 Posts
zelig is an unknown quantity at this point
Hmm... It linked to the edit page, but it didn't populate the info from the database about that item.
zelig is offline   Reply With Quote
Old 11-21-2011, 01:02 AM   PM User | #4
zelig
New Coder

 
Join Date: Nov 2011
Posts: 20
Thanks: 1
Thanked 0 Times in 0 Posts
zelig is an unknown quantity at this point
*bump*

So, it goes to the edit form, but doesn't pre-populate the info from the database.

How would I go about fixing this?

Thanks!
zelig is offline   Reply With Quote
Old 11-21-2011, 01:20 AM   PM User | #5
Adee
Regular Coder

 
Join Date: Jul 2010
Location: Oregon City
Posts: 280
Thanks: 5
Thanked 50 Times in 49 Posts
Adee can only hope to improve
In the edit form page..

You need to make like a query so it does:
SELECT * FROM table where id = 'whateverID'

then you have ..

PHP Code:
$result mysql_query($query);
$data mysql_fetch_assoc($result); 
form could be something like

Code:
<form method="post" action="someaction.php">
Name : <input type="text" name="prodname" value="<?php echo $data['name']; ?>" />
</form>
and so on..
Adee is offline   Reply With Quote
Old 11-21-2011, 08:12 PM   PM User | #6
zelig
New Coder

 
Join Date: Nov 2011
Posts: 20
Thanks: 1
Thanked 0 Times in 0 Posts
zelig is an unknown quantity at this point
Ok, I tried this, but I get an error now:


Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in edit_equipment.php on line 13

Here is what I have so far, and it didn't populate the name into the field like I thought it would... :

Code:
<?php
include("lib.php");
define("PAGENAME", "Edit Equipment");

if ($player->access < 100)

$msg1 = "<font color=\"red\">"; //name error?
$error = 0;

$query = $db->execute("SELECT * FROM `items` WHERE `id`=?", array($_POST['id']));
	
	$result = mysql_query($query);
	$data = mysql_fetch_assoc($result); 
	
$msg1 .= "</font>"; //name error?


?>

<?=$could_not_register?>

<h2 align="center"><strong>Item Creator:</strong></h2>
<form method="post"  action="edit_equipment.php">
<table width="86%" border="0">
  <tr>
    <td>
        <label>
          Name</label>
</td>
    <td><label><input type="text" name="name" value="<?php echo $data['name']; ?>">
  </label>
  &lt;-- Name of Item
  <?=$msg1;?></td>
  </tr>
</table>
<?=$msg2;?>
      <input type="submit" name="register" value="Create Item!"> 
      <input type="reset" value="Reset Fields">
</form>
zelig is offline   Reply With Quote
Old 11-21-2011, 09:34 PM   PM User | #7
coding_begins
Regular Coder

 
Join Date: Aug 2011
Posts: 134
Thanks: 20
Thanked 0 Times in 0 Posts
coding_begins is an unknown quantity at this point
have u tried echoing the query and see wat it returns:
SELECT * FROM `items` WHERE `id`=?", array($_POST['id']);
coding_begins is offline   Reply With Quote
Old 11-22-2011, 01:35 AM   PM User | #8
zelig
New Coder

 
Join Date: Nov 2011
Posts: 20
Thanks: 1
Thanked 0 Times in 0 Posts
zelig is an unknown quantity at this point
Okay, I threw in a "echo $result;", but I don't see anything...

Just that same error.

Code:
<?php
include("lib.php");
define("PAGENAME", "Edit Equipment");

if ($player->access < 100)

$msg1 = "<font color=\"red\">"; //name error?
$error = 0;

$query = $db->execute("SELECT * FROM `items` WHERE `id`=?", array($_POST['id']));
	
	$result = mysql_query($query);
	
	echo $result;
	
	$data = mysql_fetch_assoc($result); 
	
$msg1 .= "</font>"; //name error?


?>
Either I didn't do the echo correct, or there isn't anything...
zelig is offline   Reply With Quote
Old 11-22-2011, 01:54 AM   PM User | #9
zelig
New Coder

 
Join Date: Nov 2011
Posts: 20
Thanks: 1
Thanked 0 Times in 0 Posts
zelig is an unknown quantity at this point
Ok, when I throw in a "echo "$id";", it shows the right ID of the item that I clicked to edit... So it must be in the query somewhere that $result isn't pulling up...
zelig is offline   Reply With Quote
Old 11-22-2011, 02:08 AM   PM User | #10
zelig
New Coder

 
Join Date: Nov 2011
Posts: 20
Thanks: 1
Thanked 0 Times in 0 Posts
zelig is an unknown quantity at this point
Ok, another thing... I put in an echo $query, and it lists the field names rather than the actual data of the item. That could be the problem...

Any clues?

Thanks!!
zelig is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:54 PM.


Advertisement
Log in to turn off these ads.