HTML Table MySQL id & Editing existing content

Alright I have a HTML Table displaying Data from a MySQL Table.

[php]

Vipre Database


lable { display: block; }

Add Client <?php

include_once ‘resources/init.php’;

$query=“SELECT * FROM Client”;
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();
?>

<?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"firstname"); $f2=mysql_result($result,$i,"lastname"); $f3=mysql_result($result,$i,"email"); $f4=mysql_result($result,$i,"invoice"); $f5=mysql_result($result,$i,"wink"); $f6=mysql_result($result,$i,"wint"); $f7=mysql_result($result,$i,"vtype"); $f8=mysql_result($result,$i,"usera"); $f9=mysql_result($result,$i,"yeara"); $f10=mysql_result($result,$i,"sdate"); $f11=mysql_result($result,$i,"edate"); $f12=mysql_result($result,$i,"viprek"); $f13=mysql_result($result,$i,"id"); ?> <?php $i++; } ?> [/php]

I want one of the columns to have a Edit Link that will take the current tables id and then go to my edit form.
I am just starting to learn this stuff so I am guessing my code is bad or I just don’t know what I am doing. XD

Firstname Lastname Email Invoice# Windows Key Windows Type VIPRE Type User Count Year Count Start Date Expire Date VIPRE Key Edit
<?php echo $f1; ?> <?php echo $f2; ?> <?php echo $f3; ?> <?php echo $f4; ?> <?php echo $f5; ?> <?php echo $f6; ?> <?php echo $f7; ?> <?php echo $f8; ?> <?php echo $f9; ?> <?php echo $f10; ?> <?php echo $f11; ?> <?php echo $f12; ?> Edit

You have an error on the line:

[php]$num=mysql_numrows($result);[/php]

The function should be mysql_num_rows.

From a quick glance, the rest of the code should work OK, apart from the id=id part on your edit link. When you get the items from the database, you are putting the ID of the record into $f13, so you could just echo out $f13 where you need the ID:

[php]

Edit[/php]

Thanks for the help, What is a good way to pass the id number to the next page?

For some reason I can’t find the edit button on this website, but here is my page that is suppose to change existing data. I have firstname setup only just until I get it working. It is still not working. I don’t know what I need to change.

[php]<?php

include ‘init.php’;
if (isset ($_POST[‘submit’])) {
$q = “SELECT * FROM Client WHERE id = $_GET[id]”;
$result = mysql_query($q);
$client = mysql_fetch_array($result);
}
?>
Back To List

First Name: Last Name:

Email:

Invoice #:



Windows Key: Windows Type:



VIPRE Type: User Count: Year Count:

Start Date: Expire Date:

VIPRE Key:


<?php
if(isset($_POST["submit"])) {
    $u = "UPDATE Client SET `firstname`='$_POST[firstname]' WHERE id = $_POST[id]";
    mysql_query($u) or die (mysql_error());
    
    echo "User has been modified!";
    header("Location: index.php");
    
} else {

    
}
?>[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service