jerr0 Posted October 13, 2009 Share Posted October 13, 2009 Well i am quite new with PHP and for school we have to make a PHP script which reffers to a Database, Well, more explicit, we have this form showing all "employees" last name etc. made it week before, and we had to add a new bar to also upload pictures and show them. So i made this script but it won't work. And maybe it's just me being stupid.. But please help me EDIT: it's obvious that pictures reffers to the picture iwant to upload and show. 2nd EDIT: Found out i missed a " , " Well now the problem is that when i run it and try to upload a picture i won't see anything <?php function displayAllEmployees() { $sql = "SELECT * FROM `Employees` ORDER BY `LastName`"; $result = mysql_query($sql); echo"<h1>Werknemers</h1>"; echo"<br/>"; echo"<input type=\"button\" onclick=\"document.location.href='?action=addemployee';\" value=\"Werknemer toevoegen\" />"; echo"<br/>"; echo"<br/>"; echo"<table>"; echo" <tr>"; echo" <th>Employee ID</td>"; echo" <th>Last Name</td>"; echo" <th>Phone Number</td>"; echo" <th>Foto</td>"; echo" <th>Actie</td>"; echo" </tr>"; while($row = mysql_fetch_assoc($result)) { $row = escapeArray($row); echo" <tr>"; echo" <td>".$row['EmployeeID']."</td>"; echo" <td>".$row['LastName']."</td>"; echo" <td>".$row['PhoneNumber']."</td>"; echo" <td>".$row['Picture']."</td>"; echo" <td>"; echo" <a href=\"index.php?action=editemployee&id=".$row['EmployeeID']."\">Bewerken</a>"; echo" |"; echo" <a href=\"javascript:confirmAction('Zeker weten?', 'index.php?action=deleteemployee&id=".$row['EmployeeID']."');\">Verwijderen</a>"; echo" </td>"; echo" </tr>"; } echo"</table>"; } function displayAddEmployee() { echo"<h1>Werknemer bewerken</h1>"; echo" <form method=\"post\" action=\"index.php?action=insertemployee\">"; echo" <table>"; echo" <tr>"; echo" <td>werknemernummer:</td>"; echo" <td><input type=\"text\" name=\"EmployeeID\" /></td>"; echo" </tr>"; echo" <tr>"; echo" <td>achternaam:</td>"; echo" <td><input type=\"text\" name=\"LastName\" /></td>"; echo" </tr>"; echo" <tr>"; echo" <td>telefoonnummer:</td>"; echo" <td><input type=\"text\" name=\"PhoneNumber\" /></td>"; echo" </tr>"; echo" <tr>"; echo" <td>Foto:</td>"; echo" <td><input type=\"file\" name=\"Picture\" /></td>"; echo" </tr>"; echo" <td></td>"; echo" <td><input type=\"submit\" value=\"Opslaan\" /></td>"; echo" </tr>"; echo" </table>"; echo" </form>"; } function displayEditEmployees() { $sql = sprintf( "SELECT * FROM `Employees` WHERE `EmployeeID` = %d", mysql_escape_string($_GET['id']) ); $result = mysql_query($sql); if($row = mysql_fetch_assoc($result)) { $row = escapeArray($row); echo"<h1>Werknemer bewerken</h1>"; echo" <form method=\"post\" action=\"index.php?action=updateemployee\">"; echo" <table>"; echo" <tr>"; echo" <td>Titel:</td>"; echo" <td><input type=\"text\" name=\"EmployeeID\" value=\"".$row['EmployeeID']."\" /></td>"; echo" </tr>"; echo" <tr>"; echo" <td>Achternaam:</td>"; echo" <td><input type=\"text\" name=\"LastName\" value=\"".$row['LastName']."\" /></td>"; echo" </tr>"; echo" <tr>"; echo" <td>Telefoon Nummer:</td>"; echo" <td><input type=\"text\" name=\"PhoneNumber\" value=\"".$row['PhoneNumber']."\" /></td>"; echo" </tr>"; echo" <tr>"; echo" <td>Foto:</td>"; echo" <td><input type=\"text\" name=\"Picture\" value=\"".$row['Picture']."\" /></td>"; echo" </tr>"; echo" <tr>"; echo" <td></td>"; echo" <td><input type=\"submit\" value=\"Opslaan\" /></td>"; echo" </tr>"; echo" </table>"; echo" <input type=\"hidden\" name=\"EmployeeID\" value=\"".$row['EmployeeID']."\" />"; echo" </form>"; } else { die("Geen gegevens gevonden"); } } function addEmployee() { $sql = sprintf("INSERT INTO `Employees` (`EmployeeID`, `LastName`, `PhoneNumber`) VALUES ('%s', '%f', '%f', '%f')", mysql_escape_string($_POST['EmployeeID']), mysql_escape_string($_POST['LastName']), mysql_escape_string($_POST['PhoneNumber']), mysql_escape_string($_POST['Picture']) ); mysql_query($sql); header("location: index.php?action=employees"); exit(); } function updateEmployees() { $sql = sprintf("UPDATE `Employees` SET `EmployeeID` = '%s', `LastName` = '%s', `PhoneNumber` = '%s' `Picture` = '%s' WHERE `EmployeeID` = %d", mysql_escape_string($_POST['LastName']), mysql_escape_string($_POST['PhoneNumber']), mysql_escape_string($_POST['EmployeeID']) mysql_escape_string($_POST['Picture']) ); mysql_query($sql); header("location: index.php?action=employees"); exit(); } function deleteEmployees() { $sql = sprintf("DELETE FROM `Employees` WHERE `EmployeeID` = %d", mysql_escape_string($_GET['id'])); mysql_query($sql); header("location: index.php?action=employees"); exit(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/177566-php-code-reffering-to-database-doing-something-wrong-pls-help/ Share on other sites More sharing options...
taquitosensei Posted October 13, 2009 Share Posted October 13, 2009 try using [ php ]code[ /php ] tags (without the spaces ) it makes it much easier to read and people will be more likely to respond. Quote Link to comment https://forums.phpfreaks.com/topic/177566-php-code-reffering-to-database-doing-something-wrong-pls-help/#findComment-936277 Share on other sites More sharing options...
jerr0 Posted October 13, 2009 Author Share Posted October 13, 2009 Somehow i can't edit the post :S Ok so the problem now is: it doesn't add anything to the database and it won't show a thing. <?php function displayAllEmployees() { $sql = "SELECT * FROM `Employees` ORDER BY `LastName`"; $result = mysql_query($sql); echo"<h1>Werknemers</h1>"; echo"<br/>"; echo"<input type=\"button\" onclick=\"document.location.href='?action=addemployee';\" value=\"Werknemer toevoegen\" />"; echo"<br/>"; echo"<br/>"; echo"<table>"; echo" <tr>"; echo" <th>Employee ID</td>"; echo" <th>Last Name</td>"; echo" <th>Phone Number</td>"; echo" <th>Foto</td>"; echo" <th>Actie</td>"; echo" </tr>"; while($row = mysql_fetch_assoc($result)) { $row = escapeArray($row); echo" <tr>"; echo" <td>".$row['EmployeeID']."</td>"; echo" <td>".$row['LastName']."</td>"; echo" <td>".$row['PhoneNumber']."</td>"; echo" <td>".$row['Picture']."</td>"; echo" <td>"; echo" <a href=\"index.php?action=editemployee&id=".$row['EmployeeID']."\">Bewerken</a>"; echo" |"; echo" <a href=\"javascript:confirmAction('Zeker weten?', 'index.php?action=deleteemployee&id=".$row['EmployeeID']."');\">Verwijderen</a>"; echo" </td>"; echo" </tr>"; } echo"</table>"; } function displayAddEmployee() { echo"<h1>Werknemer Toevoegen</h1>"; echo" <form method=\"post\" action=\"index.php?action=insertemployee\">"; echo" <table>"; echo" <tr>"; echo" <td>werknemernummer:</td>"; echo" <td><input type=\"text\" name=\"EmployeeID\" /></td>"; echo" </tr>"; echo" <tr>"; echo" <td>achternaam:</td>"; echo" <td><input type=\"text\" name=\"LastName\" /></td>"; echo" </tr>"; echo" <tr>"; echo" <td>telefoonnummer:</td>"; echo" <td><input type=\"text\" name=\"PhoneNumber\" /></td>"; echo" </tr>"; echo" <tr>"; echo" <td>Foto:</td>"; echo" <td><input type=\"file\" name=\"Picture\" /></td>"; echo" </tr>"; echo" <td></td>"; echo" <td><input type=\"submit\" value=\"Opslaan\" /></td>"; echo" </tr>"; echo" </table>"; echo" </form>"; } function displayEditEmployees() { $sql = sprintf( "SELECT * FROM `Employees` WHERE `EmployeeID` = %d", mysql_escape_string($_GET['id']) ); $result = mysql_query($sql); if($row = mysql_fetch_assoc($result)) { $row = escapeArray($row); echo"<h1>Werknemer bewerken</h1>"; echo" <form method=\"post\" action=\"index.php?action=updateemployee\">"; echo" <table>"; echo" <tr>"; echo" <td>Titel:</td>"; echo" <td><input type=\"text\" name=\"EmployeeID\" value=\"".$row['EmployeeID']."\" /></td>"; echo" </tr>"; echo" <tr>"; echo" <td>Achternaam:</td>"; echo" <td><input type=\"text\" name=\"LastName\" value=\"".$row['LastName']."\" /></td>"; echo" </tr>"; echo" <tr>"; echo" <td>Telefoon Nummer:</td>"; echo" <td><input type=\"text\" name=\"PhoneNumber\" value=\"".$row['PhoneNumber']."\" /></td>"; echo" </tr>"; echo" <tr>"; echo" <td>Foto:</td>"; echo" <td><input type=\"text\" name=\"Picture\" value=\"".$row['Picture']."\" /></td>"; echo" </tr>"; echo" <tr>"; echo" <td></td>"; echo" <td><input type=\"submit\" value=\"Opslaan\" /></td>"; echo" </tr>"; echo" </table>"; echo" <input type=\"hidden\" name=\"EmployeeID\" value=\"".$row['EmployeeID']."\" />"; echo" </form>"; } else { die("Geen gegevens gevonden"); } } function addEmployee() { $sql = sprintf("INSERT INTO `Employees` (`EmployeeID`, `LastName`, `PhoneNumber`) VALUES ('%s', '%f', '%f', '%f')", mysql_escape_string($_POST['EmployeeID']), mysql_escape_string($_POST['LastName']), mysql_escape_string($_POST['PhoneNumber']), mysql_escape_string($_POST['Picture']) ); mysql_query($sql); header("location: index.php?action=employees"); exit(); } function updateEmployees() { $sql = sprintf("UPDATE `Employees` SET `EmployeeID` = '%s', `LastName` = '%s', `PhoneNumber` = '%s' `Picture` = '%s' WHERE `EmployeeID` = %d", mysql_escape_string($_POST['LastName']), mysql_escape_string($_POST['PhoneNumber']), mysql_escape_string($_POST['EmployeeID']), mysql_escape_string($_POST['Picture']) ); mysql_query($sql); header("location: index.php?action=employees"); exit(); } function deleteEmployees() { $sql = sprintf("DELETE FROM `Employees` WHERE `EmployeeID` = %d", mysql_escape_string($_GET['id'])); mysql_query($sql); header("location: index.php?action=employees"); exit(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/177566-php-code-reffering-to-database-doing-something-wrong-pls-help/#findComment-936290 Share on other sites More sharing options...
taquitosensei Posted October 13, 2009 Share Posted October 13, 2009 I see your functions. Where's the code that calls the functions? Quote Link to comment https://forums.phpfreaks.com/topic/177566-php-code-reffering-to-database-doing-something-wrong-pls-help/#findComment-936293 Share on other sites More sharing options...
jerr0 Posted October 13, 2009 Author Share Posted October 13, 2009 you mean this one? Srry if i'm wrong but we get all explained in Dutch even though it ain't that different <?php error_reporting(E_ALL); include("conf/config.conf.php"); // De configuratie van het systeem include("inc/database.inc.php"); // Funties om verbinding met de database te maken include("inc/general.inc.php"); // Algemene functies zoals drawHeader en drawFooter include("inc/jobs.inc.php"); // Algemene functies zoals drawHeader en drawFooter include("inc/departments.inc.php"); include("inc/locations.inc.php"); include("inc/employees.inc.php"); databaseConnect(); // verbinding met de database maken // Hieronder alle functies die geen output genereren naar de browser // Dit is nodig om de 'warning headers already sent' fout te voorkomen switch(getCurrentAction()) { case "insertjob": addJob(); break; case "updatejob": updateJob(); break; case "deletejob": deleteJob(); break; } switch(getCurrentAction()) { case "insertdepartment": addDepartment(); break; case "updatedepartment": updateDepartment(); break; case "deletedepartment": deleteDepartment(); break; } switch(getCurrentAction()) { case "insertlocation": addLocation(); break; case "updatelocation": updateLocation(); break; case "deletelocation": deleteLocation(); break; } switch(getCurrentAction()) { case "insertEmployee": addEmployee(); break; case "updateEmployee": updateEmployee(); break; case "deleteEmployee": deleteEmployee(); break; } displayHeader(); // de HTML header tonen displayNavigation(); // de menubalk tonen // Hieronder alle functies die wel output genereren naar de browser switch(getCurrentAction()) { case "jobs": displayAllJobs(); break; case "addjob": displayAddJob(); break; case "editjob": displayEditJob(); break; } switch(getCurrentAction()) { case "departments": displayAllDepartments(); break; case "adddepartment": displayAddDepartments(); break; case "editdepartment": displayEditDepartments(); break; } switch(getCurrentAction()) { case "locations": displayAllLocations(); break; case "addlocation": displayAddLocation(); break; case "editlocation": displayEditLocations(); break; } switch(getCurrentAction()) { case "employees": displayAllEmployees(); break; case "addemployee": displayAddEmployee(); break; case "editemployee": displayEditEmployees(); break; } displayFooter(); // de HTML footer tonen databaseDisconnect(); // verbinding met de database verbreken ?> Quote Link to comment https://forums.phpfreaks.com/topic/177566-php-code-reffering-to-database-doing-something-wrong-pls-help/#findComment-936295 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.