Basically I am not getting any errors when I press update or add. Can anyone help me out? I want it so when I press add it adds that data to the database, and when I press update it updates the database with that value.
<html>
<head>
<title>Subcontractors Data</title>
</head>
<body>
Logout
Homepage
<?php
//make connection
$con = mysqli_connect("localhost","root","");
if(!$con){
die("Can not connect " . mysqli_error());
}
//select db
mysqli_select_db($con , 'subcontractor');
$sql="SELECT * FROM subcontractors";
if(isset($_POST['update'])){
$UpdateQuery = "UPDATE subcontractors SET ID='$_POST[ID]', Name='$_POST[Name]', Surname='$_POST[Surname]', FPA='$_POST[FPA]', Performance='$_POST[Performance]' WHERE ID='$_POST[hidden]'";
mysqli_query($con, $UpdateQuery);
};
if(isset($_POST['add'])){
$AddQuery = "INSERT INTO subcontractors (ID, Name, Surname, FPA, Performance) VALUES ('$_POST[aID]','$_POST[aName]','$_POST[aSurname]','$_POST[aFPA]','$_POST[aPerformance]')";
mysqli_query($con, $AddQuery);
};
$my_Data=mysqli_query($con,$sql);
echo "<table border=1>";
echo"<tr>";
echo"<th>ID</th>";
echo"<th>Name</th>";
echo"<th>Surname</th>";
echo"<th>FPA</th>";
echo "<th>Performance</th>";
echo "</tr>";
while($record=mysqli_fetch_assoc($my_Data)){
echo "<form action=editsub.php method=post>";
echo "<tr>";
echo "<td>" . "<input type=text name='ID' value=".$record['ID'] ." </td>";
echo "<td>" . "<input type=text name='Name' value=".$record['Name'] . " </td>";
echo "<td>" . "<input type=text name='Surname' value=".$record['Surname'] . " </td>";
echo "<td>" . "<input type=text name='FPA' value=".$record['FPA'] . "% </td>";
echo "<td>" . "<input type=text name='Performance' value=".$record['Performance'] . "% </td>";
echo "<input type=hidden name='hidden' value=" . $record['ID'] . ">";
echo "<input type=submit name='update' value='update'>";
echo "</tr>";
echo "</form>";
}
echo "<form action=editsub.php mehtod=post>";
echo "<tr>";
echo "<td><input type=text name='aID'></td>";
echo "<td><input type=text name='aName'></td>";
echo "<td><input type=text name='aSurname'></td>";
echo "<td><input type=text name='aFPA'></td>";
echo "<td><input type=text name='aPerformance'></td>";
echo "<td>" . "<input type=submit name='add' value='add'" . " </td>";
echo "</form>";
echo "</table>";
mysqli_close($con);
?>
</body>
</html>
This way you can check error.
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
Related
I decided to make my database with an active hyperlink so when I find a record I click on an email address and and email is opened. BUT I have a problem with update, When I want to make a correction to the entry and when I press update the email disappears and I get:
Notice: Undefined index: Mail in /Applications/XAMPP/xamppfiles/htdocs/robocze/mydata_dodaj_test_1.php on line 36
I can add records but I can't update...
Can You please help me, thank You
the code:
<?php
session_start();
if(!isset($_SESSION["sess_user"])){
header("location:login.php");
} else {
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Baza Klientów</title>
</head>
<body>
<h3>Welcome, <?=$_SESSION['sess_user'];?>! Logout </h3>
<input type="button" onclick="location.href='mydata_dodaj_test_1.php';" value="Powrót do wyszukiwania" />
<input type="button" onclick="location.href='index.php';" value="MENU powrót" />
<h2><b><center>Wyszukiwanie Klientów ITalents</center></b></h2>
<?php
}
?>
<?php
$con = mysql_connect("","","","");
if (!$con){
die("Błąd połączenia: " . mysql_error());
}
mysql_select_db("baza",$con);
if(isset($_POST['update'])) {
$UpdateQuery = "UPDATE Klienci SET id='$_POST[id]', Firma='$_POST[Firma]', Mail='$_POST[Mail]', Data='$_POST[Data]', Konsultant='$_POST[Konsultant]' WHERE id='$_POST[hidden]'";
mysql_query($UpdateQuery,$con);
};
if(isset($_POST['add'])) {
$AddQuery = "INSERT INTO Klienci (id, Firma, Mail, Data, Konsultant) VALUES ('$_POST[uid]','$_POST[uFirma]','$_POST[uMail]','$_POST[uData]','$_POST[uKonsultant]')"; // this is the 36 line
mysql_query($AddQuery,$con);
};
if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
$query = "SELECT * FROM Klienci WHERE CONCAT(Firma, Mail, Konsultant) LIKE '%".$valueToSearch."%'";
$search_result = filterTable($query);
}
else {
$query = "SELECT * FROM Klienci ORDER BY id ASC";
$search_result = filterTable($query);
}
function filterTable($query)
{
$con = mysql_connect("","","","");
if (!$con){
die("Błąd połączenia: " . mysql_error());
}
mysql_select_db("baza",$con);
$filter_Result = mysql_query($query, $con);
return $filter_Result;
};
echo "<form action=mydata_dodaj_test_1.php method=post>";
echo "<input type=text name=valueToSearch placeholder=wpisz>";
echo "<input type=submit name=search value=Szukaj>";
echo "<table align=center style=text-align:center border=5>
<tr>
<th>ID</th>
<th>Firma</th>
<th>Mail</th>
<th>Data</th>
<th>Konsultant</th>
</tr>";
while($row = mysql_fetch_array($search_result)) {
echo "<form action=mydata_dodaj_test_1.php method=post>";
echo "<tr>";
echo "<td>" . "<input type=int name=id value=" . $row['id'] . " </td>";
echo "<td>" . "<input type=varchar name=Firma value=" . $row['Firma'] . " </td>";
echo "<td>" . "<a href='mailto:{$row['Mail']}'>" . $row['Mail'] . " </td>";
echo "<td>" . "<input type=date name=Data value=" . $row['Data'] . " </td>";
echo "<td>" . "<input type=varchar name=Konsultant value=" . $row['Konsultant'] . " </td>";
echo "<td>" . "<input type=hidden name=hidden value=" . $row['id'] . " </td>";
echo "<td>" . "<input type=submit name=update value=update" . " </td>";
echo "</form>";
}
echo "<form action=mydata_dodaj_test_1.php method=post>";
echo "<tr>";
echo "<td><input type=text name=uid></td>";
echo "<td><input type=varchar name=uFirma></td>";
echo "<td><input type=text name=uMail></td>";
echo "<td><input type=text name=uData></td>";
echo "<td><input type=text name=uKonsultant></td>";
echo "<td>" . "<input type=submit name=add value=dodaj" . " </td>";
echo "</form>";
echo "</table>";
?>
<input type="button" onclick="location.href='mydata_dodaj_test_1.php';" value="Powrót do wyszukiwania" />
<input type="button" onclick="location.href='index.php';" value="MENU powrót" />
</body>
</html>
As error stated undefined index in your update statement
$UpdateQuery = "UPDATE Klienci SET id='$_POST[id]', Firma='$_POST[Firma]', Mail='$_POST[Mail]', Data='$_POST[Data]', Konsultant='$_POST[Konsultant]' WHERE id='$_POST[hidden]'";
you are accessing $_POST[Mail] which is no where in your form.
I'm trying to is have have table to display my database with an update, delete, and add functions.
My problem is when I view it. It doesn't show the full text in the "Description" column and also in "Developer". Also in the "SecondDirectory" column it shows </td instead of just blank if its blank.
<html>
<head>
</head>
<body>
<?php
$con = mysql_connect("$$$$","$$$$","$$$$");
if (!$con){
die("Can not connect: " . mysql_error());
}
mysql_select_db("mydb",$con);
if(isset($_POST['update'])){
$UpdateQuery = "UPDATE table SE ID='$_POST[topic]',Filename='$_POST[filename]', Description='$_POST[description]', TopDirectory='$_POST[topdirectory]', SecondDirectory='$_POST[seconddirectory]', Developer='$_POST[developer]', Date='$_POST[date]' WHERE ID='$_POST[hidden]'";
mysql_query($UpdateQuery, $con);
};
if(isset($_POST['delete'])){
$DeleteQuery = "DELETE FROM table WHERE ID='$_POST[hidden]'";
mysql_query($DeleteQuery, $con);
};
if(isset($_POST['add'])){
$AddQuery = "INSERT INTO table (ID,Filename,Description,TopDirectory,SecondDirectory,Developer,Date) VALUES ('$_POST[uid]','$_POST[ufilename]','$_POST[udescription]','$_POST[utopdirectory]','$_POST[useconddirectory]','$_POST[udeveloper]','$_POST[udate]')";
mysql_query($AddQuery, $con);
};
$sql = "SELECT * FROM table";
$myData = mysql_query($sql,$con);
echo "<table border=1>
<tr>
<th>ID</th>
<th>Filename</th>
<th>Description</th>
<th>TopDirectory</th>
<th>SecondDirectory</th>
<th>Developer</th>
<th>Date</th>
</tr>";
while($record = mysql_fetch_array($myData)){
echo "<form action=theworks.php method=post>";
echo "<tr>";
echo "<td>" . "<input type=text name=id value=" . $record['ID'] . " </td>";
echo "<td>" . "<input type=text name=filename value=" . $record['Filename'] . " </td>";
echo "<td>" . "<input type=text name=description value=" . $record['Description'] . " </td>";
echo "<td>" . "<input type=text name=topdirectory value=" . $record['TopDirectory'] . " </td>";
echo "<td>" . "<input type=text name=seconddirectory value=" . $record['SecondDirectory'] . " </td>";
echo "<td>" . "<input type=text name=developer value=" . $record['Developer'] . " </td>";
echo "<td>" . "<input type=text name=date value=" . $record['Date'] . " </td>";
echo "<td>" . "<input type=hidden name=hidden value=" . $record['ID'] . " </td>";
echo "<td>" . "<input type=submit name=update value=update" . " </td>";
echo "<td>" . "<input type=submit name=delete value=delete" . " </td>";
echo "</tr>";
echo "</form>";
}
echo "<form action=database.php method=post>";
echo "<tr>";
echo "<td><input type=text name=uid></td>";
echo "<td><input type=text name=ufilename></td>";
echo "<td><input type=text name=udescription><td>";
echo "<td><input type=text name=utopdirectory></td>";
echo "<td><input type=text name=useconddirectory></td>";
echo "<td><input type=text name=udeveloper><td>";
echo "<td><input type=text name=udate></td>";
echo "<td>" . "<input type=submit name=add value=add" . " </td>";
echo "</tr>";
echo "</form>";
echo "</table>";
mysql_close($con);
?>
</body>
</html>
So I figured it out.
echo "<td>" . "<input type=text name=description value=" . $record['Description'] . " </td>";
What I needed to put is a single quotation right after value= and two single quotations in " " so that it also counts the spaces. The code should have been...
echo "<td>" . "<input type=text name=description value='" . $record['Description'] . "'' </td>";
This question already has answers here:
Why would $_FILES be empty when uploading files to PHP?
(22 answers)
Closed 8 years ago.
I am trying to build a file uploader, with a youtube tutorial that doesn't cover files, and right now I am stuck on the name. Using $_Files returns nothing and I am unsure as to why. :/
I tried to echo it out, but nothing comes back.
Everything else seems to work though.
<html>
<head>
</head>
<body>
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
$con = mysql_connect("localhost","root","root");
if (!$con){
die("Can not connect: " . mysql_error());
}
mysql_select_db("example",$con);
if(isset($_POST['update'])){
$UpdateQuery = "UPDATE repo SET location='$_POST[location]', name='$_POST[name]', description='$_POST[description]' WHERE location='$_POST[hidden]'";
mysql_query($UpdateQuery, $con);
};
if(isset($_POST['delete'])){
$DeleteQuery = "DELETE FROM repo WHERE location='$_POST[hidden]'";
mysql_query($DeleteQuery, $con);
};
if(isset($_POST['add'])){
$AddQuery = "INSERT INTO repo (name, id, image, location, partners, description, date) VALUES ('$image_name', '','$_POST[uimage]', '$_POST[ulocation]', '$_POST[upartners]', '$_POST[udescription]', NOW())";
mysql_query($AddQuery, $con);
};
$sql = "SELECT * FROM repo";
$myData = mysql_query($sql,$con);
echo "<table border=1>
<tr>
<th>Image</th>
<th>Name</th>
<th>Location</th>
<th>Partners</th>
<th>Description</th>
<th>Date</th>
</tr>";
while($record = mysql_fetch_array($myData)){
?>
<form action="mydata5.php"
method="post" enctype="multipart/form-data">
<?php
echo "<tr>";
echo "<td>" . "<img src=Assets/Images/" . $record['name'] . " </td>";
echo "<td>" . "<input type=text name=topic value=" . $record['name'] . " </td>";
echo "<td>" . "<input type=text name=name value=" . $record['location'] . " </td>";
echo "<td>" . "<input type=text name=name value=" . $record['partners'] . " </td>";
echo "<td>" . "<input type=text name=description value=" . $record['description'] . " </td>";
echo "<td>" . "<input type=text name=description value=" . $record['date'] . " </td>";
echo "<td>" . "<input type=hidden name=hidden value=" . $record['location'] . " </td>";
echo "<td>" . "<input type=submit name=update value=update" . " </td>";
echo "<td>" . "<input type=submit name=delete value=delete" . " </td>";
echo "</tr>";
echo "</form>";
}
echo "<form action=mydata5.php method=post>";
echo "<tr>";
// echo "<td><input type=file name=uimage></td>";
?>
<td><input type="file" name="uimage" id="uimage"></td>
<?php
$file = $_FILES['uimage']['tmp_name'];
$image_name = mysql_real_escape_string($_FILES['uimage']['name']);
echo $_FILES['uimage']['error'];
echo "<td><input type=hidden name=uname></td>";
echo "<td><input type=text name=ulocation></td>";
echo "<td><input type=text name=upartners></td>";
echo "<td><input type=text name=udescription></td>";
echo "<td>" . "<input type=submit name=add value=add" . " </td>";
echo "</form>";
echo "</table>";
mysql_close($con);
?>
</body>
</html>
You need to add enctype="multipart/form-data" in the form tag.
For file type fields you need to add enctype attribute in your form so that uploaded files can be access using $_FILES
Update form starting tag with below
<form action="mydata5.php"
method="post" enctype="multipart/form-data">
Check your Insert Query.You are using $_POST for image name. That is wrong.
I'm trying to create a dropdown list with the values being populated from the database. In the following code, I have created a table for viewing the student details and created delete and add buttons to add and delete the information.
The problem is while adding the details for class id, I used a dropdown value from another table to be populate the values, but I was not able to do it.
<html>
<head><title>viewstudent</title>
<?php
$host = "localhost";
$user = "root";
$pass = "";
$dbname = "my_attendance";
$prefix = "";
$con = mysql_connect($host, $user, $pass)
or die ("not connected to db");
mysql_select_db($dbname, $con)
or die("database not selected");
if (isset($_POST['delete'])){
$deleteqry = "DELETE from student_master WHERE ID='$_POST[hidden]'" ;
mysql_query($deleteqry, $con);
};
if (isset($_POST['add'])){
$clid=mysql_real_escape_string($_POST['classid']);
$sid=mysql_real_escape_string($_POST['studentid']);
$fn=mysql_real_escape_string($_POST['fname']);
$ln=mysql_real_escape_string($_POST['lname']);
$dob=mysql_real_escape_string($_POST['dob']);
$em=mysql_real_escape_string($_POST['email']);
$ph=mysql_real_escape_string($_POST['phone']);
$loc=mysql_real_escape_string($_POST['locationid']);
$emer=mysql_real_escape_string($_POST['emergency']);
$addquery = ("INSERT INTO student_master(classid, studentid, fname, lname, dob, phone, email, locationid, emergency)
VALUES('$clid', '$sid', '$fn', '$ln', '$dob', '$ph', '$em', '$loc', '$emer')");
mysql_query($addquery, $con);
};
$query=("SELECT * FROM student_master");
$result = mysql_query($query);
?>
</head>
<body>
<table align="center" width="500" border="1" cellspacing="1" cellpadding="1">
<tr>
<th>Id</th><th>classid</th><th>studentid</th><th>fname</th><th>lname</th><th>dob</th><th>phone</th><th>email</th><th>locationid</th><th>emergency</th>
</tr>
<?php
while( $row = mysql_fetch_array($result,MYSQLI_ASSOC))
{
echo "<form action=viewstudentinfo.php method=POST >";
echo "<tr align='center'>";
echo "<td>" . "<input type=text name=ids value=" .$row['id']." </td>";
echo "<td>" . "<input type=text name=classid value=" .$row['classid']." </td>";
echo "<td>" . "<input type=number name=studentid value=" .$row['studentid']." </td>";
echo "<td>" . "<input type=text name=fname value=" .$row['fname']." </td>";
echo "<td>" . "<input type=text name=lname value=" .$row['lname']." </td>";
echo "<td>" . "<input type=text name=dob value=" .$row['dob']." </td>";
echo "<td>" . "<input type=text name=phone value=" .$row['phone']." </td>";
echo "<td>" . "<input type=text name=email value=" .$row['email']." </td>";
echo "<td>" . "<input type=text name=locationid value=" .$row['locationid']." </td>";
echo "<td>" . "<input type=text name=emergency value=" .$row['emergency']." </td>";
echo "<td>" . "<input type=hidden name=hidden value=" .$row['id']." </td>";
echo "<td>" . "<input type=submit name=delete value=Delete" ." </td>";
echo "</tr>";
echo "</form>";
}
echo "<form action=viewstudentinfo.php method= post>";
echo "<tr>";
echo "<td><input type=text name=id></td>";
echo "<td><select type=text name=classid></td>";?>
// populating classid values from another table....
<?php
$query = 'SELECT classid FROM class_master';
$result1 = mysql_query($query, $con) or die(mysql_error($con));
while ($row = mysql_fetch_array($result1))
{
echo '<option value="' . $row["classid"] . '"> ' . $row["classid"] . '</option>';
}
echo "</select>";
?>
<?php
echo "<td><input type=number name=studentid></td>";
echo "<td><input type=text name=fname></td>";
echo "<td><input type=text name=lname></td>";
echo "<td><input type=date name=dob></td>";
echo "<td><input type=number name=phone></td>";
echo "<td><input type=email name=email></td>";
echo "<td><input type=number name=locationid></td>";
echo "<td><input type=number name=emergency></td>";
echo "<td>" . "<input type=submit name=add value=ADD" ." </td>";
echo "</tr>";
echo "</form>";
echo "</table>";
mysql_close($con);
?>
You are closing the <td> inside the select:
Replace
echo "<td><select type=text name=classid></td>";?>
With
echo "<td><select type=text name=classid>";?>
And close the '</td>' after the '</select>'
Find out <td><select type=text name=classid></td> in your code and remove the ending tag </td> from it. After all the <option> ... </option> close the </td>
I am having a problem displaying content on a table from mysql table in the database to a form in PHP. My problem is that only the first word show on the address field for example.
Please look at my page on: http://www3.londonmet.ac.uk:8008/~iia0014/employeeManager.php
And also the cells are not aligned with the title.
Can anyone help me to solve this?
On my css I have:
table {
table-layout:fixed;
width:180%;
overflow:hidden;
border:1px ;
word-wrap:nowrap;
text-align:left;
}
But even if removing the CSS, just the first word appear.
PHP CODE:
<?php
// Connect to server and select databse.
$con = mysql_connect("$host","$username","$password");
if (!$con){
die("Can not connect: " . mysql_error());
}
mysql_select_db("$db_name",$con);
if(isset($_POST['update'])){
$UpdateQuery = "UPDATE employees SET
Name='$_POST[name]',
DOB='$_POST[dob]',
Tel='$_POST[tel]',
Address='$_POST[address]',
Department='$_POST[department]',
PayRate='$_POST[payrate]',
Skills='$_POST[skills]',
Gender='$_POST[gender]'
WHERE EmpNo='$_POST[hidden]'";
mysql_query($UpdateQuery, $con);
};
if(isset($_POST['delete'])){
$DeleteQuery = "DELETE FROM employees WHERE EmpNo='$_POST[hidden]'";
mysql_query($DeleteQuery, $con);
};
if(isset($_POST['add'])){
$AddQuery = "INSERT INTO employees (EmpNo, Name, DOB, Tel, Address, Department, PayRate, Skills, Gender) VALUES ('$_POST[uempNo]','$_POST
[uname]','$_POST[udob]', '$_POST[utel]','$_POST[uaddress]','$_POST[udepartment]', '$_POST[upayrate]','$_POST[uskills]','$_POST[ugender]')";
mysql_query($AddQuery, $con);
};
$sql = "SELECT * FROM employees";
$myData = mysql_query($sql,$con);
?>
<table border="1" width="10%">
<?php
echo "<tr>
<th>Number</th>
<th >Employee Name</th>
<th>DOB</th>
<th>Telephone</th>
<th>Address</th>
<th>Department</th>
<th>Pay Rate</th>
<th>Skills</th>
<th>Gender</th>
</tr>";
while($record = mysql_fetch_array($myData)){
echo "<form action=employeeManager.php method=post>";
echo "<tr>";
echo "<td>" . "<input type=hidden name=hidden value=" . $record['EmpNo'] . " </td>";
echo "<td>" . "<input type=text name=name value=" . $record['Name'] . " </td>";
echo "<td>" . "<input type=text name=dob value=" . $record['DOB'] . " </td>";
echo "<td>" . "<input type=text name=tel value=" . $record['Tel'] . " </td>";
echo "<td>" . "<input type=text name=address value=" . $record['Address'] . " </td>";
echo "<td>" . "<input type=text name=department value=" . $record['Department'] . " </td>";
echo "<td>" . "<input type=text name=payrate value=" . $record['PayRate'] . " </td>";
echo "<td>" . "<input type=text name=skills value=" . $record['Skills'] . " </td>";
echo "<td>" . "<input type=text name=gender value=" . $record['Gender'] . " </td>";
echo "<td>" . "<input type=submit name=update value=update" . " </td>";
echo "<td>" . "<input type=submit name=delete value=delete" . " </td>";
echo "</tr>";
echo "</form>";
}
echo "<form action=employeeManager.php method=post>";
echo "<tr>";
echo "<td><input type=text name=uempNo></td>";
echo "<td><input type=text name=uname></td>";
echo "<td><input type=text name=udob></td>";
echo "<td><input type=text name=utel></td>";
echo "<td><input type=text name=uaddress></td>";
echo "<td><input type=text name=udepartment></td>";
echo "<td><input type=text name=upayrate></td>";
echo "<td><input type=text name=uskills></td>";
echo "<td><input type=text name=ugender></td>";
echo "<td>" . "<input type=submit name=add value=add" . " </td></tr>";
echo "</form>";
echo "</table>";
mysql_close($con);
?>
In the below quotes you were missing quotes and the tags were not closed proprely!
while($record = mysql_fetch_array($myData)){
echo "<form action='employeeManager.php' method='post'>";
echo "<tr>";
echo "<td><input type='hidden' name=hidden value='" . $record['EmpNo'] . "'> </td>";
echo "<td><input type='text' name='name' value='" . $record['Name'] . "'> </td>";
echo "<td><input type='text' name='dob' value='" . $record['DOB'] . "'> </td>";
echo "<td><input type='text' name='tel' value='" . $record['Tel'] . "'> </td>";
echo "<td><input type='text' name='address' value='" . $record['Address'] . "'> </td>";
echo "<td><input type='text' name='department' value='" . $record['Department'] . " </td>";
echo "<td><input type='text' name='payrate' value='" . $record['PayRate'] . "'> </td>";
echo "<td><input type='text' name='skills' value='" . $record['Skills'] . "'> </td>";
echo "<td><input type='text' name='gender' value='" . $record['Gender'] . "'> </td>";
echo "<td><input type='submit' name='update' value='update'> </td>";
echo "<td><input type='submit' name='delete' value='delete'> </td>";
echo "</tr>";
echo "</form>";
}
For better understanding of your mistake, notice your code:
echo "<td><input type=text></td>";
It should be like that:
echo "<td><input type='text'></td>";
It works, its just that you don't close the tag, which results in:
<input type=text name=address value=one two thre
The browser reads it as value=one and "two" and "three" like separate arguments.
What you need is a quote like this:
<input type=text name=address value="one two three"/>