error mysql query in a php code [duplicate] - php

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 8 years ago.
This is a php code i wrote to edit a line in an array "article" every line is compsed by:
(Colonne: Type)
(ref : int(11),
nom :varchar(25),
cat : varchar(25),
prix : int(11),
fabricant : varchar(35),
photo :varchar(35))
so i make this php code:
<?php
require_once("connection.php");
$ref=$_POST['ref'];
$req="Select * from article where ('ref =". $ref."')";
$rs= mysql_query($req) or die(mysql_error());
$AR=mysql_fetch_assoc($rs);
?>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<form method="POST" action="modifierArticle.php" enctype="multipart/form-data">
<table>
<tr>
<td>Référence:</td>
<td><input type="text" name="ref" value="<?php echo ($AR['ref']) ?>" readonly="true"></td>
</tr>
<tr>
<td>Nom:</td>
<td><input type="text" name="nom" value="<?php echo ($AR['nom']) ?>"></td>
</tr>
<tr>
<td> Catégorie: </td>
<td><input type="text" name="cat" value="<?php echo ($AR['cat']) ?>"></td>
</tr>
<tr>
<td> Prix Unitaire: </td>
<td><input type="text" name="prix" value="<?php echo ($AR['prix']) ?>"></td>
</tr>
<tr>
<td> Fabricant: </td>
<td><input type="text" name="fab" value="<?php echo ($AR['fabricant']) ?>"></td>
</tr>
<tr>
<td>Photo: </td>
<td><input type="file" name="photo"><img src="./images/<?php echo ($AR['photo']) ?>"</td>
</tr>
<tr>
<td></td>
<td> <input type="submit" value="Enregistrer"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
mysql_free_result($rs);
mysql_close($conn);
?>
so i got an error:
Notice: Undefined index: ref in ...\editerArticle.php on line 3
Notice: Undefined index: ref in ...\editerArticle.php on line 3

Use this code
<?php
require_once("connection.php");
$ref=$_POST['ref'];
$req="Select * from article where ref =$ref";
$rs= mysql_query($req) or die(mysql_error());
?>
<html>
<had>
<meta charset="utf-8">
</had>
<body>
<form method="POST" action="modifierArticle.php" enctype="multipart/form-data">
<table>
<?php while($AR=mysql_fetch_assoc($rs)) { ?>
<tr>
<td>Référence:</td>
<td><input type="text" name="ref" value="<?php echo ($AR['ref']) ?>" readonly="true"></td>
</tr>
<tr>
<td>Nom:</td>
<td><input type="text" name="nom" value="<?php echo ($AR['nom']) ?>"></td>
</tr>
<tr>
<td> Catégorie: </td>
<td><input type="text" name="cat" value="<?php echo ($AR['cat']) ?>"></td>
</tr>
<tr>
<td> Prix Unitaire: </td>
<td><input type="text" name="prix" value="<?php echo ($AR['prix']) ?>"></td>
</tr>
<tr>
<td> Fabricant: </td>
<td><input type="text" name="fab" value="<?php echo ($AR['fabricant']) ?>"></td>
</tr>
<tr>
<td>Photo: </td>
<td><input type="file" name="photo"><img src="./images/<?php echo ($AR['photo']) ?>"</td>
</tr>
<tr>
<td></td>
<td> <input type="submit" value="Enregistrer"></td>
</tr>
<?php } ?>
</table>
</form>
</body>
</html>
<?php
mysql_free_result($rs);
mysql_close($conn);
?>

you need to use isset and iempty to ensure you have value in your $_POST
<?php
require_once("connection.php");
if (isset($_POST['ref']) && !empty ($_POST['ref']))
{
$ref=$_POST['ref'];
$req="Select * from article where ref ='.$ref.'";
$rs= mysql_query($req) or die(mysql_error());
while($rs = mysql_fetch_array($rs)){
$ref = $rs['ref'];
$nom = $rs['nom'];
$cat = $rs['cat'];
$prix = $rs['prix'];
$fabricant = $rs['fabricant'];
$photo = $rs['photo'];
}
?>
html
<form method="POST" action="modifierArticle.php" enctype="multipart/form-data">
<table>
<tr>
<td>Référence:</td>
<td><input type="text" name="ref" value="<?php echo $ref; ?>" readonly="true"></td>
</tr>
<tr>
<td>Nom:</td>
<td><input type="text" name="nom" value="<?php echo $nom; ?>"></td>
</tr>
<tr>
<td> Catégorie: </td>
<td><input type="text" name="cat" value="<?php echo $cat; ?>"></td>
</tr>
<tr>
<td> Prix Unitaire: </td>
<td><input type="text" name="prix" value="<?php echo $prix; ?>"></td>
</tr>
<tr>
<td> Fabricant: </td>
<td><input type="text" name="fab" value="<?php echo $fabricant; ?>"></td>
</tr>
<tr>
<td>Photo: </td>
<td><input type="file" name="photo"><img src="./images/<?php echo $photo; ?>"</td>
</tr>
<tr>
<td></td>
<td> <input type="submit" value="Enregistrer"></td>
</tr>
</table>
</form>
</body>
</html>
end mysql connnection
<?php
mysql_free_result($rs);
mysql_close($conn);
?>
EDIT
EDITED FEW SYNTEX mistakes :)

if(isset($_POST['ref']))
{
$ref=$_POST['ref'];
$req="Select * from article where ref = $ref";
$rs= mysql_query($req) or die(mysql_error());
$AR=mysql_fetch_assoc($rs);
}
You had a syntax error in $req add the if condition to make sure that $_POST['ref'] isset before running the query
HTML
<html>
<had>
<meta charset="utf-8">
</had>
<body>
<form method="POST" action="modifierArticle.php" enctype="multipart/form-data">
<table>
<tr>
<td>Référence:</td>
<td><input type="text" name="ref" value="<?php echo $AR['ref']; ?>" readonly="true"></td>
</tr>
<tr>
<td>Nom:</td>
<td><input type="text" name="nom" value="<?php echo $AR['nom']; ?>"></td>
</tr>
<tr>
<td> Catégorie: </td>
<td><input type="text" name="cat" value="<?php echo ;AR['cat']; ?>"></td>
</tr>
<tr>
<td> Prix Unitaire: </td>
<td><input type="text" name="prix" value="<?php echo $AR['prix']; ?>"></td>
</tr>
<tr>
<td> Fabricant: </td>
<td><input type="text" name="fab" value="<?php echo $AR['fabricant']; ?>"></td>
</tr>
<tr>
<td>Photo: </td>
<td><input type="file" name="photo"><img src="../images/<?php echo $AR['photo']; ?>"</td>
</tr>
<tr>
<td></td>
<td> <input type="submit" value="Enregistrer"></td>
</tr>
</table>
</form>
</body>
</html>

Use a array_key_exists check. Like this:
if(array_key_exists('ref', $_POST)) {
//your code here
}

check whether the POST request is empty or not
if(!empty($_POST['ref']))
{
$ref=$_POST['ref'];
}
else
{
echo 'no value';
exit;
}

Related

I write code simple update and its run but name field value not proper fetch in input box, it is only fetch before white space string

<?php
include ('bcpdb.php');
if (isset($_POST['ok']));
$ern=$_POST['erno'];
$cname=$_POST['name'];
$cb=$_POST['branch'];
$cay=$_POST['admyear'];
$iq= "UPDATE stuinfo SET ERNO=$ern, SNAME='$cname',BRANCH='$cb',ADMYEAR='$cay' WHERE ERNO=$ern";
$query=mysqli_query($con,$iq);
mysqli_close($con);
echo '<script> window.location="stulist.php"</script>';
<! DOCTYPE html>
<html>
<head><title>Update</title>
<script type="text/javascript" src="vForm.js"></script>
</head>
<body>
<?php
include 'menu.php'; ?>
<?php
include 'bcpdb.php';
$erno=$_GET['erpass'];
$nm=$_GET['npass'];
$br=$_GET['bpass'];
$ay=$_GET['ypass'];
?>
<form name="f1" method="post" action="updatestu.php" onsubmit="return vForm()" >
<table border=0>
<tr><td colspan=2 ><center><h3>UPDATE STUDENT PROFILE</h3></center></td></tr>
<tr>
<td><label for="fname">Enrollnment No</label></td>
<td><input type="text" name="erno" value=<?php echo "$erno"; ?> ></td>
</tr>
<tr>
<td><label for="fname">Name</label></td>
<td><input type="text" name="name" value=<?php echo "$nm"; ?> ></td>
<tr>
<td><label for="fname">Branch</label></td>
<td><input type="text" name="branch" value=<?php echo "$br"; ?> ></td>
</select></td>
</tr>
<tr>
<td><label for="fname">Addmision Year</label></td>
<td><input type="text" name="admyear" value=<?php echo "$ay"; ?> ></td>
</tr>
<td colspan=2 align=center>
<button type="submit" name="ok">SUBMIT </button></td>
</table>
</form>
</body>
</html>
?>enter image description here
You are using wrong PHP tag.
<td><input type="text" name="admyear" value=<?php echo "$ay"; ?> ></td>
It should be:
<td><input type="text" name="admyear" value="<?php echo $ay; ?>" ></td>

Update sql table on php using html forms

I have been trying to update a record on my table by using an html form. I am able to create and delete a record successfully but I am unable to update it. I am not sure what I have done wrong. Could it be the SQL query syntax? or is my save button not calling my condition statement? I would appreciate any advice given.
ps. I am aware that my SQL database is open to SQL injection. It will be implemented soon!
<?php
include('partregister2.php');
$epr='';
$msg='';
if(isset($_GET['epr']))
$epr=$_GET['epr'];
//+++++++++++++++ UPDATE PARTICIPANTS RECORD +++++++++++++++++
if($epr=='saveup'){
$Name=$_POST['name'];
$Surname=$_POST['surname'];
$Date_of_Birth=$_POST['dob'];
$Age_at_Camp=$_POST['age'];
$Branch=$_POST['branch'];
$Gender=$_POST['gender'];
$Address=$_POST['address'];
$Contact_No=$_POST['contactNo'];
$Next_of_Kin=$_POST['nextKin'];
$Kin_ContactNo=$_POST['kinContact'];
$Attendance_Camp=$_POST['attendCamp'];
$Attendance_School=$_POST['attendSchool'];
$Comments=$_POST['comments'];
$event_name_FK=$_POST['Event_Name'];
$Room_Name_FK=$_POST['Room_Name'];
$a_sql = mysql_query("UPDATE participants SET Name='$Name',Surname='$Surname',Date_of_Birth ='$Date_of_Birth',Age_at_Camp ='$Age_at_Camp',Branch ='$Branch',Gender ='$Gender',Address ='$Address',
Contact_No ='$Contact_No',Next_of_Kin ='$Next_of_Kin',Kin_ContactNo = '$Kin_ContactNo',Attendance_Camp ='$Attendance_Camp',Attendance_School ='$Attendance_School',Comments ='$Comments',event_name_FK ='$event_name_FK',Room_Name_FK ='$Room_Name_FK' WHERE partID='$id'");
if(a_sql)
header("location:index.php");
else
$msg='Error : '.mysql_error();
}
?>
<html>
<head>
</head>
<body>
<?php
if($epr=='update'){
$id=$_GET['id'];
$row=mysql_query("SELECT * FROM participants WHERE partID='$id'");
$st_row=mysql_fetch_array($row);
?>
<h2 align="center">Update Participant Records</h2>
<form method="POST" action='index.php?epr=saveup'>
<table align="center">
<tr>
<td>First Name:</td>
<td><input type='text' name ='name' value="<?PHP echo $st_row['Name'] ?>"/></td>
</tr>
<tr>
<td>Surname:</td>
<td><input type='text' name ='surname' value="<?PHP echo $st_row['Surname'] ?>"/></td>
</tr>
<tr>
<td>Date of Birth:</td>
<td><input type='date' name ='dob' value="<?PHP echo $st_row['Date_of_Birth'] ?>"/></td>
</tr>
<tr>
<td>Age at Camp:</td>
<td><input type='text' name ='age' value="<?PHP echo $st_row['Age_at_Camp'] ?>"/></td>
</tr>
<tr>
<td>Branch:</td>
<td><select name='branch' value="<?PHP echo $st_row['Branch'] ?>"/>
<option></option>
<option>Brixton</option>
<option>North London</option>
<option>East London</option>
<option>Southall</option>
<option>Leicester</option>
<option>Newport</option>
<option>Liverpool</option></td>
</tr>
</select>
<tr>
<td>Gender:</td>
<td>Male<input type="radio" value="male" name="gender" value="<?PHP echo $st_row['Gender'] ?>"/>
Female<input type="radio" value="female" name="gender" value="<?PHP echo $st_row['Gender'] ?>" /><td/>
</tr>
<tr>
<td>Address:</td>
<td><input type='text' name ='address' value="<?PHP echo $st_row['Address'] ?>"/></td>
</tr>
<tr>
<td>Contact No:</td>
<td><input type='text' name ='contactNo' value="<?PHP echo $st_row['Contact_No'] ?>"/></td>
</tr>
<tr>
<td>Next of Kin:</td>
<td><input type='text' name ='nextKin' value="<?PHP echo $st_row['Next_of_Kin'] ?>"/></td>
</tr>
<tr>
<td>Kin's Contact No:</td>
<td><input type='text' name ='kinContact' value="<?PHP echo $st_row['Kin_ContactNo'] ?>"/></td>
</tr>
<tr>
<td>Attendance at Camp:</td>
<td><input type='text' name ='attendCamp' value="<?PHP echo $st_row['Attendance_Camp'] ?>"/></td>
</tr>
<tr>
<td>Attendance at Sunday School:</td>
<td><input type='text' name ='attendSchool' value="<?PHP echo $st_row['Attendance_School'] ?>"/></td>
</tr>
<tr>
<td>Comments:</td>
<td><input type='text' name ='comments' value="<?PHP echo $st_row['Comments'] ?>"/></td>
</tr>
<tr>
<td>Event Name:</td>
<td><select name='Event_Name' value="<?PHP echo $st_row['event_name_FK'] ?>">
<?php
$res = mysql_query("SELECT * FROM events");
while($row=mysql_fetch_array($res))
{
?>
<option>
<?php echo $row["Event_Name"]; ?>
</option>
<?php } ?>
</tr>
</select>
<tr>
<td>Allocate Room:</td>
<td><select name='Room_Name' value="<?PHP echo $st_row['Room_Name_FK'] ?>">
<?php
$res = mysql_query("SELECT * FROM rooms");
while($row=mysql_fetch_array($res))
{
?>
<option>
<?php echo $row["Room_Name"]; ?>
</option>
<?php } ?>
</td>
</select>
</tr>
<td></td>
<tr>
<td></td>
<td><input type ='submit' name='save'/></td>
</tr>
</table>
</form>
<?php } else{
?>
</body>
</html>
I think you forgot to add $
$a_sql = mysql_query("UPDATE participants SET Name='$Name',Surname='$Surname',Date_of_Birth ='$Date_of_Birth',Age_at_Camp ='$Age_at_Camp',Branch ='$Branch',Gender ='$Gender',Address ='$Address',
Contact_No ='$Contact_No',Next_of_Kin ='$Next_of_Kin',Kin_ContactNo = '$Kin_ContactNo',Attendance_Camp ='$Attendance_Camp',Attendance_School ='$Attendance_School',Comments ='$Comments',event_name_FK ='$event_name_FK',Room_Name_FK ='$Room_Name_FK' WHERE partID='$id'");
if($a_sql) //here
header("location:index.php");
else
$msg='Error : '.mysql_error();
After executing sql query, you have used a_sql variable without $ sign inside if condition, i have improved your code.
if($a_sql)
header("location:index.php");
else
$msg='Error : '.mysql_error();

Im getting Undefined index: name in C:\xampp\htdocs\boot\fill.php on line 15 [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 7 years ago.
this code will display the details of the owner if I enter the application number but it is displaying errors how can i fix the errors please help me
index.php
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db_test", $con);
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db_test", $con);
//$sql="select * from tbl_owner";
$result = mysql_query("select * from tbl_owner where Application_no='$_POST[name]'");
while($rowval = mysql_fetch_array($result))
{
$name = $_POST['name'];
$Application_no= $rowval['Application_no'];
$Full_name= $rowval['Full_name'];
$contact= $rowval['contact'];
$residence= $rowval['residence'];
$age= $rowval['age'];
$status= $rowval['civil_status'];
$spouse= $rowval['name_of_spouse'];
$goods= $rowval['kind_of_goods'];
}
mysql_close($con);
?>
<html>
<head><title></title>
</head>
<body>
<form action="fill.php" method="post">
<table style="color:purple;border-style:groove; height:150px;width:350px" background="backimage.jpg">
<tr>
<td style=" height:25px; font-family:'Copperplate Gothic Bold'"> </td>
</tr>
<tr>
<td style="color:red;background-color:aqua;height:25px">Enter Account no
<input name="name" type="text"/></td>
</tr>
<tr>
<td style="height:25px">
<input type="submit" value="Submit" style="color:white;background-color:brown; height:30px" /></td>
</tr>
</table>
</form>
<span>
<table name="tab" style="color:purple;border-style:groove; height:150px;width:350px" background="3.jpg">
<tr>
<td style="font-family:Copperplate Gothic Bold"></td>
</tr>
<tr>
<td style="height:25px">
<input type="submit" value="Submit" style="color:white;background-color:brown; height:30px" /></td>
</tr>
<tr>
<td style="color:red;background-color:aqua;" class="auto-style3">Account no:</td>
<td class="auto-style4">
<input id="Text1" type="text" value='<?php echo $Application_no; ?>'/></td>
</tr>
<tr>
<td style="color:red;background-color:aqua;" class="auto-style3">Fullname</td>
<td class="auto-style4">
<input id="Text2" type="text" disabled value='<?php echo $Full_name; ?>'/></td>
</tr>
<tr>
<td style="color:red;background-color:aqua;" class="auto-style3">Contact:</td>
<td class="auto-style4">
<input id="Text3" type="text" disabled value='<?php echo $contact; ?>' /></td>
</tr>
<tr>
<td style="color:red;background-color:aqua;" class="auto-style3">Residence:</td>
<td class="auto-style4">
<input id="Text4" type="text" disabled value='<?php echo $residence; ?>' /></td>
</tr>
<tr>
<td style="color:red;background-color:aqua;" class="auto-style3">Age:</td>
<td class="auto-style4">
<input id="Text4" type="text" disabled value='<?php echo $age; ?>' /></td>
</tr>
<tr>
<td style="color:red;background-color:aqua;" class="auto-style3">Civil Status:</td>
<td class="auto-style4">
<input id="Text4" type="text" disabled value='<?php echo $status; ?>' /></td>
</tr>
<tr>
<td style="color:red;background-color:aqua;" class="auto-style3">Spouse:</td>
<td class="auto-style4">
<input id="Text4" type="text" disabled value='<?php echo $spouse; ?>' /></td>
</tr>
<tr>
<td style="color:red;background-color:aqua;" class="auto-style3">kind of goods:</td>
<td class="auto-style4">
<input id="Text4" type="text" disabled value='<?php echo $goods; ?>' /></td>
</tr>
<tr>
<td></td>
</tr>
</table>
</span>
</body>
</html>
You haven't specified the names of the textboxes. Use it like the following:
<input id="Text2" name="name" type="text" disabled value='<?php echo $Full_name; ?>'/>
Try this
$name='';
$Application_no='';
$Full_name='';
$contact='';
$residence='';
$age='';
$status='';
$spouse='';
$goods='';
if(isset($_POST['name'])){
$result = mysql_query("select * from tbl_owner where Application_no='{$_POST[name]}'");
while($rowval = mysql_fetch_array($result))
{
$name = $_POST['name'];
$Application_no= $rowval['Application_no'];
$Full_name= $rowval['Full_name'];
$contact= $rowval['contact'];
$residence= $rowval['residence'];
$age= $rowval['age'];
$status= $rowval['civil_status'];
$spouse= $rowval['name_of_spouse'];
$goods= $rowval['kind_of_goods'];
}
mysql_close($con);
}

Edit Database in PHP-Site

I'm very new to php and databases. So I need you to help me out please.
I want to edit the data of my database online in my php site. But the form is empty and I don't know why.
I don't know if you need more information so this is the code of the table with the form. If you need more let me know.
<table>
<?php
$con=mysqli_connect("x","y","z","xyz");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Transparente");
while($row = mysqli_fetch_array($result))
mysqli_close($con);
?>
<form method="post" action="edit_data.php">
<input type="text" name="id" value="<? echo "$row[id]"?>">
<tr>
<td>Firma</td>
<td>
<input type="text" name="name"
size="40" value="<? echo "$row[Name]"?>">
</td>
</tr>
<tr>
<td>Wer</td>
<td>
<input type="text" name="wer" size="40"
value="<? echo "$row[Wer]"?>">
</td>
</tr>
<tr>
<td>Erhalten</td>
<td>
<input type="text" name="erhalten" size="40"
value="<? echo "$row[Erhalten]"?>">
</td>
</tr>
<tr>
<td>Digital</td>
<td>
<input type="text" name="digital" size="40"
value="<? echo "$row[Digital]"?>">
</td>
</tr>
<tr>
<td>Betrag in Euro</td>
<td>
<input type="text" name="betrag" size="40"
value="<? echo "$row[Betrag]"?>">
</td>
</tr>
<tr>
<td>Bezahlt am</td>
<td>
<input type="text" name="bezahlt" size="40"
value="<? echo "$row[Bezahlt]"?>">
</td>
</tr>
<tr>
<td>Anmerkung</td>
<td>
<input type="text" name="anmerkung" size="40"
value="<? echo "$row[Anmerkung]"?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
Try below code
1)If data base contain more rows it shows multiple form
2)You need to show one form you need to restrict in query using where class
<?php
$con=mysqli_connect("x","y","z","xyz");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Transparente");
while($row = mysqli_fetch_array($result))
{
?>
<table>
<form method="post" action="edit_data.php">
<input type="text" name="id" value="<?php echo $row['id'];?>">
<tr>
<td>Firma</td>
<td>
<input type="text" name="name"
size="40" value="<?php echo $row['Name'];?>">
</td>
</tr>
<tr>
<td>Wer</td>
<td>
<input type="text" name="wer" size="40"
value="<?php echo $row['Wer']?>">
</td>
</tr>
<tr>
<td>Erhalten</td>
<td>
<input type="text" name="erhalten" size="40"
value="<?php echo $row['Erhalten']?>">
</td>
</tr>
<tr>
<td>Digital</td>
<td>
<input type="text" name="digital" size="40"
value="<?php echo $row['Digital']?>">
</td>
</tr>
<tr>
<td>Betrag in Euro</td>
<td>
<input type="text" name="betrag" size="40"
value="<?php echo $row['Betrag']?>">
</td>
</tr>
<tr>
<td>Bezahlt am</td>
<td>
<input type="text" name="bezahlt" size="40"
value="<?php echo "$row[Bezahlt]"?>">
</td>
</tr>
<tr>
<td>Anmerkung</td>
<td>
<input type="text" name="anmerkung" size="40"
value="<?php echo $row['Anmerkung'];?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
<?php } ?>
Edit:
change query like below
$result = mysqli_query($con,"SELECT * FROM Transparente where id={$_REQUEST['id']}");
<table>
<?php
$con=mysqli_connect("x","y","z","xyz");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Transparente");
while($row = mysqli_fetch_array($result))
?>
<form method="post" action="edit_data.php">
<input type="text" name="id" value="<? echo "$row[id]"?>">
<tr>
<td>Firma</td>
<td>
<input type="text" name="name"
size="40" value="<? echo "$row[Name]"?>">
</td>
</tr>
<tr>
<td>Wer</td>
<td>
<input type="text" name="wer" size="40"
value="<? echo "$row[Wer]"?>">
</td>
</tr>
<tr>
<td>Erhalten</td>
<td>
<input type="text" name="erhalten" size="40"
value="<? echo "$row[Erhalten]"?>">
</td>
</tr>
<tr>
<td>Digital</td>
<td>
<input type="text" name="digital" size="40"
value="<? echo "$row[Digital]"?>">
</td>
</tr>
<tr>
<td>Betrag in Euro</td>
<td>
<input type="text" name="betrag" size="40"
value="<? echo "$row[Betrag]"?>">
</td>
</tr>
<tr>
<td>Bezahlt am</td>
<td>
<input type="text" name="bezahlt" size="40"
value="<? echo "$row[Bezahlt]"?>">
</td>
</tr>
<tr>
<td>Anmerkung</td>
<td>
<input type="text" name="anmerkung" size="40"
value="<? echo "$row[Anmerkung]"?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
<?php mysqli_close($con);?>
// close connection at the end of the code
You are not opening the while loop.Try this it will show you the values in the form
<table>
<?php
$con=mysqli_connect("x","y","z","xyz");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Transparente");
while($row = mysqli_fetch_array($result))
{
mysqli_close($con);
?>
<form method="post" action="edit_data.php">
<input type="text" name="id" value="<? echo "$row[id]"?>">
<tr>
<td>Firma</td>
<td>
<input type="text" name="name"
size="40" value="<? echo "$row[Name]"?>">
</td>
</tr>
<tr>
<td>Wer</td>
<td>
<input type="text" name="wer" size="40"
value="<? echo "$row[Wer]"?>">
</td>
</tr>
<tr>
<td>Erhalten</td>
<td>
<input type="text" name="erhalten" size="40"
value="<? echo "$row[Erhalten]"?>">
</td>
</tr>
<tr>
<td>Digital</td>
<td>
<input type="text" name="digital" size="40"
value="<? echo "$row[Digital]"?>">
</td>
</tr>
<tr>
<td>Betrag in Euro</td>
<td>
<input type="text" name="betrag" size="40"
value="<? echo "$row[Betrag]"?>">
</td>
</tr>
<tr>
<td>Bezahlt am</td>
<td>
<input type="text" name="bezahlt" size="40"
value="<? echo "$row[Bezahlt]"?>">
</td>
</tr>
<tr>
<td>Anmerkung</td>
<td>
<input type="text" name="anmerkung" size="40"
value="<? echo "$row[Anmerkung]"?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
<?php }?>

table cuts off page after 2nd <td>

I don't know why but my table cuts off right after the second <td> tag... can anyone help, I have constantly looked over it over and over. Can someone help me find where the problem is?
<tr>
<td>Username:</td>
<td>
<input name="username" type="text" value='<?
if($form->value("username")==""){
echo($req_user_info["username"]);
}else{
echo $form->value("username");
}
?>' size="56" maxlength="30">
</td>
<td>
<? echo($form->error("username")); ?>
</td>
</tr>
<tr>
<td>New Password:</td>
<td>
<input name="newpass" type="password" value='<?
echo($form->value("newpass"));
?>' size="56" maxlength="30">
</td>
<td>
<? echo($form->error("newpass")); ?>
</td>
</tr>
Btw, that code is only the first two rows.
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
?>
<form action="adminprocess.php" method="POST">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr>
<td>Username:</td>
<td>
<input name="username" type="text" value='<?php
if($form->value("username")==""){
echo($req_user_info["username"]);
}else{
echo $form->value("username");
}
?>' size="56" maxlength="30">
</td>
<td>
<?php echo($form->error("username")); ?>
</td>
</tr>
<tr>
<td>New Password:</td>
<td>
<input name="newpass" type="password" value='<?php
echo($form->value("newpass"));
?>' size="56" maxlength="30">
</td>
<td>
<?php echo($form->error("newpass")); ?>
</td>
</tr>
<tr>
<td>Confirm New Password:</td>
<td><input name="conf_newpass" type="password" value='
<?php echo $form->value("newpass"); ?>' size="56" maxlength="30"></td>
<td><?php echo $form->error("newpass"); ?></td>
</tr>
</tr>
<td>Edit motto:</td>
<td><input type="text" size="56" name="motto" value='<?php
if($form->value("motto") == ""){
echo $req_user_info['motto'];
}else{
echo $form->value("motto");
}
?>'></td>
<tr>
<tr>
<td>Edit profile bio:</td>
<td><textarea cols="40" rows="10" name="profile" value=""><?php
if($form->value("profile") == ""){
echo $req_user_info['profile'];
}else{
echo $form->value("profile");
}
?></textarea></td>
<tr>
<tr>
<td>Email:</td>
<td><input name="email" type="text" value='
<?php
if($form->value("email") == ""){
echo $req_user_info["email"];
}else{
echo $form->value("email");
}
?>' size="56" maxlength="50">
</td>
<td><?php echo $form->error("email"); ?></td>
</tr>
<tr>
<td>User level:</td>
<td><input name="userlevel" type="text" value='
<?php
if($form->value("userlevel") == ""){
echo $req_user_info["userlevel"];
}else{
echo $form->value("userlevel");
}
?>' size="4" maxlength="10"></td>
<td><?php echo $form->error("userlevel"); ?></td>
</tr>
<tr><td align="right">
<input type="hidden" name="subedit" value="1">
<input type="hidden" name="usertoedit" value="<?php echo $usertoedit; ?>">
<input type="submit" name="button" value="Edit Account">
</td>
<td colspan="2" style="text-align:right;">
<input type="submit" name="button" value="Delete" onclick="return confirm ('Are you sure you want to delete this user, this cannot be undone?\n\n' + 'Click OK to continue or Cancel to Abort!')">
</td>
</tr>
</table>
</form>
I've changed your syntax a little..
<tr>
<td>Username:</td>
<td><input name="username" type="text" value="<?php echo htmlspecialchars(($form->value("username")=="" ? $req_user_info["username"] : $form->value("username"))); ?>" size="56" maxlength="30"></td>
<td><?php echo $form->error("username"); ?></td>
</tr>
<tr>
<td>New Password:</td>
<td><input name="newpass" type="password" value="<?php echo htmlspecialchars($form->value("newpass")); ?>" size="56" maxlength="30"></td>
<td><?php echo $form->error("newpass"); ?></td>
</tr>
For additional php error logging, put this at the top of the page:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
?>

Categories