PHP Code reffering to database, doing something wrong.. pls help
Posted on
16th Feb 2014 07:03 pm by
admin
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();
}
?>
No comments posted yet
Your Answer:
Login to answer
221
11
Other forums
Lack of simpleXML Documentation
What is up with this.
Look at: http://www.php.net/manual/en/function.simplexml-load-file.php<
update 2 columns by doing inner 2-column query
Hi,
is something like this possible?
update contract_all set col1,col2 =
(
Ajax Issues - Update Panel / Timer. Intellisense doesn't know about them
Type 'System.Web.UI.ScriptManager' does not have a public property named 'UpdatePanel'.
That is wha
help me, how to find text on an external html site using PHP
Would anyone know how to search an external html file for a work or phrase ?
I was thinking s
Sending a hyperlink through mail
HI all,
I am sending a mail to outlook mailbox of a user using FM SO_NEW_DOCUMENT_ATT_S
Access database inside of a validation class
Hello,
For quite some time, I have been using functions to validate form input and access the
How to separate records and ORDER BY
Let say i have 100 records and displayed in one page, then i want to get the records from 50-100 and
Simple MySQL script is not working
Hey guys,
Just familiarizing myself with PHP and MySQL. I am following along in the O'Reilly
Extracting Long text from message class with parameters
Hi,
I would like to extract the long text from a message class. However, the long text ha
How to search for several parameters from objects in a database?
I have a database with lots of information about objects.
Now I would like to search for 4 or 5 p