Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

add, edit, delete error

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

add, edit, delete error

Postby arjanvrx » Fri Sep 20, 2013 2:59 pm

I already asked this in a few other forms and I am getting suggestions but I still cannot put it together. Can someone please tell me how to fix it by giving the exact code so I can learn from my mistakes. If it's a million lines to add then I understand it's too much work but if it's only a few line. I need this to work asap so I can extend it and have the complete script with search function working somewhere next week.

I posted below on other forums:
I rewritten parts of my script that should add, edit and delete items from my mysql database. A simple task for most of you guys but I am running into trouble. Please tell me how to fix this script so I can learn from it..



Klanten.php, where I display and add data. This works fine.

Code: Select all
<!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=iso-8859-1" />
<title>Toevoegen</title>
</head>

<body>

<!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=iso-8859-1" />
<title>Toevoegen</title>
</head>

<body>

<?php
# errors weergeven
ini_set('display_errors',1); // 1 == aan , 0 == uit
error_reporting(E_ALL | E_STRICT);
?>

<form method="post">
<table>
    <tr>
        <td>Klantnummer:</td>
        <td><input type="text" name="Klantnummer" /></td>
    </tr>
    <tr>
        <td>Bedrijf:</td>
        <td><input type="text" name="Bedrijf" /></td>
    </tr>
    <tr>
        <td>Contactpersoon:</td>
        <td><input type="text" name="Contactpersoon" /></td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td><input type="submit" name="submit" value="add" /></td>
    </tr>
</table>
<?php
if (isset($_POST['submit']))
    {       
    include 'db_config.php';
                    $Klantnummer=$_POST['Klantnummer'] ;
                    $Bedrijf=$_POST['Bedrijf'] ;
                    $Contactpersoon= $_POST['Contactpersoon'] ;                   
                                                       
                                               
         mysql_query("INSERT INTO `klanten`(Klantnummer,Bedrijf,Contactpersoon)
         VALUES ('$Klantnummer','$Bedrijf','$Contactpersoon')");

   }
?>
</form>
<table border="1">
   
            <?php
            error_reporting(E_ALL);
            include("db_config.php");
           
               
            $result=mysql_query("SELECT * FROM klanten");
           
            while($test = mysql_fetch_array($result))
            {
                $Klantnummer = $test['Klantnummer'];   
                echo "<tr align='center'>";
                echo"<td><font color='black'>" .$test['Klantnummer']."</font></td>";   
                echo"<td><font color='black'>" .$test['Bedrijf']."</font></td>";
                echo"<td><font color='black'>" .$test['Contactpersoon']."</font></td>";
                echo"<td> <a href ='edit.php?ID=$Klantnummer'>Edit</a>";
                echo"<td> <a href ='del.php?ID=$Klantnummer'><center>Delete</center></a>";
                                   
                echo "</tr>";
            }
           
            ?>
</table>

</body>
</html>                                                                           

del.php where offcouse I delete clients, it did work in the past before I tried to modiy the primary ID to Klantnummer



It shows:

Notice: Undefined variable: ID in /home/schoolme/public_html/ret/del.php on line 12

Warning: Cannot modify header information - headers already sent by (output started at /home/schoolme/public_html/ret/del.php:12) in /home/schoolme/public_html/ret/del.php on line 15

Code: Select all
<?php
    # errors weergeven
    ini_set('display_errors',1); // 1 == aan , 0 == uit
    error_reporting(E_ALL | E_STRICT);
   
    include("db_config.php"); 

    $id =$_REQUEST['ID'];
   
   
    // sending query
    mysql_query("DELETE FROM klanten WHERE Klantnummer = '$Klantnummer'")
    or die(mysql_error());     
   
    header("Location: klanten.php");
?>Edit.php seems to work as it brings me to a page that shows all the data.

<?php
# errors weergeven
ini_set('display_errors',1); // 1 == aan , 0 == uit
error_reporting(E_ALL | E_STRICT);
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table>
  <tr>
    <td align="center">EDIT DATA</td>
  </tr>
  <tr>
    <td>
      <table border="1">
      <?
      include"db_config.php";//database connection
      $order = "SELECT * FROM klanten";
      $result = mysql_query($order);
      while ($row=mysql_fetch_array($result)){
        echo ("<tr><td>$row[Klantnummer]</td>");
        echo ("<tr><td>$row[Bedrijf]</td>");
        echo ("<td>$row[Contactpersoon]</td>");
        echo ("<td><a href=\"edit_form.php?Klantnummer=$row[Klantnummer]\">Edit</a></td></tr>");
      }
      ?>
      </table>
    </td>
   </tr>
</table>
</body>
</html>


Then we click edit to go to edit_form.php which shows this error



Notice: Undefined variable: Klantnummer in /home/schoolme/public_html/ret/edit_form.php on line 22



But the biggest problem here which in any of the scripts I was not able to fix is the fact that it only shows the blanc fields and not the existing data of that entry that I want to edit..

<?php
ini_set('display_errors',1); // 1 == aan , 0 == uit
error_reporting(E_ALL | E_STRICT);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Form Edit Data</title>
</head>

<body>
<table border=1>
<tr>
<td align=center>Form Edit Employees Data</td>
</tr>
<tr>
<td>
<table>
<?
include "db_config.php";//database connection
$order = "SELECT * FROM klanten where Klantnummer='$Klantnummer'";
$result = mysql_query($order);
$row = mysql_fetch_array($result);
?>
<form method="post" action="edit_data.php">
<tr>
<td>Klantnummer</td>
<td>
<input type="text" name="Klantnummer" size="40"
value="<? echo "$row[Klantnummer]"?>">
</td>
</tr>
<tr>
<td>Bedrijf</td>
<td>
<input type="text" name="Bedrijf" size="40"
value="<? echo "$row[Bedrijf]"?>">
</td>
</tr>
<tr>
<td>Contactpersoon</td>
<td>
<input type="text" name="Contactpersoon" size="40"
value="<? echo "$row[Contactpersoon]"?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>
</body>
</html>
If I click Edit there to save the new data it goes to edit data which shows loads of error



Notice: Undefined variable: Klantnummer in /home/schoolme/public_html/ret/edit_data.php on line 8

Notice: Undefined variable: Bedrijf in /home/schoolme/public_html/ret/edit_data.php on line 9

Notice: Undefined variable: Contactpersoon in /home/schoolme/public_html/ret/edit_data.php on line 11

Notice: Undefined variable: Klantnummer in /home/schoolme/public_html/ret/edit_data.php on line 11

Warning: Cannot modify header information - headers already sent by (output started at /home/schoolme/public_html/ret/edit_data.php: in /home/schoolme/public_html/ret/edit_data.php on line 13

Code: Select all
<?
ini_set('display_errors',1); // 1 == aan , 0 == uit
error_reporting(E_ALL | E_STRICT);
//edit_data.php
include "db_config.php";
$order = "UPDATE klanten
          SET Klantnummer='$Klantnummer',
              Bedrijf='$Bedrijf',
              Contactpersoon='$Contactpersoon'
          WHERE
          Klantnummer='$Klantnummer'";
mysql_query($order);
header("location:edit.php");
?>
Please help, if someone can tell me what to fix I might be able to learn from that..



Much appriciated!
arjanvrx
New php-forum User
New php-forum User
 
Posts: 1
Joined: Fri Sep 20, 2013 11:22 am

Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.