im trying to make a enrollment system in the school and i need help
not to duplicate the emails and fullname with middlename, but if the name and lastname is the same its ok to add but with the middlename will not continue to add the student. still the same process when i update the student
function student($param1 = '', $param2 = '', $param3 = '')
{
if ($this->session->userdata('admin_login') != 1)
redirect('login', 'refresh');
if ($param1 == 'create') {
$data['name'] = $this->input->post('name');
$data['mname'] = $this->input->post('mname');
$data['lastname'] = $this->input->post('lastname');
$data['birthday'] = $this->input->post('birthday');
$data['sex'] = $this->input->post('sex');
$data['address'] = $this->input->post('address');
$data['phone'] = $this->input->post('phone');
$data['email'] = $this->input->post('email');
$data['password'] = md5($this->input->post('password'));
$data['father_name'] = $this->input->post('father_name');
$data['mother_name'] = $this->input->post('mother_name');
$data['class_id'] = $this->input->post('class_id');
$data['roll'] = $this->input->post('roll');
$this->db->insert('student', $data);
$student_id = mysql_insert_id();
move_uploaded_file($_FILES['userfile']['tmp_name'], 'uploads/student_image/' . $student_id . '.jpg');
$this->email_model->account_opening_email('student', $data['email']); //SEND EMAIL ACCOUNT OPENING EMAIL
$this->session->set_flashdata('flash_message', get_phrase('add_student_success'));
redirect(base_url() . 'index.php?admin/student/' . $data['class_id'], 'refresh');
}
if ($param2 == 'do_update') {
$data['name'] = $this->input->post('name');
$data['mname'] = $this->input->post('mname');
$data['lastname'] = $this->input->post('lastname');
$data['birthday'] = $this->input->post('birthday');
$data['sex'] = $this->input->post('sex');
$data['address'] = $this->input->post('address');
$data['phone'] = $this->input->post('phone');
$data['email'] = $this->input->post('email');
$data['password'] = md5($this->input->post('password'));
$data['father_name'] = $this->input->post('father_name');
$data['mother_name'] = $this->input->post('mother_name');
$data['class_id'] = $this->input->post('class_id');
$data['roll'] = $this->input->post('roll');
$this->db->where('student_id', $param3);
$this->db->update('student', $data);
move_uploaded_file($_FILES['userfile']['tmp_name'], 'uploads/student_image/' . $param3 . '.jpg');
$this->crud_model->clear_cache();
$this->session->set_flashdata('flash_message', get_phrase('edit_student_success'));
redirect(base_url() . 'index.php?admin/student/' . $param1, 'refresh');
} else if ($param2 == 'edit') {
$page_data['edit_data'] = $this->db->get_where('student', array(
'student_id' => $param3
))->result_array();
} else if ($param2 == 'personal_profile') {
$page_data['personal_profile'] = true;
$page_data['current_student_id'] = $param3;
} else if ($param2 == 'academic_result') {
$page_data['academic_result'] = true;
$page_data['current_student_id'] = $param3;
}
Related
I am attempting to write code that will edit a Single entry in a SQL database, the $num is the invoice ID number, I must be passing it incorrectly, because my console was showing an Undefined value for the idinvoice,
Now the console isn't showing any errors :/
Google and stack haven't yield much yet,
Here is my Javascript
$scope.saveEdit = function($param){
$scope.list2 = { };
if($scope.who == 'Dealer'){ $scope.list2.billTo = 'Dealer'; $scope.billTo = ''; }
else { $scope.list2.billTo = 'Customer'; $scope.billTo = ''; }
if($scope.billStart) { $scope.list2.billStart = $scope.billStart; $scope.billStart = ''; }
if($scope.customerName) { $scope.list2.customerName = $scope.customerName; $scope.customerName = ''; }
if($scope.dealerName) { $scope.list2.dealerName = $scope.dealerName; $scope.dealerName = ''; }
if($scope.item) { $scope.list2.item = $scope.item; $scope.item = ''; }
if($scope.price) { $scope.list2.price = $scope.price; $scope.price = ''; }
if($scope.qty) { $scope.list2.qty = $scope.qty; $scope.qty = ''; }
if($scope.cost) { $scope.list2.cost = $scope.cost; $scope.cost = ''; }
if($scope.contractTerms) { $scope.list2.contractTerms = $scope.contractTerms; $scope.contractTerms = ''; }
$scope.list2.per = $scope.per; $scope.per = '0';
$http.post('DealerRec/writeInvoice.php?$num='+$param+'&action=writeEdit', $scope.list2)
.success(function(data){ console.log("Data Written"); console.log(data); })
.error(function() { console.log("Data Not Written"); });
}
Here is my php file for connecting to SQL
switch($_GET['action']){
case 'writeInvoice':
writeInvoice();
break;
case 'fetchInvoice':
echo fetchInvoice($_GET['num']);
break;
case 'saveEdit':
writeEdit($_GET['num']);
break;
}
function writeEdit($num){
$data = json_decode(file_get_contents("php://input"));
$customerName = $data->customerName;
$dealerName = $data->dealerName;
$billTo = $data->billTo;
$billStart = substr($data->billStart,0,10);
$contractTerms = $data->contractTerms;
$item = $data->item;
$price = $data->price;
$qty = $data->qty;
$per = $data->per;
$cost = $data->cost;
$qry = "UPDATE invoice
SET
customerName = '{$customerName}',
dealerName = '{$dealerName}',
billTo = '{$billTo}',
billStart = '{$billStart}',
contractTerms = '{$contractTerms}',
item = '{$item}',
itemPrice = '{$price}',
quantity = '{$qty}',
cost = '{$cost}',
sharePercent = '{$per}'
WHERE idInvoice ='{$num}'";
echo ($qry);
$qry_res = new Query($qry);
if ($qry_res) { $arr = array('msg' => "Invoice edited successfully!!!", 'error' => ''); }
else { $arr = array('msg' => "", 'error' => 'Error in inserting record'); }
}
The solution was as follows
change to this
$http.post('DealerRec/writeInvoice.php?action=saveEdit', $scope.list2)
.success(function(data){ console.log("Data Written"); console.log(data); })
.error(function() { console.log("Data Not Written"); });
}
and this
case 'saveEdit':
saveEdit();
break;
and finally this
$price = $data->price;
$qty = $data->qty;
$per = $data->per;
$cost = $data->cost;
$num = $data->idInvoice; <----------------------
These functions now work. Thank you all for your help.
i have created a native javascript code (w/o jquery) to upload using php for server side, it seems that everything is ok and going fine, but when i selected 10 or more images, not all of them are uploaded some images are having problem, here is my javascript so far:
var uploadevent = function(event) {
event.preventDefault();
event.stopPropagation();
var xhr = new XMLHttpRequest();
var data = new FormData();
for(var i = 0; i < images.files.length; ++i) {
data.append('images[]', images.files[i]);
}
data.append('EmailAd', EmailAd);
data.append('UserID', UserID);
data.append('Studentnumber', Studentnumber);
data.append('album_name', document.getElementById('hidden_album_name').value);
var ul_album_thumbnails = document.getElementById('ul_album_thumbnails');
var rand = Math.random().toString().split('.');
var str = rand[1]; // need this to generate unique id
var newli = document.createElement('li');
newli.setAttribute('id', str);
var display = document.createElement('div'); // div element that handles preview
display.style.position = "relative";
display.style.height = "191px";
display.style.width = "180px";
display.style.cssFloat = "right";
display.style.border = "1px solid #a4a4a4";
display.style.background = "#fff";
display.style.zIndex = '998'; // this thumbnail container should be on the top
$(display).append("<progress id='progressBar' style='border:1px solid #a4a4a4;position:absolute;bottom:0px;width:178px;z-index:1' value='0' max='100'></progress>");
$(display).append("<div id='progressStatus' style='position:absolute;bottom:0px;width:178px;z-index:1;text-align:right;background:transparent'></div>");
newli.appendChild(display);
ul_album_thumbnails.insertBefore(newli, ul_album_thumbnails.childNodes[1]);
xhr.upload.addEventListener('progress', function(event) {
var percent = (event.loaded / event.total) * 100;
document.getElementById('progressBar').value = Math.round(percent);
document.getElementById('progressStatus').innerHTML = Math.round(percent) + ' %';
});
xhr.onload = function() {
if((typeof this.response == 'object' || typeof this.response) && this.status == 200 && this.response != '') {
try {
var $resp = JSON.parse(this.response);
document.body.style.overflowY = 'auto';
divback.removeAttribute('style');
$('#ul_album_thumbnails > li#' + str + ' > div').css('z-index','1');
$('li#' + str + ' > div').html('');
var newimg = document.createElement('img'), thumb = $resp.ImageUrl.replace('../', '');
newimg.src = 'temp_pages/image.php?nocache=nocache&width=180&height=180&cropratio=5:4&image=/prototype/' + thumb;
$('li#' + str + ' > div').append(newimg);
var strs = $resp.AlbumName; // album name
var divfooter = document.createElement('div');
divfooter.style.position = 'absolute';
divfooter.style.width = '180px';
divfooter.style.height = '50px';
divfooter.style.bottom = '0px';
$(divfooter).append("<a href='JavaScript:void(0)' style='font-family:Tahoma, Geneva, sans-serif;font-size:11px;font-weight:bold;position:relative;top:8px;left:3px;'>" + strs + "</a>");
$('li#' + str + ' > div').append(divfooter);
images.value = '';
document.getElementById('hidden_album_name').value = '';
} catch(SyntaxError) {
}
} else {
}
} // end of xmlhttprequest onload event
xhr.open('POST', 'ajax/ajax_upload_photo_album.php', true);
xhr.setRequestHeader('Cache-Control', 'no-cache');
xhr.send(data);
xhr.close();
}
and this is my PHP
<?php
function find($filename, $key) {
//$x = is_file($base . $filename) ? 'true' : 'false';
// count the number of period occurence as this return an array object
$countp = explode('.', $filename);
$s = (count($countp) > 2) ? end($countp) : $countp[1];
$countp[0] = md5($countp[0]) . md5(rand());
if($key == 0) {
$filename = $countp[0] . '_' . 'thumbnail' . '.' . $s;
} else {
$filename = $countp[0] . '.' . $s;
}
return strtolower($filename);
}
$base_url = '../user/images/albums/';
$EmailAd = $_REQUEST['EmailAd'];
$username = explode('#', $EmailAd);
$UserID = $_REQUEST['UserID'];
$Studentnumber = $_REQUEST['Studentnumber'];
$album_name = $_REQUEST['album_name'];
$base_url .= $UserID.'_'.$Studentnumber.'_'.$username[0].'/'.$UserID.'_'.$Studentnumber.'_'.$username[0].'_'.$album_name.'/';
$tmp = array();
foreach($_FILES['images']['name'] as $key => $name) {
//$sizexy = getimagesize($w);
$image_info = getimagesize($_FILES['images']['tmp_name'][$key]);
$imageWidth = $image_info[0];
$imageHeight = $image_info[1];
$f = $base_url . $imageWidth . '_' . $imageHeight . '_' . find($name, $key);
if($_FILES['images']['error'][$key] == 0 && move_uploaded_file($_FILES['images']['tmp_name'][$key], $f)) {
if($key == 0) {
$g = array('ImageUrl' => $f, 'BaseUrl' => $base_url, 'AlbumName' => $album_name, 'ImageCount' => count($_FILES['images']['name']), 'Created' => date('h:ia', filectime($base_url)));
}
}
}
echo json_encode($g);
clearstatcache();
?>
is there alternative code for this?
My problem now when I click on the picture on my page, for the first time it will display. But for the second time it will display fail. This process will start by sending the data to ajax, then ajax(prosess.js) will send it to the php page(process1.php).
When I remove the code in blockquote ($query = "SELECT ...") it will run, but if not, it will display fail.
process1.php
<?php
include 'session.php';
include 'connection.php';
if(isset($_POST['dataS'])) {
$table = $_POST['table'];
$concat = "";
$serial = $_POST['dataS'];
$query = "SELECT * FROM product WHERE serialNum = '$serial'";
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_assoc($result);
if($row) {
$prodName = $row['prodName'];
$quanProd = 1;
$priceProd = $_POST['total'] + $row['salePrice'];
if($table == "") {
$query = "SELECT * FROM product WHERE serialNum = '$serial'";
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_assoc($result);
}
else{
$DOM = new DOMDocument;
$DOM->loadHTML($table);
$items = $DOM->getElementsByTagName('tr');
$check = 0;
$check_one = 0;
$y=0;
function tdrows($elements,$check,$serial,$prodName,$y) {
$quantity="";
$item = "";
$price = "";
$delete = "";
$x = 0;
foreach($elements as $element) {
if($x == 0)
$delete = $element->nodeValue;
else if($x == 1)
$item = $element->nodeValue;
else if($x == 2)
$quantity = $element->nodeValue;
else if($x == 3)
$price = $element->nodeValue;
$x++;
}
**$query = 'SELECT prodName FROM product WHERE prodName = "$item"';
$search = mysqli_query($conn, $query) or die(mysqli_error());
$row = mysqli_fetch_assoc($search);
$s = $row['prodName'];**
if($prodName == $s) {
$quantity++;
$check = 1;
}
else {
$check = 0;
}
return $check;
}
foreach ($items as $node) {
$check = tdrows($node->childNodes,$check,$serial,$prodName,$y);
$y++;
}
}
$priceProd = number_format((float)$priceProd, 2, '.', '');
echo json_encode (
array ( //this array is used to send the data back to ajax.
"success" => "1",
"concat" => $concat,
"quantity" => $quanProd,
"price" => $priceProd,
)
);
}
else {
echo json_encode (
array ( //this array is used to send the data back to ajax.
"success" => "0",
)
);
}
}
?>
process.js
$(document).ready(
function() {
$("body").on("click","#product .add",
function(e) {
var total = document.getElementById("total").value;
var table = document.getElementById('table-list').innerHTML;
table = (table.trim) ? table.trim() : table.replace(/^\s+/,'');
var serial = $(this).attr('id');
var totalQ = document.getElementById("totalQ").value;
if(total == "")
total = 0;
else
total = parseFloat(total);
if(totalQ == "")
totalQ = 0;
else
totalQ = parseInt(totalQ);
var dataS = serial;
e.preventDefault();
$.ajax({
type : "POST",
url : "process1.php",
crossDomain: true,
data : {dataS : dataS, table : table, total : total},
dataType : 'json',
})
.done(function(html) {
if(html.success == 1) {
console.log('done: %o', html);
$("#table-list").html(html.concat).show();
document.getElementById('totalQuantity').innerHTML = html.quantity;
document.getElementById("total").value = html.price;
document.getElementById("payment").value = html.price;
document.getElementById('totalQ').value = html.quantity;
document.getElementById('title').innerHTML = html.price;
document.getElementById('input').value='';
$("#input").focus();
}
else {
alert("Wrong serial number!");
document.getElementById('input').value='';
$("#input").focus();
}
})
.fail(function(html) {
console.info('fail: %o', html);
alert("fail");
});
return false;
});
});
connection.php
<?php
$conn = mysqli_connect('localhost','root','','rds');
?>
your query is wrong:try this
$query = "SELECT prodName FROM product WHERE prodName = '".$item."'";
According to your pictures, your problem is that your database connection isn't correct. When you execute the first request it won't do any database interaction (because off the blocknotes). The second request you will send table data, which will perform a query. So the first request will succeed, while the second request will give you an error on your mysqli ($conn) object.
if($table == "") {
//Database interaction
$query = "SELECT * FROM product WHERE serialNum = '$serial'";
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_assoc($result);
}
else{
//No database interaction because of the blocknotes
$DOM = new DOMDocument;
$DOM->loadHTML($table);
$items = $DOM->getElementsByTagName('tr');
$check = 0;
$check_one = 0;
$y=0;
function tdrows($elements,$check,$serial,$prodName,$y) {
$quantity="";
$item = "";
$price = "";
$delete = "";
$x = 0;
foreach($elements as $element) {
if($x == 0)
$delete = $element->nodeValue;
else if($x == 1)
$item = $element->nodeValue;
else if($x == 2)
$quantity = $element->nodeValue;
else if($x == 3)
$price = $element->nodeValue;
$x++;
}
**$query = 'SELECT prodName FROM product WHERE prodName = "$item"';
$search = mysqli_query($conn, $query) or die(mysqli_error());
$row = mysqli_fetch_assoc($search);
$s = $row['prodName'];**
if($prodName == $s) {
$quantity++;
$check = 1;
}
else {
$check = 0;
}
return $check;
}
foreach ($items as $node) {
$check = tdrows($node->childNodes,$check,$serial,$prodName,$y);
$y++;
}
}
Check your the username, password and database name. I'm pretty sure you used something wrong here. As mentioned in your connection.php file you don't use a password. Are you sure the user root doens't have a password? Can you access the database with a MySQL administration tool like phpMyAdmin?
what i am trying to do is getting data from database and tick the checkbox according to that but i did not success any idea?
i am not sure what is the problem
JS code
function editPer(role_pk) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState === 4) {
var jsonObj = JSON.parse(xmlHttp.responseText);
document.getElementById("role_pk1").value = jsonObj.pk;
document.getElementById("role_name1").value = jsonObj.name;
for (var i = 1; i < 29; i++){
if (jsonObj.permission_fk+i != null)
document.getElementById("per"+i).checked = true;
else
document.getElementById("per"+i).checked = false;
}
}
};
xmlHttp.open("GET", "classes/controller/RoleController.php?action=getp&pk=" + role_pk, true);
xmlHttp.send();
/*
* Reset error message
* Show update role button
*/
resetErrorMessage("roleMessage");
showUpdateRoleButton();
$("#perModalDetail").modal('show');
};
PHP code RoleController.php
}else if ($action == "getp") {
if (isset($pk)) {
/*
* Select single Role value
*/
$itemArray = $roleDao->getp($pk);
if (count($itemArray) == 0) {
echo NULL;
} else {
echo json_encode($itemArray[0]);
}
}
PHP code in the class roleDao
public function getp($pk) {
$query = "SELECT pk, name FROM roles WHERE pk=".$pk.";";
$result = mysql_query($query, $this->dbconn);
$itemArray = array();
while ($row = mysql_fetch_row($result)) {
$item = array("pk" => $row[0], "name" => $row[1]);
array_push($itemArray, $item);
}
$query = "SELECT permission_fk FROM role_permission WHERE role_fk=".$pk.";";
$result = mysql_query($query, $this->dbconn);
$i=1;
while ($row = mysql_fetch_row($result)) {
$item = array("permission_fk$i" => $row[0]);
$i++;
array_push($itemArray, $item);
}
//print $itemArray;
return $itemArray;
}
JS file this deletes by button the Event
buttons: {
save : function() {
calEvent.start = new Date(startField.val());
calEvent.end = new Date(endField.val());
calEvent.title = titleField.val();
calEvent.body = bodyField.val();
$calendar.weekCalendar("updateEvent", calEvent);
$dialogContent.dialog("close");
},
"delete" : function() {
calEvent.id = id;
$.post("events.php?action=del&id="+calEvent.id);
$calendar.weekCalendar("removeEvent", calEvent.id);
$dialogContent.dialog("close");
},
cancel : function() {
$dialogContent.dialog("close");
}
}
}).show();
PHP File
if($action == 'save')
{
$title = $_REQUEST['title'];
$body = $_REQUEST['body'];
$start_time = (int)$_REQUEST['start'];
$start_time = $start_time + 60*60;
$end_time = (int)$_REQUEST['end'];
$end_time = $end_time + 60*60;
$start = date('c',$start_time);
$end = date('c',$end_time);
$sql = "INSERT INTO meeting_rooms_calendar(title,body,start,end) VALUES ('$title','$body','$start','$end')";
$result = mysql_query($sql, $link);
}
elseif ($action == 'del')
{
$del = "DELETE FROM `agenda`.`meeting_rooms_calendar` WHERE `meeting_rooms_calendar`.`id` = VALUES ('$id')";
$result = mysql_query($del, $link);
}
else
{
$sql= "SELECT id, title, body,
DATE_FORMAT(start, '%Y-%m-%dT%H:%i' ) AS startTime, DATE_FORMAT(end, '%Y-%m-%dT%H:%i' ) AS endTime
FROM meeting_rooms_calendar
ORDER BY start DESC";
$result = mysql_query($sql, $link);
This wont delete from database, what am I doing wrong to delete it from database?