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);
?>
Related
Please look into this code unable to find out the actual error:
This is PHP upload code:
<?php
include_once("config.php");
if(isset($_GET['pro_id']))
{
$id=$_GET['pro_id'];
if(isset($_POST['submitBtn'])) {
$dept_id = $_POST['dept_id'];
$cat_id = $_POST['cat_id'];
/*$pro_id = $_POST['pro_id'];*/
$pro_name = $_POST['pro_name'];
$pro_desc = $_POST['pro_desc'];
$pro_spec = $_POST['pro_spec'];
$pro_price = $_POST['pro_price'];
$status = 'on';
$pro_keywords = $_POST['pro_keywords'];
//image names
$pro_image = $_FILES['pro_image']['name'];
//temp images names
$temp_image = $_FILES['pro_image']['tmp_name'];
if($dept_id=='' OR $cat_id=='' OR $pro_name=='' OR $pro_desc=='' OR $pro_spec=='' OR $pro_price=='' OR $pro_image=='' OR $pro_keywords=='')
{
echo "<script>alert('All the fields are mandatory')</script>";
exit();
}
else
{
//upload image to folder
move_uploaded_file($temp_image,"images/product_images/$pro_image");
$run_query1 = mysqli_query($login, "update products1 SET (dept_id,cat_id,pro_name,pro_desc,pro_spec,pro_price,pro_image,status,date,pro_keywords) values ( '$dept_id','$cat_id','$pro_name','$pro_desc','$pro_spec','$pro_price','$pro_image','$status','NOW()','$pro_keywords' WHERE pro_id='$id'");
if($run_query1)
{
echo "<script>alert('Product updated successfully')</script>";
exit();
}
else
{
echo "<script>alert('Errors')</script>";
}
} }
$query1 = mysqli_query($login, "select * from products1 where pro_id='$id'");
$query2 = mysqli_fetch_array($query1);
?>
This the form Part where data retrieve from table and when click on the update button nothing happened and page is redirected to view data page and showing the old data:
<form action="ViewProduct.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table width="650" border="0">
<tr>
<td width="183" align="right">Department:</td>
<th width="231" align="left">
<select name="dept_id" id="dept_id">
<option>Select Department</option>
<?php
$result=dept_show();
while($row=mysqli_fetch_assoc($result))
{
echo "<option value='{$row['dept_id']}'>{$row['dept_name']}</option>";
}
?>
</select></th></tr>
<tr>
<td width="183" align="right">Catagory</td>
<th width="231" align="left">
<select name="cat_id" id="cat_id">
<option>Select Catagory</option>
<?php
$result1=cat_show();
while($row=mysqli_fetch_assoc($result1))
{
echo "<option value='{$row['cat_id']}'>{$row['cat_name']}</option>";
}
?>
</select></th></tr>
<tr>
<!--<td width="231"><input type="hidden" name="pro_id" id="pro_id" value="<t?php echo $pro_id; ?>" /></td>-->
</tr>
<tr>
<td align="right">Product Name/Model:</td>
<td><input type="text" name="pro_name" id="pro_name" value="<?php echo $query2['pro_name']; ?>" /></td>
</tr>
<tr>
<td align="right">Product Description:</td>
<td><textarea type="textarea" name="pro_desc" id="pro_desc" cols="45" rows="5"><?php echo $query2['pro_desc']; ?></textarea></td>
</tr>
<tr>
<td align="right">Products Specification:</td>
<td><textarea type="textarea" name="pro_spec" id="pro_spec" cols="45" rows="5"><?php echo $query2['pro_spec']; ?></textarea></td>
</tr>
<tr>
<td align="right">Product Price:</td>
<td><input type="text" name="pro_price" id="pro_price" value="<?php echo $query2['pro_price']; ?>" /></td>
</tr>
<tr>
<td align="right">Product Image:</td>
<td><input type="file" name="pro_image" id="pro_image" value="<?php echo $query2['pro_image']; ?>" /></td>
</tr>
<tr>
<td></td>
<td><input size="45" type="text" name="text" id="text" value="<?php echo $query2['pro_image']; ?>" /></td>
</tr>
<tr>
<td align="right">Keywords:</td>
<td><input size="45" type="text" name="pro_keywords" id="pro_keywords" value="<?php echo $query2['pro_keywords']; ?>" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submitBtn" id="submit" value="Update" /></td>
</tr>
</table>
</form>
</div> <?php } ?>
</td>
</tr>
</table>
</div>
Form method is POST and you are using GET method in if loop
if(isset($_GET['pro_id']))
Use POST here.
I have made the changes in you complete code. Use this code and if required made the changes (if issues arrived)
PHP code
<?php
include_once("config.php");
if(isset($_POST['submitBtn']))
{
$dept_id = $_POST['dept_id'];
$cat_id = $_POST['cat_id'];
$pro_id = $_POST['pro_id'];*/
$pro_name = $_POST['pro_name'];
$pro_desc = $_POST['pro_desc'];
$pro_spec = $_POST['pro_spec'];
$pro_price = $_POST['pro_price'];
$status = 'on';
$pro_keywords = $_POST['pro_keywords'];
//image names
$pro_image = $_FILES['pro_image']['name'];
//temp images names
$temp_image = $_FILES['pro_image']['tmp_name'];
if($dept_id=='' OR $cat_id=='' OR $pro_name=='' OR $pro_desc=='' OR $pro_spec=='' OR $pro_price=='' OR $pro_image=='' OR $pro_keywords=='')
{
echo "<script>alert('All the fields are mandatory')</script>";
exit();
}
else
{
//upload image to folder
move_uploaded_file($temp_image,"images/product_images/$pro_image");
$run_query1 = mysqli_query($login, "update products1 SET (dept_id,cat_id,pro_name,pro_desc,pro_spec,pro_price,pro_image,status,date,pro_keywords) values ( '$dept_id','$cat_id','$pro_name','$pro_desc','$pro_spec','$pro_price','$pro_image','$status','NOW()','$pro_keywords' WHERE pro_id='$id'");
if($run_query1)
{
echo "<script>alert('Product updated successfully')</script>";
exit();
}
else
{
echo "<script>alert('Errors')</script>";
}
}
}
$query2 = array();
if(isset($_GET['pro_id']))
{
$id=$_GET['pro_id'];
$query1 = mysqli_query($login, "select * from products1 where pro_id='$id'");
$query2 = mysqli_fetch_array($query1);
}
?>
HTML Code
<form action="ViewProduct.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table width="650" border="0">
<tr>
<td width="183" align="right">Department:</td>
<th width="231" align="left">
<select name="dept_id" id="dept_id">
<option>Select Department</option>
<?php
$result=dept_show();
while($row=mysqli_fetch_assoc($result))
{
echo "<option value='{$row['dept_id']}'>{$row['dept_name']}</option>";
}
?>
</select></th></tr>
<tr>
<td width="183" align="right">Catagory</td>
<th width="231" align="left">
<select name="cat_id" id="cat_id">
<option>Select Catagory</option>
<?php
$result1=cat_show();
while($row=mysqli_fetch_assoc($result1))
{
echo "<option value='{$row['cat_id']}'>{$row['cat_name']}</option>";
}
?>
</select></th></tr>
<tr>
<td width="231"><input type="hidden" name="pro_id" id="pro_id" value="<t?php echo $pro_id; ?>" /></td>
</tr>
<tr>
<td align="right">Product Name/Model:</td>
<td><input type="text" name="pro_name" id="pro_name" value="<?php echo $query2['pro_name']; ?>" /></td>
</tr>
<tr>
<td align="right">Product Description:</td>
<td><textarea type="textarea" name="pro_desc" id="pro_desc" cols="45" rows="5"><?php echo $query2['pro_desc']; ?></textarea></td>
</tr>
<tr>
<td align="right">Products Specification:</td>
<td><textarea type="textarea" name="pro_spec" id="pro_spec" cols="45" rows="5"><?php echo $query2['pro_spec']; ?></textarea></td>
</tr>
<tr>
<td align="right">Product Price:</td>
<td><input type="text" name="pro_price" id="pro_price" value="<?php echo $query2['pro_price']; ?>" /></td>
</tr>
<tr>
<td align="right">Product Image:</td>
<td><input type="file" name="pro_image" id="pro_image" value="<?php echo $query2['pro_image']; ?>" /></td>
</tr>
<tr>
<td></td>
<td><input size="45" type="text" name="text" id="text" value="<?php echo $query2['pro_image']; ?>" /></td>
</tr>
<tr>
<td align="right">Keywords:</td>
<td><input size="45" type="text" name="pro_keywords" id="pro_keywords" value="<?php echo $query2['pro_keywords']; ?>" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submitBtn" id="submit" value="Update" /></td>
</tr>
</table>
</form>
</div> <?php } ?>
</td>
</tr>
</table>
Your pro_id field is commented out in your HTML using <!-- and -->, so the following never is true:
if(isset($_GET['pro_id']))
Also, you have a mismatch between your form method POST and $_GET that you are looking for.
Your query of update is correct? I think you must use
UPDATE products1 SET dept_id='$dept_id',cat_id ='$cat_id'... the rest of values
WHERE pro_id='$id'
And verify if your dept_id is INT as well cat_id, so if they are INT you don't need ''
UPDATE products1 SET dept_id=$dept_id,cat_id =$cat_id
Try to do this steps:
First thing comment out this line,
<!--<td width="231"><input type="hidden" name="pro_id" id="pro_id" value="<t?php echo $pro_id; ?>" /></td>-->
next step,
you are sending data using POST i.e. (form method="post"), so use this
if(isset($_POST['pro_id'])) , then comment out $pro_id = $_POST['pro_id'];
you will get $pro_id value.
I am loading a php page into a spefific div, using this code
function peopleEdit(id, currid) {
$("#people_edit").load( "people_edit.php?id="+currid );
return false;
}
There are 2 issues though.
the form displayed, has the option values out of the select box, and the option is not working.
the tinymce box is displayed but the data are out of the box.
the form is tested and is working properly before the ajax .load
here's the html of the form.
<form action="people.php" enctype="multipart/form-data" name="pelatesForm" id="pelatesForm" method="post">
<table width="90%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="20%" align="right">Τύπος</td>
<td width="80%"><label>
<select name="pelates_type_det" id="pelates_type_det" />
<option value="<?php echo $pelates_det_type ?>"><?php echo $pelates_det_type ?></option>
<option value="Πελάτης">Πελάτης</option>
<option value="Προμηθευτής">Προμηθευτής</option>
</select>
</label></td>
</tr>
<tr>
<td width="20%" align="right">Όνομα</td>
<td width="80%"><label>
<input name="pelates_first_name_det" type="text" id="pelates_first_name_det" size="64" value="<?php echo $pelates_det_first_name ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Επίθετο</td>
<td width="80%"><label>
<input name="pelates_last_name" type="text" id="pelates_last_name" size="64" value="<?php echo $pelates_det_last_name ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Τηλέφωνο - Σταθερό</td>
<td width="80%"><label>
<input name="pelates_phone" type="text" id="pelates_phone" size="64" value="<?php echo $pelates_det_phone ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Τηλέφωνο - Κινητό</td>
<td width="80%"><label>
<input name="pelates_cell" type="text" id="pelates_cell" size="64" value="<?php echo $pelates_det_cell ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Email</td>
<td width="80%"><label>
<input name="pelates_email" type="text" id="pelates_email" size="64" value="<?php echo $pelates_det_email ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Όνομα εταιρείας - Ιδιώτης</td>
<td width="80%"><label>
<input name="pelates_company" id="pelates_company" size="64" value="<?php echo $pelates_det_company ?>" />
</label>
</td>
</tr>
<tr>
<td width="20%" align="right">ΑΦΜ</td>
<td width="80%"><label>
<input name="pelates_afm" type="text" id="pelates_afm" size="64" value="<?php echo $pelates_det_afm ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">ΔΟΥ</td>
<td width="80%"><label>
<input name="pelates_doy" type="text" id="pelates_doy" size="64" value="<?php echo $pelates_det_doy ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Διεύθυνση</td>
<td width="80%"><label>
<input name="pelates_address" type="text" id="pelates_address" size="64" value="<?php echo $pelates_det_address ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Ταχυδρομικός κώδικας</td>
<td width="80%"><label>
<input name="pelates_tk" type="text" id="pelates_tk" size="64" value="<?php echo $pelates_det_tk ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Περιοχή</td>
<td width="80%"><label>
<input name="pelates_area" type="text" id="pelates_area" size="64" value="<?php echo $pelates_det_area ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Σχόλια</td>
<td width="80%">
<textarea name="pelates_comments_det" type="text" class="tinymce" id="pelates_comments_det" size="64" /><?php echo $pelates_det_comments ?></textarea>
</td>
</tr>
<tr>
<td> </td>
<td><label>
<input name="thisID" type="hidden" value="<?php echo $targetID ?>" />
<input type="submit" name="submitpel" id="submitpel" value="Υποβολή" />
<input type="button" value="Άκυρο" onclick="return epistrofi('people_detailed','<?php echo $targetID ?>');" />
</label>
</td>
</tr>
</table>
</form>
any ideas of why is this happening?
You close your select :
<select name="pelates_type_det" id="pelates_type_det" />
Change to:
<select name="pelates_type_det" id="pelates_type_det">
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 }?>
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;
}
I have a form which loops if the value indicated is less than or equal the number of 'enrollee's needed. The while loop works perfectly with one exception, I use DOB fields which ALSO use FOR loops to display their values. If I remove the DOB fields, the form loop works fine, when left in, it errors out. Any ideas?
<form id="Enroll_Form" action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="Enroll_Form" >
<?php
$i=1;
while ($i <= ($_SESSION['Num_Members'])): {?>
<table class="demoTable">
<tr>
<td>First Name: </td>
<td><input type="text" name="F1FirstName" value="<?php echo $fields['F1FirstName']; ?>" /></td>
</tr>
<tr>
<td>Middle Initial: </td>
<td><input type="text" name="F1MI" size="2" maxlength="1" value="<?php echo $fields['F1MI']; ?>" /></td>
</tr>
<tr>
<td>Last Name: </td>
<td><input type="text" name="F1LastName" value="<?php echo $fields['F1LastName']; ?>" /></td>
</tr>
<tr>
<td>Federation No: </td>
<td><input type="text" name="F1FedNum" maxlength="10" value="<?php echo $fields['F1FedNum']; ?>" /></td>
</tr>
<tr>
<td>SSN: </td>
<td><input type="text" name="F1SSN1" size="3" maxlength="3" value="<?php echo $fields['F1SSN1']; ?>" /> -
<input type="text" name="F1SSN2" size="2" maxlength="2" value="<?php echo $fields['F1SSN2']; ?>" /> -
<input type="text" name="F1SSN3" size="4" maxlength="4" value="<?php echo $fields['F1SSN3']; ?>" />
</td>
</tr>
<tr>
<td>Date of Birth</td>
<td>
<select name="F1DOB1">
<option value="">Month</option>
<?php
for ($i=1; $i<=12; $i++)
{
echo "<option value='$i'";
if ($fields["F1DOB1"] == $i)
echo " selected";
echo ">$i</option>";
}
?>
</select> /
<select name="F1DOB2">
<option value="">Day</option>
<?php
for ($i=1; $i<=31; $i++)
{
echo "<option value='$i'";
if ($fields["F1DOB2"] == $i)
echo " selected";
echo ">$i</option>";
}
?>
</select> /
<select name="F1DOB3">
<option value="">Year</option>
<?php
for ($i=date('Y'); $i>=1900; $i--)
{
echo "<option value='$i'";
if ($fields["F1DOB3"] == $i)
echo " selected";
echo ">$i</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>Address: </td>
<td><input type="text" name="F1Address" value="<?php echo $fields['F1Address']; ?>" /></td>
</tr>
<tr>
<td>City: </td>
<td><input type="text" name="F1City" value="<?php echo $fields['F1City']; ?>" /></td>
</tr>
<tr>
<td>State: </td>
<td><select name="F1State"><option value="">Choose a State</option><?php showOptionsDrop($states_arr, null, true); ?></select></td>
</tr>
<tr>
<td>Zip Code: </td>
<td><input type="text" name="F1Zip" size="6" maxlength="5" value="<?php echo $fields['F1Zip']; ?>" /></td>
</tr>
<tr>
<td>Contact Telephone No: </td>
<td>( <input type="text" name="F1Phone1" size="3" maxlength="3" value="<?php echo $fields['F1Phone1']; ?>" /> )
<input type="text" name="F1Phone2" size="3" maxlength="3" value="<?php echo $fields['F1Phone2']; ?>" /> -
<input type="text" name="F1Phone3" size="4" maxlength="4" value="<?php echo $fields['F1Phone3']; ?>" />
</td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="F1Email" value="<?php echo $fields['F1Email']; ?>" /></td>
</tr>
</table>
<br />
<?php } $i++; endwhile; ?>
<div align="right"><input class="enrbutton" type="submit" name="submit" value="Continue" /></div>
</form>
You are using $i in your while loop, and in all of your for loops. You need to change it to something else.
That is probably causing you some problems (not to mention it being terribly hard to understand)