arjanvr Posted September 20, 2013 Share Posted September 20, 2013 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. <!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> </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 12Warning: 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 <?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 8Notice: Undefined variable: Bedrijf in /home/schoolme/public_html/ret/edit_data.php on line 9Notice: Undefined variable: Contactpersoon in /home/schoolme/public_html/ret/edit_data.php on line 11Notice: Undefined variable: Klantnummer in /home/schoolme/public_html/ret/edit_data.php on line 11Warning: 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 <? 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! Link to comment https://forums.phpfreaks.com/topic/282310-add-edit-delete-script-problems/ Share on other sites More sharing options...
Barand Posted September 20, 2013 Share Posted September 20, 2013 If you get an "undefined variable" message it means what it says. You are using a variable that has not been given a value previously in the script. Link to comment https://forums.phpfreaks.com/topic/282310-add-edit-delete-script-problems/#findComment-1450479 Share on other sites More sharing options...
cyberRobot Posted September 20, 2013 Share Posted September 20, 2013 Did you try using the suggestions made here: http://forums.phpfreaks.com/topic/282282-add-edit-delete-script-problems/ Link to comment https://forums.phpfreaks.com/topic/282310-add-edit-delete-script-problems/#findComment-1450480 Share on other sites More sharing options...
arjanvr Posted September 20, 2013 Author Share Posted September 20, 2013 This one has different issues i think but i did not quite understand the suggestions. In the proces of learning but i need this working asap Link to comment https://forums.phpfreaks.com/topic/282310-add-edit-delete-script-problems/#findComment-1450495 Share on other sites More sharing options...
ignace Posted September 22, 2013 Share Posted September 22, 2013 Duplicate: http://forums.phpfreaks.com/topic/282282-add-edit-delete-script-problems/?do=findComment&comment=1450234 Link to comment https://forums.phpfreaks.com/topic/282310-add-edit-delete-script-problems/#findComment-1450713 Share on other sites More sharing options...
Recommended Posts