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 :) )
Related
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'])
I have tried to get this working for a couple hours now, i think its related to the fact that i have a $_GET['ID']; on the first script but im not sure:
Script 1 (FORM):
<?php
require_once('db_access.php');
$editID = $_GET['id'];
$query = mysql_query("SELECT * from routes where id = '".$editID."'");
$row = mysql_fetch_assoc($query);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Form Edit Data</title>
</head>
<body>
<table border=1>
<tr>
<td align=center>Route Edit Data</td>
</tr>
<tr>
<td>
<table>
<form method="post" action="complete_edit.php">
<tr>
<td>ID #</td>
<td>
<input type="hidden" name="formid" value="<?php echo $row['id'] ?>">
</td>
</tr>
<tr>
<td>Route Name</td>
<td>
<input type="text" name="route_title" size="40"
value="<?php echo $row['route_title']?>">
</td>
</tr>
<tr>
<td>Total Price</td>
<td>
<input type="text" name="total_price" size="40"
value="<?php echo $row['total_price']?>">
</td>
</tr>
<tr>
<td>Down Payment</td>
<td>
<input type="text" name="down_payment" size="40"
value="<?php echo $row['down_payment']?>">
</td>
</tr>
<tr>
<td>Weekly Net</td>
<td>
<input type="text" name="weekly_net" size="40"
value="<?php echo $row['weekly_net']?>">
</td>
</tr>
<tr>
<td>Location</td>
<td>
<input type="text" name="location" size="40"
value="<?php echo $row['location']?>">
</td>
</tr>
<tr>
<td>Remarks</td>
<td>
<input type="text" name="remarks" size="40"
value="<?php echo $row['remarks']?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>
</body>
</html>
SCRIPT 2(PROCESSING):
<?php
$id = $_POSt['formid'];
$editroute = $_POST['route_title'];
$editprice = $_POST['total_price'];
$editdownpay = $_POST['down_payment'];
$editweeklynet = $_POST['weekly_net'];
$editlocation = $_POST['location'];
$editremarks = $_POST['remarks'];
$query = "UPDATE routes SET id = '$id', route_title = '$editroute', total_price = '$editprice', down_payment = '$editdownpay', weekly_net = '$editweeklynet', location = '$editlocation', remarks = '$editremarks' WHERE id = '$id'";
header('Location:index.php');
?>
The first lot of code is where my form is placed and the second is where the processing happens
Thanks for your help people :)
Alex
$id = $_POSt['formid'];
$_POSt is not $_POST
Im so silly after reading the comments to the question here i realised that i had no mysql_query string :)
Thanks guys for giving me my mind haha :)
Alex
"Undefined index: image in
C:\xampp\htdocs\learn_php\Category\insertup.php on line 34" this error
is showing and that line 34 is-
$path= "Image/".$_FILES["image"]["name"];
EDIT.PHP File:-
<?php
if(isset($_GET['id']) && $_GET['id'] != '') {
mysql_connect('localhost', 'root', '');
mysql_select_db('opencart_php');
$id=$_GET['id'];
$query=mysql_query("SELECT * FROM categories WHERE Id='".$id."'");
$row=mysql_fetch_array($query);
$cname = $row['category_name'];
$sname = $row['sort_order'];
$desc = $row['description'];
$image = $row['image'];
} else {
$id = '';
$cname = '';
$sname = '';
$desc = '';
$image = '';
}
?>
<!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=iso-8859-1" />
<title>Category Details</title>`
<h1 align="center">Category Details</h1>
</head>
<body>
<table width="400" border="1" align="center">
<tr>
<td><form name="myform" action="insertup.php?id=<?php echo $id; ?>" method="post" enctype="multipart/form_data">
<table width="334" border="0" align="center">
<tr>
<td><b>Category Name:</b></td>
<td><input type="text" name="cname" value="<?php echo $cname; ?>"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><b>Sort Order:</b></td>
<td><input type="text" name="sorder" size="5" value="<?php echo $sname; ?>"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="40"><b>Description:</b></td>
<td><input type="text" rows="10" cols="20" name="desc" value="<?php echo $desc; ?>" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="37"><b>Image:</b></td>
<td><input type="file" name="image" id="image"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><b>Status:</b></td>
<td><select name="status">
<option value='1'>Enable</option>
<option value='0'>Disable</option>
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
<table width="368">
<tr>
<td width="173" align="right"><input type="submit" name="submit" value="Submit"></td>
<td width="183" align="center"><input type="reset" name="reset" value="Reset"></td>
</tr>
</table>
</form></td>
</tr>
</table>
</body>
</html>
INSERTUP.PHP :-
if($_POST["cname"] != "" && $_POST["desc"] != "" && $_POST["image"] != "") {
$_SESSION['cname']=$_POST["cname"];
//echo $_SESSION['cname'];
$query=mysql_query("SELECT * FROM categories WHERE category_name='".$_SESSION['cname']."'");
$row=mysql_fetch_array($query);
$c_name=$row['category_name'];
$img=$row['image'];
echo $c_name;
//$id=$row['id'];
//if(isset($_FILES["image"])) {
print_r($_FILES);
if($cname != $c_name && $image != $img) {
$path= "Image/".$_FILES["image"]["name"];
if($path != '') {
if(copy($_FILES["image"]["tmp_name"], $path)) {
$sql=mysql_query("INSERT INTO categories (category_name, sort_order, description, image, status)
VALUES ('$cname', '$sorder', '$desc', '$image', '$status')") or die(mysql_error());
header('location: index.php');
} else {
echo "Error in Insertion";
}
} else {
echo "Image not Uploaded";
}
} //}
}
}
On your html there is a typo in (form-data)
change
<form name="myform" action="insertup.php?id=<?php echo $id; ?>" method="post" enctype="multipart/form_data">
to
<form name="myform" action="insertup.php?id=<?php echo $id; ?>" method="post" enctype="multipart/form-data">
In your HTML, in form has to be enctype="multipart/form-data", not enctype="multipart/form_data".
<form name="myform" action="insertup.php?id=<?php echo $id; ?>" method="post" enctype="multipart/form-data">
Then, $_POST['image'] in your condition on line 1 of insertup.php will be probably empty, so change that to
if($_POST["cname"] != "" && $_POST["desc"] != "" && !empty($_FILES["image"]["name"])) {
I have the following code to insert data into a DB but when inserting the data some times it insert successfully while most of the time its giving me error like below.
Could not enter data: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's fist name?', 'Kabul Janm', 'Afghanistan', 'Kabul', 'Kabul', '1985-03-26', 'Mal' at line 1
Can someone help me out, I need to have it stable, the code is as below please,
<html>
<head>
<title>Add New Record in MySQL Database</title>
<script src="SpryAssets/SpryCollapsiblePanel.js" type="text/javascript"></script>
<script src="SpryAssets/SpryTabbedPanels.js" type="text/javascript"></script>
<link href="SpryAssets/SpryCollapsiblePanel.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
include_once ('top.php');
?>
<?php
include '/Connections/conn.php';
if(isset($_POST['add']))
{
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
if(! get_magic_quotes_gpc() )
{
$first_name = addslashes ($_POST['first_name']);
$last_name = addslashes ($_POST['last_name']);
}
else
{
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
}
$email_address = $_POST['email_address'];
$phone_no = $_POST['Phone_no'];
$user_name = $_POST['user_name'];
$password = $_POST['password'];
$sec_question = $_POST['sec_question'];
$Answer = $_POST['Answer'];
$Country = $_POST['Country'];
$State = $_POST['State'];
$city = $_POST['city'];
$date_birth = $_POST['date_birth'];
$gender = $_POST['gender'];
$sql = "INSERT INTO users(first_name, last_name, email_address, Phone_no, user_name, password, sec_question, Answer, Country, State, city, date_birth, gender) VALUES('$first_name', '$last_name', '$email_address', '$phone_no', '$user_name', '$password', '$sec_question', '$Answer', '$Country', '$State', '$city', '$date_birth', '$gender')";
$dbname;
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
header("Location: /thank.php");
//echo "<center>Thanks for registration in Mashwani Info Tech Free Online Trainings (MOFT)</center>\n";
mysql_close($conn);
}
else
{
?>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationPassword.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationConfirm.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationSelect.css" rel="stylesheet" type="text/css" />
<script src="SpryAssets/SpryValidationPassword.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationConfirm.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationSelect.js" type="text/javascript"></script>
<table width="100%" background="/Images/gradient_medium.jpg">
<tr>
<td width="100%" height="34">
<!--<center> <marquee behavior="Scroll" width="100%" scrollamount="8" direction="Right"><img src="/Images/mtn.jpg" /> <img src="/Images/mtn1.jpg" /></marquee> </center>
-->
</td>
</tr>
</table>
<table width="100%" align="center" bgcolor="#ECF5F0" border="0">
<tr valign="bottom"> <td height="25"><p> </p>
<form action="<?php $_PHP_SELF?>" method="post" name="form1" id="form1">
<table align="center" border="1">
<tr valign="baseline">
<td colspan="2" align="left" nowrap="nowrap" bordercolor="#CCCC33">First Name</td>
<td width="388"><span id="sprytextfield1">
<input type="text" name="first_name" value="" size="37" id="first_name"/>
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr valign="baseline">
<td colspan="2" align="left" nowrap="nowrap">Last Name</td>
<td><input type="text" name="last_name" id="last_name" value="" size="37" /></td>
</tr>
<tr valign="baseline">
<td colspan="2" align="left" nowrap="nowrap">Email Address</td>
<td><span id="sprytextfield2">
<input type="text" name="email_address" id="email_address" value="" size="37" />
<span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
</tr>
<tr valign="baseline">
<td colspan="2" align="left" nowrap="nowrap">Phone No <font size="-4" color="#00CC66">(0093772221521)</font></td>
<td><span id="sprytextfield3">
<input type="text" name="Phone_no" id="Phone_no" value="" size="37" />
<span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
</tr>
<tr valign="baseline">
<td colspan="2" align="left" nowrap="nowrap">User Name</td>
<td><span id="sprytextfield4">
<input type="text" name="user_name" id="user_name" value="" size="37" />
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr valign="baseline">
<td colspan="2" align="left" nowrap="nowrap">Password <font size="-4" color="#00CC66">(Min 8 Charectors) </font></td>
<td><span id="pass">
<input type="password" name="password" value="" size="37" id="password" />
<span class="passwordRequiredMsg">A value is required.</span><span class="passwordInvalidStrengthMsg">The password doesn't meet the specified strength.</span></span></td>
</tr>
<tr valign="baseline">
<td colspan="2" align="left" nowrap="nowrap">Confirm Password:</td>
<td><span id="spryconfirm1">
<label for="confirm"></label>
<input name="confirm" type="password" id="confirm" size="37" />
<span class="confirmRequiredMsg">A value is required.</span><span class="confirmInvalidMsg">The values don't match.</span></span></td>
</tr>
<tr valign="baseline">
<td colspan="2" align="left" nowrap="nowrap">Secret Question</td>
<td><span id="spryselect1">
<label for="sec"></label>
<select name="sec_question" id="sec_question">
<option value="What is your fist school name?">What is your fist school name?</option>
<option value="Where did your birth happened?">Where did your birth happened?</option>
<option value="What is your father's fist name?">What is your father's fist name?</option>
<option value="Where did you get your degree?">Where did you get your degree?</option>
</select>
<span class="selectRequiredMsg">Please select an item.</span></span></td>
</tr>
<tr valign="baseline">
<td colspan="2" align="left" nowrap="nowrap">Answer for Question</td>
<td><span id="sprytextfield5">
<input type="text" name="Answer" id="Answer" value="" size="37" />
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr valign="baseline">
<td width="61" rowspan="3" align="left" valign="middle" nowrap="nowrap">Address</td>
<td width="121" align="left" nowrap="nowrap">Country</td>
<td><input type="text" name="Country" id="Country" value="" size="37" /></td>
</tr>
<tr valign="baseline">
<td width="121" align="left" nowrap="nowrap">State</td>
<td><span id="sprytextfield6">
<input type="text" name="State" id="State" value="" size="37" />
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr valign="baseline">
<td width="121" align="left" nowrap="nowrap">City</td>
<td><span id="sprytextfield7">
<input type="text" name="city" id="city" value="" size="37" />
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr valign="baseline">
<td colspan="2" align="left" nowrap="nowrap">Date of Birth <font size="-4" color="#00CC66"> (YYYY-MM-DD) </font></td>
<td><span id="sprytextfield8">
<input type="text" name="date_birth" id="date_birth" value="" size="37" />
<span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
</tr>
<tr valign="baseline">
<td colspan="2" align="left" nowrap="nowrap">Gender</td>
<td><span id="spryselect2">
<label for="gen"></label>
<select name="gender" id="gender">
<option value="Select your gender here." selected="selected">Select your gender here.</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
<span class="selectRequiredMsg">Please select an item.</span></span></td>
</tr>
</table>
<center> <input name="add" type="submit" value="Sign Up" id="add" /> </center>
<input type="hidden" name="ID" value="" />
<input type="hidden" name="admin_level" id="admin_level" value="" />
<input type="hidden" name="time_stamp" id="time_stamp" value="" />
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p></td>
</tr>
</table>
<?php
}
?>
<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "none", {validateOn:["blur"]});
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "email");
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "phone_number", {format:"phone_custom"});
var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4");
var sprypassword1 = new Spry.Widget.ValidationPassword("pass", {minAlphaChars:1, minUpperAlphaChars:1, minSpecialChars:1, validateOn:["blur"]});
var spryconfirm1 = new Spry.Widget.ValidationConfirm("spryconfirm1", "password", {validateOn:["blur"]});
var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1");
var sprytextfield5 = new Spry.Widget.ValidationTextField("sprytextfield5");
var sprytextfield6 = new Spry.Widget.ValidationTextField("sprytextfield6");
var sprytextfield7 = new Spry.Widget.ValidationTextField("sprytextfield7");
var sprytextfield8 = new Spry.Widget.ValidationTextField("sprytextfield8", "date", {format:"yyyy-mm-dd"});
var spryselect2 = new Spry.Widget.ValidationSelect("spryselect2");
var CollapsiblePanel1 = new Spry.Widget.CollapsiblePanel("CollapsiblePanel1");
</script>
<?php
include_once ('bottom.php');
?>
</body>
</html>
You have to escape "'" signs before using data in a query.
What happens is that your users enter "'" in the input field, and MySQL gets an error.
Use prepared statements for automatical way to deal with that problem.
Here is and example.
Edit:
Edit your code like this:
if(! get_magic_quotes_gpc() )
{
$first_name = addslashes ($_POST['first_name']);
$last_name = addslashes ($_POST['last_name']);
$email_address = addslashes ($_POST['email_address']);
$phone_no = addslashes ($_POST['Phone_no']);
$user_name = addslashes ($_POST['user_name']);
$password = addslashes ($_POST['password']);
$sec_question = addslashes ($_POST['sec_question']);
$Answer = addslashes ($_POST['Answer']);
$Country = addslashes ($_POST['Country']);
$State = addslashes ($_POST['State']);
$city = addslashes ($_POST['city']);
$date_birth = addslashes ($_POST['date_birth']);
$gender = addslashes ($_POST['gender']);
}
else
{
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email_address = $_POST['email_address'];
$phone_no = $_POST['Phone_no'];
$user_name = $_POST['user_name'];
$password = $_POST['password'];
$sec_question = $_POST['sec_question'];
$Answer = $_POST['Answer'];
$Country = $_POST['Country'];
$State = $_POST['State'];
$city = $_POST['city'];
$date_birth = $_POST['date_birth'];
$gender = $_POST['gender'];
}
It should prevent the errors.
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.