I am new in php. I have a web form. In which i use textarea. I have another PHP page where I display data from db and applying CRUD operation. Now here is the problem when I click on Edit button my all form data has been fetched from db but the formatting of textarea Text has been changed. It shows \r\r\r\n I use nl2br but its not working. I want to display my data in same formating.
<textarea rows="20" cols="100" id="text" name="text" style="font-size:14px;" > <?php echo !empty(nl2br($text))?(nl2br($text)):'';?> </textarea><td>
My Full Page Code is
<?php
require 'database.php';
$id = null;
if ( !empty($_GET['id'])) {
$id = $_REQUEST['id'];
}
if ( null==$id ) {
header("Location: index.php");
}
if ( !empty($_POST)) {
// keep track post values
$file_name = $_POST['file_name'];
$ref_no = $_POST['ref_no'];
$to_name = $_POST['to_name'];
$confidential = $_POST['confidential'];
$designation = $_POST['designation'];
$date = $_POST['date'];
$solutation = $_POST['solutation'];
$entity = $_POST['entity'];
$add_1 = $_POST['add_1'];
$thank_you = $_POST['thank_you'];
$add_2 = $_POST['add_2'];
$yours_truly = $_POST['yours_truly'];
$add_3 = $_POST['add_3'];
$sign_name = $_POST['sign_name'];
$city = $_POST['city'];
$s_designation = $_POST['s_designation'];
$heading_line_1 = $_POST['heading_line_1'];
$encl_line_1 = $_POST['encl_line_1'];
$heading_line_2 = $_POST['heading_line_2'];
$encl_line_2 = $_POST['encl_line_2'];
$heading_line_3 = $_POST['heading_line_3'];
$encl_line_3 = $_POST['encl_line_3'];
$text = mysql_real_escape_string( $_POST['text'] );
// update data
$valid = true;
if ($valid) {
$pdo = Database::connect();
// $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "UPDATE test set file_name ='$file_name', ref_no ='$ref_no', to_name ='$to_name',
confidential ='$confidential', designation = '$designation', date ='$date',
solutation ='$solutation', entity ='$entity', add_1 ='$add_1',
thank_you ='$thank_you', add_2 ='$add_2', yours_truly ='$yours_truly',
add_3 ='$add_3', sign_name ='$sign_name', city ='$city',
s_designation ='$s_designation', heading_line_1 ='$heading_line_1', encl_line_1 ='$encl_line_1',
heading_line_2 ='$heading_line_2', encl_line_2 ='$encl_line_2', heading_line_3 ='$heading_line_3',
encl_line_3 ='$encl_line_3', text ='$text' WHERE id ='$id'";
$q = $pdo->prepare($sql);
$q->execute(array($file_name,$ref_no,$to_name,$confidential,$designation,$date,$solutation,$entity,$add_1,
$thank_you,$add_2,$yours_truly,$add_3,$sign_name,$city,$s_designation,$heading_line_1,$encl_line_1,$heading_line_2,
$encl_line_2,$heading_line_3,$encl_line_3,$id));
Database::disconnect();
header("Location: index.php");
}
else {
}
}
$con=mysqli_connect("localhost","MY_LOGIN","MY_PASSWORD","MY_DATABASE");
$id2 = $_GET['id'];
$sql = "SELECT * FROM test where id='$id2'";
$result=mysqli_query($con,$sql);
$row= (mysqli_fetch_array($result,MYSQLI_ASSOC));
$file_name = $row['file_name'];
$ref_no = $row['ref_no'];
$to_name = $row['to_name'];
$confidential = $row['confidential'];
$designation = $row['designation'];
$date = $row['date'];
$solutation = $row['solutation'];
$entity = $row['entity'];
$add_1 = $row['add_1'];
$thank_you = $row['thank_you'];
$add_2 = $row['add_2'];
$yours_truly = $row['yours_truly'];
$add_3 = $row['add_3'];
$sign_name = $row['sign_name'];
$city = $row['city'];
$s_designation = $row['s_designation'];
$heading_line_1 = $row['heading_line_1'];
$encl_line_1 = $row['encl_line_1'];
$heading_line_2 = $row['heading_line_2'];
$encl_line_2 = $row['encl_line_2'];
$heading_line_3 = $row['heading_line_3'];
$encl_line_3 = $row['encl_line_3'];
$text = mysql_real_escape_string( $row['text'] );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="newstyles.css">
<script src="js/bootstrap.min.js"></script>
<script>
function show_confirm(){
return confirm("Copy is being created....");
window.location.href='index.php';
}
</script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script>
$(document).ready(function() {
$("#date").datepicker({
dateFormat: "yy-mm-dd"
}).datepicker();
});
</script>
</head>
<body>
<form action="edit4.php?id=<?php echo $id; ?>" method="POST" >
<table border="0" class="DivTableBorder" width="840px">
<tr>
<td class="DivSubHeaderCellTop" colspan="6">Letters</td>
</tr> <tr> </td> </tr>
<tr>
<td class="DivCellText" width="80px">File Name </td>
<td class="DivCellText" width="480px" colspan="3"><input name="file_name" type="text" id="file_name"
value="<?php echo !empty($file_name)?$file_name:'';?>" class="inputRemarks" />
</td>
<td class="DivCellText" width="80px">Referance #</td>
<td class="DivCellText" width="200px"><input name="ref_no" type="text" id="ref_no"
value="<?php echo !empty($ref_no)?$ref_no:'';?>" class="inputRemarks" />
</td> </tr>
<tr ><td bgcolor="#999999" colspan="4"></td>
<td class="DivCellText" width="80px"></td>
<td class="DivCellText" width="200px"></td>
</tr>
<tr>
<td class="DivCellText" width="80px">To - Name</td>
<td class="DivCellText" colspan="3"><input name="to_name" type="text" id="to_name"
value="<?php echo !empty($to_name)?$to_name:'';?>" class="inputRemarks" />
</td>
<td class="DivCellText" width="80px">Confidential</td>
<td class="DivCellText" width="200px">
<?php if($confidential == "on"){ ?>
<input name="confidential" type="checkbox" checked="checked" id="confidential" value="on" />
<?php }else{ ?>
<input name="confidential" type="checkbox" id="confidential" value="on" />
<?php } ?>
</td> </tr>
<tr>
<td class="DivCellText" width="80px"> Designation</td>
<td class="DivCellText" colspan="3"><input name="designation" type="text" id="designation"
value="<?php echo !empty($designation)?$designation:'';?>" class="inputRemarks" />
</td>
<td class="DivCellText" width="80px">Date :</td>
<td class="DivCellText" width="200px">
<input name="date" type="text" id="date" value="<?php echo $date; ?>" />
</td> </tr>
<tr>
<td class="DivCellText" > </td>
<td class="DivCellText" colspan="3"> </td>
<td class="DivCellText" width="80px">Solutation</td>
<td class="DivCellText" width="200px" >
<select name='solutation' id='solutation' size='1' STYLE='width: 95%' value="<?php echo !empty($solutation)?$solutation:'';?>" >
<option value='Others' >[--Others--]</option>
<option value='Dear Sir' >Dear Sir</option>
<option value='Madam' >Madam</option>
</select>
</td> </tr>
<tr>
<td class="DivCellText" width="80px"> Entity</td>
<td class="DivCellText" colspan="3"><input name="entity" type="text" id="entity"
value="<?php echo !empty($entity)?$entity:'';?>" class="inputRemarks" />
</td>
<td class="DivCellText" width="80px"> </td>
<td class="DivCellText" width="200px" >
<input name="txtSolutation" type="text" id="txtSolutation"
value="" class="inputRemarks" />
</td> </tr>
<tr>
<td class="DivCellText" width="80px"> Add-1</td>
<td class="DivCellText" colspan="3"><input name="add_1" type="text" id="add_1"
value="<?php echo !empty($add_1)?$add_1:'';?>" class="inputRemarks" />
</td>
<td class="DivCellText" width="80px">Thank You.</td>
<td class="DivCellText" width="200px" ><input name="thank_you" type="text" id="thank_you"
value="<?php echo !empty($thank_you)?$thank_you:'';?>" class="inputRemarks" />
</td>
</tr>
<tr>
<td class="DivCellText" width="80px"> Add-2</td>
<td class="DivCellText" colspan="3"><input name="add_2" type="text" id="add_2"
value="<?php echo !empty($add_2)?$add_2:'';?>" class="inputRemarks" />
</td>
<td class="DivCellText" width="80px">Yours truly</td>
<td class="DivCellText" width="200px" >
<select name='yours_truly' id='yours_truly' size='1' STYLE='width: 95%' value="<?php echo !empty($yours_truly)?$yours_truly:'';?>" >
<option value='1' >Yours truly</option>
<option value='2' >Regards</option>
</select>
</td> </tr>
<tr>
<td class="DivCellText" width="80px"> Add-3</td>
<td class="DivCellText" colspan="3"><input name="add_3" type="text" id="add_3"
value="<?php echo !empty($add_3)?$add_3:'';?>" class="inputRemarks" />
</td>
<td class="DivCellText" width="80px">Signature-Name</td>
<td class="DivCellText" width="200px" >
<select name='sign_name' id='sign_name' size='1' style='width:95%' value="<?php echo !empty($sign_name)?$sign_name:'';?>">
<option value='1' >Adnan Afaq</option>
<option value='2' >Muhammad Shahzad Saleem</option>
<option value='3' >Adnan Dilawar</option>
<option value='4' >Rana Muhammad Nadeem</option>
<option value='5' >Jhangeer Hanif</option>
</select>
</td> </tr>
<tr>
<td class="DivCellText" width="80px"> City</td>
<td class="DivCellText" colspan="3"><input name="city" type="text" id="city"
value="<?php echo !empty($city)?$city:'';?>" class="inputRemarks" />
</td>
<td class="DivCellText" width="80px">S-Designation</td>
<td class="DivCellText" width="200px">
<select name='s_designation' id='s_designation' size='1' STYLE='width: 95%' value="<?php echo !empty($s_designation)?$s_designation:'';?>" >
<option value='1' >Managing Director</option>
<option value='2' >Chief Operating Officer</option>
<option value='3' >Manager Ratings</option>
<option value='4' >Unit Head Ratings</option>
</select>
</td>
</tr>
<tr>
<td class="DivCellText" width="80px">Heading Line-1</td>
<td class="DivCellText" width="480px" colspan="3"><input name="heading_line_1" type="text" id="heading_line_1"
value="<?php echo !empty($heading_line_1)?$heading_line_1:'';?>" class="inputRemarks" maxlength="55"/>
</td>
<td class="DivCellText" width="80px">Encl: Line-1</td>
<td class="DivCellText" width="200px" >
<input name="encl_line_1" type="text" id="encl_line_1" value="<?php echo !empty($encl_line_1)?$encl_line_1:'';?>" class="inputRemarks" />
</td>
</tr>
<tr>
<td class="DivCellText" width="80px">Heading Line-2</td>
<td class="DivCellText" width="480px" colspan="3"><input name="heading_line_2" type="text" id="heading_line_2"
value="<?php echo !empty($heading_line_2)?$heading_line_2:'';?>" class="inputRemarks" maxlength="55" />
</td>
<td class="DivCellText" width="80px"> Line-2</td>
<td class="DivCellText" width="200px" >
<input name="encl_line_2" type="text" id="encl_line_2" value="<?php echo !empty($encl_line_2)?$encl_line_2:'';?>" class="inputRemarks" />
</tr>
<tr>
<td class="DivCellText" width="80px">Heading Line-3</td>
<td class="DivCellText" width="480px" colspan="3"><input name="heading_line_3" type="text" id="heading_line_3"
value="<?php echo !empty($heading_line_3)?$heading_line_3:'';?>" class="inputRemarks" maxlength="55" />
</td>
<td class="DivCellText" width="80px"> Line-3</td>
<td class="DivCellText" width="200px">
<input name="encl_line_3" type="text" id="encl_line_3" value="<?php echo !empty($encl_line_3)?$encl_line_3:'';?>" class="inputRemarks" />
</td>
</tr>
<tr ><td bgcolor="#999999" colspan="6"></td></tr>
<tr ><td colspan="6">
<table border="0" class="DivTableBorder" width="840px">
<tr>
<td class="DivCellText" colspan="4">
<textarea rows="20" cols="100" id="text" name="text" style="font-size:14px;" > <?php echo !empty(nl2br($text))?(nl2br($text)):'';?> </textarea><td>
</tr>
<tr>
<td width="100"><input type="submit" name="submit" value="Create Copy" onclick="return show_confirm();" class="blueButton"></input></td>
<td width="100"><input type="reset" name="reset" value="Cancel" class="blueButton" /> </td>
<td width="100">
<input type="submit" name="submit" value="Save" class="blueButton"></input>
</td>
<td width="303"> <input type="submit" name="submit" value="Update" class="blueButton"> </input> </td>
<td width="209">
<a class="btn" href="index.php">Back</a> </td>
</tr>
</table>
</form>
<?php
$_POST['submit']="";
if($_POST['submit'] == "Create Copy"){
$connection = mysql_connect("localhost", "root", ""); // Establishing Connection with Server
$db = mysql_select_db("pacra1", $connection); // Selecting Database from Server
if(isset($_POST['submit'])){ // Fetching variables of the form which travels in URL
$file_name = $_POST['file_name'];
$ref_no = $_POST['ref_no'];
$to_name = $_POST['to_name'];
$confidential = $_POST['confidential'];
$designation = $_POST['designation'];
$date = $_POST['date'];
$solutation = $_POST['solutation'];
$entity = $_POST['entity'];
$add_1 = $_POST['add_1'];
$thank_you = $_POST['thank_you'];
$add_2 = $_POST['add_2'];
$yours_truly = $_POST['yours_truly'];
$add_3 = $_POST['add_3'];
$sign_name = $_POST['sign_name'];
$city = $_POST['city'];
$s_designation = $_POST['s_designation'];
$heading_line_1 = $_POST['heading_line_1'];
$encl_line_1 = $_POST['encl_line_1'];
$heading_line_2 = $_POST['heading_line_2'];
$encl_line_2 = $_POST['encl_line_2'];
$heading_line_3 = $_POST['heading_line_3'];
$encl_line_3 = $_POST['encl_line_3'];
$text = mysql_real_escape_string( $_POST['text'] );
//$txtTitle = mysql_real_escape_string( $_POST['txtTitle'] );
//$txtRational = $_POST['txtRational'];
//Insert Query of SQL
$query = mysql_query("INSERT INTO test(file_name, ref_no, to_name, confidential, designation, date, solutation, entity, add_1, thank_you, add_2, yours_truly, add_3, sign_name, city, s_designation, heading_line_1, encl_line_1, heading_line_2, encl_line_2, heading_line_3, encl_line_3, text)
values
('$file_name', '$ref_no', '$to_name', '$confidential', '$designation', '$date', '$solutation', '$entity', '$add_1', '$thank_you', '$add_2', '$yours_truly', '$add_3', '$sign_name', '$city', '$s_designation', '$heading_line_1', '$encl_line_1', '$heading_line_2', '$encl_line_2', '$heading_line_3', '$encl_line_3', '$text')");
echo "<br/><br/><span>Data Inserted successfully...!!</span>";
}
else{
echo "<p>Insertion Failed <br/> Some Fields are Blank....!!</p>";
}
//mysql_close($connection); // Closing Connection with Server
}
?>
</body>
</html>
You should change your php echo code as you dont need to include the !empty verification. If you do then you will have to create that before you echo the textbox. I suggest you change your code to this:
<textarea rows="20" cols="100" id="text" name="text" style="font-size:14px;" > <?php echo nl2br($text);?> </textarea><td>
You can also find some documentation of the nl2br here :
http://php.net/manual/en/function.nl2br.php
Upon inserting to the database, apply the nl2br - as you are likely to be presenting that data as text on a page more often than an textarea.
$mysql->real_escape_string(trim(nl2br($_POST['text'])))
Where $mysql is the mysqli database connection
Disclaimer As Bartdude mentioned, this is not especially good practice, since the information in the database should be as free from tags as possible - however, if this data is to be used in HTML pages only, then this solution should work.
Then when returning the data to a textarea, simply remove the <br> tags, the newline characters will be there anyway and should be interpreted by the browser correctly.
str_replace("<br>", " ", $row['text'])
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'm having a hard time figuring this out. Tried everything, yet nothing seems to work. I even have two similar pages and the other inserts and updates just fine but this has been giving me sleepless nights.
After filling form entries and submitting, there's a confirmation that the record has been added but nothing is inserted into the database table. This is supposed to be part of an app for a clinic to deal with maternity/anc/pnc but this problem affects only the anc files. The pnc part of it works pretty well.
I'm certain you guys can help me see exactly what I'm not doing right and I truly would appreciate any assistance. Right or wrong.
First here's the file that's supposed to insert the records, called submitanc.php:
#$cid= $_POST["cid"];
#$card= $_POST["card"];
#$date= $_POST["date"];
#$doctor= $_POST["doctor"];
#$riskfactor= $_POST["riskfactor"];
#$cycle= $_POST["cycle"];
#$lmp= $_POST["lmp"];
#$edd= $_POST["edd"];
#$gestationage= $_POST["gestationage"];
#$visit= $_POST["visit"];
#$parity= $_POST["parity"];
#$bp= $_POST["bp"];
#$height= $_POST["height"];
#$weight= $_POST["weight"];
#$gestation= $_POST["gestation"];
#$fhh= $_POST["fhh"];
#$sickling= $_POST["sickling"];
#$hb= $_POST["hb"];
#$hb36wk= $_POST["hb36wk"];
#$vdll= $_POST["vdll"];
#$pmtct= $_POST["pmtct"];
#$arv= $_POST["arv"];
#$tt= $_POST["tt"];
#$itw= $_POST["itw"];
#$ipt= $_POST["ipt"];
#$referredto= $_POST["referredto"];
#$diagnosis= $_POST["diagnosis"];
#$remark= $_POST["remark"];
require_once 'conn.php';
if (isset($_POST['submit']))
{
switch ($_POST['submit'])
{
case 'Add Record':
if (Trim($card) != "" and Trim($date) != "")
{
$query_insert = "Insert into `anc` (`Card Number`, `Date`, `Physician`, `Risk Factor`, `Cycle`, `LMP`, `Edd`, `Gestation Age`, `Visit`, `Parity`, `BP`, `Height`, `Weight`, `Gestation`, `FHH`, `Sickling`, `HB#Reg`, `Temp`, `VDLL`, `PMTCT`, `ARV`,`TT`,`IPT`,`ITW`,`Referred To`,`Diagnosis` `Remark`,`SFH`,`HIV`,`Hep B`,`PH`,`Urine`,`Presentation`,`Lie`)
VALUES ('$card', '$date', '$doctor', '$riskfactor', '$cycle', '$lmp', '$edd', '$gestationage', '$visit', '$parity', '$bp', '$height', '$weight', '$gestation', '$fhh', '$sickling', '$hb', '$temp', '$vdll', '$pmtct', '$arv','$tt','$ipt','$itw','$referredto','$diagnosis', '$remark','$sfh','$hiv','$hepb','$ph','$urine','$presentation','$lie')"; $result_insert = mysql_query($query_insert);
And here, I know its crazy, but this is the form page, called anc.php:
<form action="submitanc.php" method="post">
<fieldset id="fieldset">
<legend><b><font size="2" face="Tahoma" color="green">Ante-Natal Basics</font></b></legend>
<div align="left">
<TABLE width='99%' border='0' cellpadding='1' cellspacing='1' align='center' bordercolor="#005B00" id="">
<tr>
<td width="20%">
<b><font face="Verdana" style="font-size: 9pt">Date of Visit:</font></b>
</td>
<td>
<input type="hidden" size="20" name="card" value="<?php echo $card; ?>">
<input type="hidden" size="20" name="cid" value="<?php echo $idx; ?>">
<?php
if (!$idx)
{ ?>
<input id="inputField" type="text" size="20" name="date" value="<?php echo date('Y-m-d'); ?>">
<?php
} else
{ ?>
<input id="inputField" type="text" size="20" name="date" value="<?php echo $srow['Date']; ?>">
<?php } ?>
</td>
<td width="20%">
<b><font face="Verdana" style="font-size: 9pt">Name of Doctor/Midwife:</font></b>
</td>
<td>
<input type="text" size="20" name="doctor" value="<?php echo $srow['Physician']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Major Risk Factor:</font></b>
</td>
<td colspan='3'>
<textarea cols="40" rows="3" name="riskfactor"><?php echo $srow['Risk Factor']; ?></textarea>
</td>
</tr>
</table>
</fieldset>
<fieldset id="fieldset">
<legend><b><font size="2" face="Tahoma" color="green">Menstrual History</font></b></legend>
<div align="left">
<TABLE width='99%' border='0' cellpadding='1' cellspacing='1' align='center' bordercolor="#005B00" id="">
<tr>
<td width="20%">
<b><font face="Verdana" style="font-size: 9pt">Cycle:</font></b>
</td>
<td>
<input type="text" size="20" name="cycle" value="<?php echo $srow['Cycle']; ?>">
</td>
<td width="20%">
<b><font face="Verdana" style="font-size: 9pt">Last Mentrual Period (L.M.P):</font></b>
</td>
<td>
<input type="text" size="20" name="lmp" value="<?php echo $srow['LMP']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Expected Delivery Date (E.D.D):</font></b>
</td>
<td>
<input type="text" size="20" name="edd" value="<?php echo $srow['EDD']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Gestation Age at Booking:</font></b>
</td>
<td>
<input type="text" size="20" name="gestationage" value="<?php echo $srow['Gestation Age']; ?>">
</td>
</tr>
</TABLE>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#dcdfdf" width="100%" id="AutoNumber1">
<?php
echo "<TR bgcolor='#9ff4ae'><TH><b><u>LMP </b></u> </TH><TH><b><u>EDD </b></u> </TH><TH><b><u>EGA to Date</b></u> </TH></TR>";
$querya="SELECT `ID`,`Card Number`,`Date`,`LMP`,`EDD`,`Gestation Age` FROM `anc` WHERE `Card Number`='$card' order by `Date` desc";
$resulta=mysql_query($querya);
while(list($idx,$cart,$date,$lmp,$edd,$ega)=mysql_fetch_row($resulta))
{
echo "<TR><TH><a title='Click on this to amend it' href = 'anc.php?idx=" . $idx . "&card=" . $cart . "&dat=" . $date . "'>$lmp </a> </TH><TH> $edd </TH><TH>$ega </font></TH></TR>";
}
?>
</table>
</fieldset>
<fieldset id="fieldset">
<legend><b><font size="2" face="Tahoma" color="green">Ante-Natal Examination</font></b></legend>
<div align="left">
<TABLE width='99%' border='0' cellpadding='1' cellspacing='1' align='center' bordercolor="#005B00" id="">
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Blood Pressure:</font></b>
</td>
<td>
<input type="text" size="20" name="bp" value="<?php echo $srow['BP']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Parity:</font></b>
</td>
<td>
<input type="text" size="20" name="parity" value="<?php echo $srow['Parity']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Weight:</font></b>
</td>
<td>
<input type="text" size="20" name="weight" value="<?php echo $srow['Weight']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Temperature:</font></b>
</td>
<td>
<input type="text" size="20" name="temp" value="<?php echo $srow['Temp']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Visit:</font></b>
</td>
<td>
<select size="1" name="visit">
<?php
echo '<option selected>' . $srow['Visit'] . '</option>';
echo '<option>New Visit</option>';
echo '<option>Returning Visit</option>';
?>
</select>
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Height:</font></b>
</td>
<td>
<input type="text" size="20" name="height" value="<?php echo $srow['Height']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Gestational Age:</font></b>
</td>
<td>
<input type="text" size="20" name="gestation" value="<?php echo $srow['Gestation']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">SFH:</font></b>
</td>
<td>
<input type="text" size="20" name="sfh" value="<?php echo $srow['SFH']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Sickling:</font></b>
</td>
<td>
<input type="text" size="20" name="sickling" value="<?php echo $srow['Sickling']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Hb:</font></b>
</td>
<td>
<input type="text" size="20" name="hb" value="<?php echo $srow['HB#Reg']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">HIV:</font></b>
</td>
<td>
<input type="text" size="20" name="hiv" value="<?php echo $srow['HIV']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Hep B:</font></b>
</td>
<td>
<input type="text" size="20" name="hepb" value="<?php echo $srow['HepB']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">PH:</font></b>
</td>
<td>
<input type="text" size="20" name="ph" value="<?php echo $srow['PH']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Urine:</font></b>
</td>
<td>
<input type="text" size="20" name="urine" value="<?php echo $srow['Urine']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Presentation:</font></b>
</td>
<td>
<input type="text" size="20" name="presentation" value="<?php echo $srow['Presentation']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Lie:</font></b>
</td>
<td>
<input type="text" size="20" name="lie" value="<?php echo $srow['Lie']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">FHR:</font></b>
</td>
<td>
<input type="text" size="20" name="fhh" value="<?php echo $srow['FHH']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Sickling:</font></b>
</td>
<td>
<input type="text" size="20" name="sickling" value="<?php echo $srow['Sickling']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">VDLL:</font></b>
</td>
<td>
<input type="text" size="20" name="vdll" value="<?php echo $srow['VDLL']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">PMTCT:</font></b>
</td>
<td>
<?php
$sqlv2 = "SELECT `val`,`type` FROM `booln` ORDER BY `type` desc";
$result_v2 = mysql_query($sqlv2,$conn) or die('Could not list; ' . mysql_error());
$v2=$srow['PMTCT'];
while ($rows = mysql_fetch_array($result_v2))
{
echo ' <input type="radio" class="radio" align="left" id="v2_' . $rows['val'] . '" name="pmtct" value="' . $rows['val'] . '" ';
if ($rows['val'] == $v2)
{
echo 'checked="checked" ';
}
echo '/>' . $rows['type'] . "\n";
}
?>
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">ARV:</font></b>
</td>
<td>
<input type="text" size="20" name="arv" value="<?php echo $srow['ARV']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">TT:</font></b>
</td>
<td>
<input type="text" size="20" name="tt" value="<?php echo $srow['TT']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">ITW:</font></b>
</td>
<td>
<input type="text" size="20" name="itw" value="<?php echo $srow['ITW']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">IPT:</font></b>
</td>
<td>
<?php
$sqlv2 = "SELECT `val`,`type` FROM `booln` ORDER BY `type` desc";
$result_v2 = mysql_query($sqlv2,$conn) or die('Could not list; ' . mysql_error());
$v2=$srow['IPT'];
while ($rows = mysql_fetch_array($result_v2))
{
echo ' <input type="radio" class="radio" align="left" id="v2_' . $rows['val'] . '" name="ipt" value="' . $rows['val'] . '" ';
if ($rows['val'] == $v2)
{
echo 'checked="checked" ';
}
echo '/>' . $rows['type'] . "\n";
}
?>
</td>
</tr>
<tr>
<td width="15%">
<b><font face="Verdana" style="font-size: 9pt">Refered To:</font></b>
</td>
<td>
<input type="text" size="20" name="referredto" value="<?php echo $srow['Referred To']; ?>">
</td>
<td width="15%">
<b><font face="Verdana" style="font-size: 9pt">Diagnosis:</font></b>
</td>
<td>
<input type="text" size="20" name="diagnosis" value="<?php echo $srow['Diagnosis']; ?>">
</td>
</tr>
<tr>
<td width="14%">
<b><font face="Verdana" style="font-size: 9pt">Remark:</font></b>
</td>
<td colspan='3'>
<textarea cols="40" rows="3" name="remark"><?php echo $srow['Remark']; ?></textarea>
</td>
</tr>
<tr>
<td width="10%">
<?php
if (!$idx)
{ ?>
<input type="submit" value="Add Record" name="submit">
<?php
} else
{ ?>
<input type="submit" value="Update Record" name="submit">
<?php } ?>
</td>
</tr>
</TABLE>
</form>
</fieldset>
<fieldset style="padding: 2">
<legend><b><font size="2" face="Tahoma" color="green">History of ANC</font></b></legend>
<b><font color="#FF0000" style="font-size: 8pt"><?php echo $tval ; ?></font></b>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#dcdfdf" width="99%" id="AutoNumber1">
<?php
echo "<TR bgcolor='#9ff4ae'><TH><b><u>Date of Visit </b></u> </TH><TH><b><u>Weight </b></u> </TH><TH><b><u>BP</b></u> </TH><TH><b><u>SFH </b></u> </TH><TH><b><u>Urine </b></u> </TH><TH><b><u>FHR </b></u> </TH></TR>";
$query="SELECT `ID`,`Card Number`,`Date`,`Weight`,`BP`,`SFH`,`Urine`,`FHR` FROM `anc` WHERE `Card Number`='$card' order by `Date` desc";
$result=mysql_query($query);
while(list($idx,$cart,$date,$wt,$bp,$sfh,$urine,$fhr)=mysql_fetch_row($result))
{
echo "<TR><TH><a title='Click on this to amend it' href = 'anc.php?idx=" . $idx . "&card=" . $cart . "&dat=" . $date . "'>$date </a> </TH><TH> $wt </TH><TH>$bp </font></TH><TH>$sfh </TH><TH>$urine </TH><TH>$fhr </TH></TR>";
}
?>
</table>
</fieldset>
its better to use
mysql_escape_string($_POST['fieldname']);
and echo that query and check in mysql
$query_insert = "Insert into `anc` (`Card Number`, `Date`, `Physician`, `Risk Factor`, `Cycle`, `LMP`, `Edd`, `Gestation Age`, `Visit`, `Parity`, `BP`, `Height`, `Weight`, `Gestation`, `FHH`, `Sickling`, `HB#Reg`, `Temp`, `VDLL`, `PMTCT`, `ARV`,`TT`,`IPT`,`ITW`,`Referred To`,`Diagnosis` `Remark`,`SFH`,`HIV`,`Hep B`,`PH`,`Urine`,`Presentation`,`Lie`)
VALUES ('$card', '$date', '$doctor', '$riskfactor', '$cycle', '$lmp', '$edd', '$gestationage', '$visit', '$parity', '$bp', '$height', '$weight', '$gestation', '$fhh', '$sickling', '$hb', '$temp', '$vdll', '$pmtct', '$arv','$tt','$ipt','$itw','$referredto','$diagnosis', '$remark','$sfh','$hiv','$hepb','$ph','$urine','$presentation','$lie')"; $result_insert = mysql_query($query_insert);
$res=mysql_query($query_insert);
if(!$res){
die('Could not enter data: ' . mysql_error());
}
//Confirm success with the username
echo '<p><b>Your MSG</b></p>';
}
then give the successfull msg . and figure where its goin wrong
The problem here is that when I want to submit the form, it will return to its original state (empty form). There are 2 parts in the form where user have to type in the input and also to upload files.
Here is the form..
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Application for Paper Presentation</title>
<script>
function checkFile(grabObj)
{
var sFileName = grabObj.value;
var sFileExt = sFileName.split('.')[sFileName.split('.').length - 1].toLowerCase();
var iFileSize = grabObj.file[0].size;
var iConvert=(iFileSize/1048576).toFixed(2);
if (sFileExt!= "pdf" &&
sFileExt != "doc" &&
sFileExt != "docx") || iFileSize > 1048576)
{
txt="File type : "+ sFileExt +"\n\n";
txt+="Size: " + iConvert + " MB \n\n";
txt+="Please make sure your file is in pdf or doc format and less than 10 MB.\n\n";
alert(txt);
}
}
</script>
</head>
<body><br />
<form action="student_newSubmission.php" method="post" enctype="multipart/form-data">
<center>
<fieldset style="width:500px; background-color: #FFC"><legend align="center" style="font-size:24px">Application for Paper Presentation</legend>
<br>
<?php
$sql=oci_parse($conn,"SELECT * FROM student WHERE matricno='".$_SESSION['id']."'");
$result=oci_execute($sql);
$row=oci_fetch_array($sql,OCI_ASSOC+OCI_RETURN_NULLS);
$stfID=$row['SUPERVISOR'];
$stfID2=$row['COSUPERVISOR'];
//================================
$sql2=oci_parse($conn,"SELECT * FROM staff WHERE staffID='".$stfID."'") or die(oci_error());
$result2=oci_execute($sql2);
$row2=oci_fetch_array($sql2,OCI_ASSOC+OCI_RETURN_NULLS);
$stfname=$row2['STFNAME'];
$sql3=oci_parse($conn,"SELECT * FROM staff WHERE staffID='".$stfID2."'") or die(oci_error());
$result3=oci_execute($sql3);
$row3=oci_fetch_array($sql3,OCI_ASSOC+OCI_RETURN_NULLS);
$stfname2=$row3['STFNAME'];
?>
<table width="1023" cellpadding="2" cellspacing="2">
<tr>
<td width="160"><strong>First Name : </strong></td><td><?php echo $row['FNAME']; ?></td>
<td width="160"><strong>Last Name : </strong></td><td><?php echo $row['LNAME']; ?></td>
</tr>
<tr>
<td><strong>Sponsor : </strong></td><td width="374"><input name="sponsor" type="text" size="50" style="text-transform:uppercase" required value=""></td>
<td><strong>Admission Date : </strong></td><td width="309"><?php echo $row['ADMISSIONDATE']; ?></td>
</tr>
<tr>
<td><strong>Matric No : </strong></td><td width="374"><?php echo $row['MATRICNO']; ?><input type="hidden" name="matricno" value="<?php echo $row['MATRICNO']; ?>" /> </td>
<td><strong>Email Address :</strong></td><td width="309"><?php echo $row['EMAIL']; ?> </td>
</tr>
<tr>
<td><strong>Programme / Sem : </strong></td><td width="374"> <?php echo $row['PROGRAMME']; ?> / <?php echo $row['SEM']; ?>
<td><strong>Phone No.</strong></td><td width="309"><?php echo $row['PHONE']; ?> </td>
</tr>
<tr>
<td width="160"><strong>Field of Study : </strong></td><td colspan="3"><input name="field" type="text" size="140" style="text-transform: uppercase"> </td>
</tr>
<tr>
<td><strong>Supervisor : </strong></td><td width="374"><?php echo $stfname ?></td>
<td><strong>Co-supervisor : </strong></td><td width="309"><?php echo $stfname2; ?></td>
</tr>
</table>
<br />
<fieldset style="width:500px; background-color: #FFC"><legend align="center"> Program Detail </legend>
<table width="833" cellpadding="2" cellspacing="2">
<tr>
<td width="431"><strong> Title of Paper : </strong></td><td width="386"><input name="papertitle" type="text" size="50" style="text-transform: uppercase" required value=""></td>
</tr>
<tr>
<td><strong> Author/ Co. Author : <br />( Please separate using semicolon ' ; ' )</strong></td><td width="386"><textarea name="author" cols="38" rows="3" style="text-transform: uppercase; resize:none" required value=" "></textarea></td>
</tr>
<tr>
<td><strong> Title of Conference : </strong></td><td width="386"><input name="conftitle" type="text" size="50" style="text-transform: uppercase" required value=""></td>
</tr>
<tr>
<td><strong> Organizer : </strong></td><td width="386"><input name="organizer" type="text" size="50" style="text-transform: uppercase"></td>
</tr>
<tr>
<td><strong> Address : </strong></td><td width="386"><textarea name="address" cols="38" id="address" style="text-transform: uppercase; resize:none"></textarea></td>
</tr>
<tr>
<td><strong> Tel/Fax : </strong></td><td width="386"><input name="tel" type="text" size="50"></td>
</tr>
<tr>
<td><strong> Venue : </strong></td><td width="386"><input name="venue" type="text" size="50" style="text-transform: uppercase"></td>
</tr>
<tr>
<td><strong> Date : (dd/mm/YY)</strong></td><td width="386"><input name="confDate" type="text" size="50" style="text-transform: uppercase" ></td>
</tr>
<tr>
<td><strong> Conference / Journal Fees : </strong></td><td width="386"><input name="fee" type="text" size="50" style="text-transform: uppercase"></td>
</tr>
</table>
</fieldset>
<br />
</fieldset>
<br/>
<fieldset style="width:500px; background-color: #FFC"><legend align="center" style="font-size:24px">Upload file</legend>
<p style="color:#F00"> ( Please take note to name your files accordingly and save as .pdf or .doc ) </p>
<table width="809" cellpadding="2" cellspacing="2">
<tr>
<td width="341"><label for="file">Turnitin Similarity Report :</label></td>
<td width="452"><input type="file" name="userfile[]" id="turnitin" onchange="checkFile(this)" required value=""></td>
</tr>
<tr>
<td width="341"><label for="file">Paper Indexing :</label></td>
<td width="452"><input type="file" name="userfile[]" id="paperIndex" onchange="checkFile(this)" > <br />/ Link : <input type="text" name="paperindexurl" size="30" /></td>
</tr>
<tr>
<td width="341"><label for="file">Camera Ready Paper (full) :</label></td>
<td width="452"><input type="file" name="userfile[]" id="cameraReady" onchange="checkFile(this)" required value=""></td>
</tr>
<tr>
<td width="341"><label for="file">Blind Paper (withour author info) :</label></td>
<td width="452"><input type="file" name="userfile[]" id="blindPaper" onchange="checkFile(this)" required value=""></td>
</tr>
<tr><td colspan="2">========================= Extra for Journal Publication =========================</td></tr>
<tr>
<td width="341"><label for="file">Acceptance Letter from Publisher:</label></td>
<td width="452"><input type="file" name="userfile[]" id="acceptLetter" onchange="checkFile(this)"></td>
</tr>
<tr>
<td width="341"><label for="file">Publisher's Reviewers Report :</label></td>
<td width="452"><input type="file" name="userfile[]" id="reviewerReport" onchange="checkFile(this)"></td>
</tr>
<tr>
<td width="341"><label for="file">Paper Submitted Version :</label></td>
<td width="452"><input type="file" name="userfile[]" id="submittedVersion" onchange="checkFile(this)"></td>
</tr>
<tr>
<td width="341"><label for="file">Published Conference Paper :</label></td>
<td width="452">Link : <input type="text" name="confPaperurl" size="30"/></td>
</tr>
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input type="hidden" name="submissionDate" required value="<?php echo date("d-M-Y"); ?>" />
</table>
</fieldset><br />
<input type="submit" value="Submit the form" id="submit" align="center">
</center>
</form>
</body>
</html>
and here is the student_newSubmission.php
<?php
// Inialize session
session_start();
$conn = oci_connect("system","db","localhost/XE")or die(oci_error());
//require_once('connection.php');
?>
<?php
if(isset($_POST['submit']) && !empty($_POST['submit']))
{
$matricNo = $_POST['matricno'];
$submissionDate = $_POST['submissionDate'];
$sponsor = $_POST['sponsor'];
$field = $_POST['field'];
$papertitle = $_POST['papertitle'];
$author = $_POST['author'];
$conftitle = $_POST['conftitle'];
$organizer = $_POST['organizer'];
$address = $_POST['address'];
$tel = $_POST['tel'];
$venue = $_POST['venue'];
$confDate = $_POST['confDate'];
$fee = $_POST['fee'];
$paperIndexUrl = $_POST['paperindexurl'];
$confPaperUrl = $_POST['confPaperurl'];
$query = oci_parse($conn,"INSERT INTO submission(subID, matricNo, submissionDate, sponsor, field, papertitle, author, conftitle, organizer, orgaddress, orgtel, venue, confDate, fee, paperindexurl, confpaperurl) VALUES (seq_subID.nextval, '$matricNo', '$submissionDate', '$sponsor', '$field', '$papertitle', '$author', '$conftitle', '$organizer', '$address', '$tel', '$venue', '$confDate', '$fee', '$paperIndexUrl', '$confPaperUrl')") or die(oci_error());
$exe= oci_execute($query);
if($exe==1)
{
$query2 = oci_parse($conn, "SELECT subID FROM submission WHERE matricNo='".$matricNo."' ORDER BY submissionDate")or die(oci_error());
$exe2 = oci_execute($query2);
$row = oci_fetch_array($query2);
$subID = $row['SUBID'];
}
else
{
echo '<script type="text/javascript">';
echo 'alert("There was an error while uploading your form. Please try again.")';
echo '</script>';
}
if(isset($_POST['submit']) && $_FILES['userfile']['size'] > 0)
{
$count=0;
foreach ($_FILES['userfile']['name'] as $filename)
{
$fileName = $_FILES['userfile']['name'][$count];
$tmpName = $_FILES['userfile']['tmp_name'][$count];
$fileSize = $_FILES['userfile']['size'][$count];
$fileType = $_FILES['userfile']['type'][$count];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
$query3 = oci_parse($conn,"INSERT INTO upload (uploadID, uploadname, uploadtype, uploadsize, content, subID) VALUES (seq_uploadID.nextval, '$fileName', '$fileType', '$fileSize', '$content', '$subID')");
$exe3 = oci_execute($query) or die('Error, query failed');
$count=$count + 1;
}
//echo "<br>File $fileName uploaded<br>";
}
if ($exe3 == 1)
{
header('location:homeStudent.php');
echo '<script type="text/javascript">';
echo 'alert ("Successfully submit your form!")';
echo '</script>';
}
else
{
echo '<script type="text/javascript">';
echo 'alert("There was an error while uploading your form. Please try again.")';
echo '</script>';
}
}
?>
I've try comment the file upload process and just proceed with the type-in process.. but it still return without do anything. I hope it can show some error so I can fix. When it returns empty I also feel empty.
Can someone help me. I really dont know how to proceed.
You're using if(isset($_POST['submit']) and this is looking for a button named "submit", where you have:
<input type="submit" value="Submit the form" id="submit" align="center">
which should read as:
<input type="submit" name="submit" value="Submit the form" id="submit" align="center">
---------------------^^^^^^^^^^^^^
Cant work. If i understood your code right, you send the data via $_POST to student_newSubmission.php. Then you locate via "header" back to your old page, but you dont send the $_POST with it. You have to save the data send to the student_newSubmission and send it back to the other page. $_POST gets deleted after every script, you cant use it so save informations permanently. You have to use either $_COOKIE or $_SESSION for it.
I've got the sessions working to display the child information, I now want to be able to edit that information and update the database. I've tried every youtube video and website but nothing uses $_SESSION they all use $_POST.
<div class="post">
<h1 class="title">Child Details: </h1>
<p class="title"><img src=" <?php echo "".$_SESSION['sourcepath']; ?>"
</p>
<p class="title"><?php echo "".$_SESSION['ChildID']; ?></p>
<table style="width: 100%">
<tr>
<td style="width: 106px">Name</td>
<td style="width: 252px"><?php echo "".$_SESSION ['Firstname']; ?> <?php echo "".$_SESSION['Surname']; ?></td>
<td style="width: 94px">School</td>
<td><form method="post">
<br />
<textarea name="School" cols="20" rows="5"><?php echo "".$_SESSION['School']; ?></textarea></form>
</td>
</tr>
<tr>
<td style="width: 106px">Date of Birth</td>
<td><?php echo "".$_SESSION['DateOfBirth']; ?></td>
<td style="width: 94px">English</td>
<td><form method="post">
<br />
<textarea name="English" cols="20" rows="5"><?php echo "".$_SESSION['English']; ?></textarea></form>
</td>
</tr>
<tr>
<td style="width: 106px">Age</td>
<td><?php echo "".$_SESSION['Age']; ?>;</td>
<td style="width: 94px">Science</td>
<td><form method="post">
<br />
<textarea name="Science" cols="20" rows="5"><?php echo "".$_SESSION['Science']; ?></textarea></form>
</td>
</tr>
<tr>
<td style="width: 106px">Address</td>
<td><form method="post">
<br />
<textarea name="Address" cols="20" style="height: 89px"><?php echo "".$_SESSION['Address']; ?></textarea></form>
</td>
<td style="width: 94px">Maths</td>
<td><form method="post">
<br />
<textarea name="Maths" cols="20" rows="5"><?php echo "".$_SESSION['Maths']; ?></textarea></form>
</td>
</tr>
<tr>
<td style="width: 106px">Postcode:</td>
<td><?php echo "".$_SESSION['PostCode']; ?>;</td>
<td style="width: 94px">Homework</td>
<td><form method="post">
<br />
<textarea name="Homework" cols="20" rows="5"><?php echo "".$_SESSION['Homework']; ?></textarea></form>
</td>
</tr>
<tr>
<td style="width: 106px">Contact Number</td>
<td><form method="post">
<textarea name="ContactNumber" cols="20" rows="2"><?php echo "".$_SESSION['ContactNumber']; ?></textarea></form>
</td>
<td style="width: 94px">Additional</td>
<td><form method="post">
<br />
<textarea name="Additional" cols="20" rows="8"><?php echo "".$_SESSION['Additional']; ?></textarea></form>
</td>
</tr>
<tr>
<td style="width: 106px">Mother Name</td>
<td><?php echo "".$_SESSION['MotherName']; ?></td>
<td style="width: 94px"> </td>
<td> </td>
</tr>
<tr>
<td style="width: 106px"> </td>
<td> </td>
<td style="width: 94px"> </td>
<td> </td>
</tr>
<tr>
<td style="width: 106px">Last Update</td>
<td><?php echo "".$_SESSION['TimeStamp']; ?></td>
<td style="width: 94px"> </td>
<td> </td>
</tr>
<tr>
<td style="width: 106px"> </td>
<td> </td>
<td style="width: 94px"> </td>
<td> </td>
</tr>
<tr>
<td style="width: 106px">
</td>
<td>
<form method="post" action="updatetest.php">
<input type="hidden" name="id" value="<?php echo $_SESSION['ChildID']; ?>"/>
<input name="Submit" type="submit" value="Update" /></form>
</td>
<?php session_start(); ?>
<?php
$connect = mysql_connect("127.0.0.1" , "root" , "") or die ("Couldnt connect to database");
mysql_select_db("travellerfile") or die ("couldnt find the database");
$School = $_SESSION['School'];
$Maths = $_SESSION['Maths'];
$English = $_SESSION['English'];
$Science = $_SESSION['Science'];
$Homework = $_SESSION['Homework'];
$Additional = $_SESSION['Additional'];
$id = $_SESSION['ChildID'];
$q = "SELECT * FROM child WHERE ChildID = $_SESSION[ChildID]";
$result = mysql_query($q);
$person = mysql_fetch_array($result);
$u = "UPDATE child SET Maths= '$_SESSION['Maths']', Science= '$_SESSION['Science']';
?>
$_SESSION['School'] = $_POST['School'];
$School = $_SESSION['School'];
Somewhere you'll have to declare that $_SESSION['School'] contains the value of the Textarea with the name 'School'. You can't just expect PHP to put POST variables into SESSION variables
For example:
$_SESSION['ChildID'] = 5;
<form method="post" action="updatetest.php">
<input type="hidden" name="id" value="<?php echo $_SESSION['ChildID']; ?>"/>
<input name="Submit" type="submit" value="Update" /></form>
This will post you:
$_POST['id'] = 5;
So:
UPDATE table SET col = $_POST['id'];
Update $_SESSION end grab $_POST for database;
...
$School = $_['School'] = $_POST['School'];
$Maths = $_SESSION['Maths'] = $_POST['Maths'];
$English = $_SESSION['English'] = $_POST['English'];
$Science = $_SESSION['Science'] = $_POST['Science'];
$Homework = $_SESSION['Homework'] = $_POST['Homework'];
$Additional = $_SESSION['Additional'] = $_POST['Additional'];
$id = $_SESSION['ChildID'];
...
Both $_POST and $_SESSION are merely arrays. The only thing that makes them special is that they are global. So, if you have code that works for $_POST, just substitute in the corresponding $_SESSION values.
What your real issue is, is that you are submitting a form. Forms can submit using get or post methods. There is no session method. So your values are arriving at your php script in the $_POST variable. You could then copy them to the $_SESSION variable before running your update, but there's really no good reason to. The only reason they would need to be in $_SESSION is so that they can be output if the form needs to be re-displayed with the submitted values.
I am making a registration form in PHP and when submitting the form Date(Check In, for which I have used Date Picker), Combo boxes(Sex & Room No) & check box(taxi) is not getting inserted.
I have looked enough in to the code but not getting what is wrong..though other combo box and check box working just fine.
PHP Code -
<?php
$passport = $_POST['passport'];
$name = $_POST['name'];
$sex = $_POST['sex'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$country = $_POST['country'];
$contact = $_POST['contact'];
$email = $_POST['email'];
$roomNo = $_POST['roomNo'];
if(isset($_POST['food']) && $_POST['food'] == 'food')
{
$food = 'yes';
}
else
{
$food = 'no';
}
if(isset($_POST['car']) && $_POST['car'] == 'car')
{
$car = 'yes';
}
else
{
$car = 'no';
}
if(isset($_POST['others']) && $_POST['others'] == 'others')
{
$others = 'yes';
}
else
{
$others = 'no';
}
$checkIn = $_POST['checkIn'];
mysql_connect("localhost","root","");
mysql_select_db("guesthouse");
$personal_query = "INSERT INTO personal_details VALUES(
'',
'$name',
'$sex',
'$address1',
'$address2',
'$city',
'$country',
'$contact',
'$email')";
mysql_query($personal_query);
$result = mysql_affected_rows();
if($result == 1)
{
echo "Personal Details Submitted";
}
$booking_query = "INSERT INTO booking VALUES(
'',
'$name',
'$roomno',
'$food',
'$taxi',
'$others',
'$checkIn')";
mysql_query($booking_query);
$result = mysql_affected_rows();
if($result == 1) {
echo "<br/>Booking Details Submitted";
}
?>
HTML -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" media="all" href="jsDatePick_ltr.min.css" />
<script type="text/javascript" src="jsDatePick.min.1.3.js"></script>
<script type="text/javascript">
window.onload = function(){
new JsDatePick({
useMode:2,
target:"checkIn",
dateFormat:"%d-%M-%Y"
/*selectedDate:{
day:5,
month:9,
year:2006
},
yearsRange:[1978,2020],
limitToToday:false,
cellColorScheme:"beige",
dateFormat:"%m-%d-%Y",
imgPath:"img/",
weekStartDay:1*/
});
};
</script>
</head>
<form name="form1" method="post" action="registration_handle.php">
<table width="60%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" align="center" bgcolor="#0099FF">Room Reservation Details :</td>
</tr>
<tr>
<td width="33%" align="center" bgcolor="#66FFCC">Passport No </td>
<td width="67%"><label for="textfield"></label>
<input type="text" name="passport" id="passport"></td>
</tr>
<tr>
<td align="center" bgcolor="#66FFCC">Name</td>
<td><input type="text" name="name" id="name"></td>
</tr>
<tr>
<td align="center" bgcolor="#66FFCC">Sex</td>
<td><label for="select3"></label>
<select name="sex" id="sex">
<option value="" selected>Male</option>
<option value="" >Female</option>
</select></td>
</tr>
<tr>
<td align="center" bgcolor="#66FFCC">Address 1</td>
<td><input type="text" name="address1" id="address1"></td>
</tr>
<tr>
<td align="center" bgcolor="#66FFCC">Address2</td>
<td><input type="text" name="address2" id="address2"></td>
</tr>
<tr>
<td align="center" bgcolor="#66FFCC">City</td>
<td><input type="text" name="city" id="city" /></td>
</tr>
<tr>
<td align="center" bgcolor="#66FFCC">Country</td>
<td><label for="select2"></label>
<select name="country" id="country">
<?php
mysql_connect("localhost","root","");
mysql_select_db("guesthouse");
$query = "SELECT name FROM country";
$query_result = mysql_query($query);
while($result = mysql_fetch_assoc($query_result))
{
?>
<option value = "<?php echo $result['name'] ?>"><?php echo $result['name'] ?></option>
<?php
}
?>
</select></td>
</tr>
<tr>
<td align="center" bgcolor="#66FFCC">Contact No</td>
<td><input type="text" name="contact" id="contact"></td>
</tr>
<tr>
<td align="center" bgcolor="#66FFCC">E-Mail </td>
<td><input type="text" name="email" id="email"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td align="center" bgcolor="#66FFCC">Room No</td>
<td><label for="select4"></label>
<select name="roomNo" id="roomNo">
<?php
mysql_connect("localhost","root","");
mysql_select_db("guesthouse");
$query = "SELECT name FROM roomno";
$query_result = mysql_query($query);
while($result = mysql_fetch_assoc($query_result))
{
?>
<option value = "<?php echo $result['name'] ?>"><?php echo $result['name'] ?></option>
<?php
}
?>
</select></td>
</tr>
<tr>
<td align="center" bgcolor="#66FFCC">Extra Service</td>
<td><p>
<label> </label>
<input type="checkbox" name="food" value="food" />Food
<input type="checkbox" name="car" value="car" />Car
<input type="checkbox" name="others" value="others" />Others<br>
</p></td>
</tr>
<tr>
<td align="center" bgcolor="#66FFCC">Check In </td>
<td><label for="textfield3"></label>
<input type="text" size="16" name="checkIn" id="checkIn"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="button" id="button" value="Submit">
<input type="reset" name="Reset" id="Reset" value="Reset" />
<input type="submit" name="cancel" id="cancel" value="Cancel" /></td>
</tr>
</table>
</form>
</html>
value of sex is "" (if you want default, don't type value="")
-Tested-
<html>
<body>
<select onchange="alert(this.value);">
<option>Volvo</option>
<option>Saab</option>
<option value=''>Mercedes</option>
<option>Audi</option>
</select>
</body>
</html>
you never give any value to $taxi (wich is called car in your form)
You initialte $roomNo and store $roomno
--- found these errors because I tend to do same things. here's a tip, always verify your variables name first, 99% of your probs will be fixed --- (works for me :) )