Why I am getting 0 instead values from the database? What I am doing wrong if I give $_POST['dataType'] === 'start'. I never call a multiple DB select request. What I am doing wrong?
UPDATED:
if(isset($_POST['dataType'])){
switch ($_POST['dataType']) {
case 'start':
$data_type = 'pictures, videos, audio, documents';
break;
case 'picture':
$data_type = 'pictures';
break;
case 'video':
$data_type = 'videos';
break;
case 'audio':
$data_type = 'audio';
break;
case 'document':
$data_type = 'documents';
break;
default:
$data_type = '';
}
if (!empty($data_type)) {
$userId = mysqli_real_escape_string($connect, $_SESSION['userId']);
if ($_POST['dataType'] !== 'start')
$sql = "SELECT * FROM " . $data_type . " WHERE user_id = " . $userId;
else {
$sql_picture = "SELECT * FROM pictures WHERE user_id = " . $userId . " ORDER BY upload_time";
$sql_videos = "SELECT * FROM videos WHERE user_id = " . $userId . " ORDER BY upload_time";
$sql_audio = "SELECT * FROM audio WHERE user_id = " . $userId . " ORDER BY upload_time";
$sql_documents = "SELECT * FROM documents WHERE user_id = " . $userId . " ORDER BY upload_time";
}
// Check connection
if ($connect->connect_error) {
mysqli_close($connect);
echo 1;
}
else {
if ($_POST['dataType'] !== 'start'){
$result = $connect->query($sql);
if ($result->num_rows > 0) {
$indexOfSuggests = 0;
$data = array();
while ($row = $result->fetch_assoc()) {
$id = $row['id'];
$user_id = $row['user_id'];
$name = $row['name'];
$public = $row['public'];
$link = $row['link'];
$upload_time = $row['upload_time'];
$data[$indexOfSuggests] = array($id, $user_id, $name, $public, $link, $upload_time);
$indexOfSuggests++;
}
$result->free();
echo json_encode($data);
}
else {
echo 0; // keine ergebnisse
}
}
else {
$indexOfSuggests = 0;
$new_index;
$collectData = array();
for($i = 0; $i < 4; $i++){
$indexOfSuggests = $new_index;
if($i == 0)
$sql = $sql_picture;
else
if($i == 1)
$sql = $sql_videos;
else
if($i == 2)
$sql = $sql_audio;
else
if($i == 3)
$sql = $sql_documents;
$result = $connect->query($sql);
if ($result->num_rows > 0) {
$data = array();
while ($row = $result->fetch_assoc()) {
$id = $row['id'];
$user_id = $row['user_id'];
$name = $row['name'];
$public = $row['public'];
$link = $row['link'];
$upload_time = $row['upload_time'];
$data[$indexOfSuggests] = array($id, $user_id, $name, $public, $link, $upload_time);
array_push($collectData, $data[$indexOfSuggests]);
$indexOfSuggests++;
}
$new_index = $indexOfSuggests;
}
else {
// keine ergebnisse
}
}
echo json_encode($collectData);
}
}
}
else {
header("Location: http://google.com");
}
}
So i got it but in a really uncool way. So the last thing I have to do is to order the array values by date.
here is new fix :)
<?php
if (isset($_POST['dataType'])) {
switch ($_POST['dataType']) {
case 'start':
$data_type = 'pictures,videos,audio,documents';
break;
case 'picture':
$data_type = 'pictures';
break;
case 'videos':
$data_type = 'videos';
break;
case 'audio':
$data_type = 'audio';
break;
case 'documents':
$data_type = 'documents';
break;
default:
$data_type = '';
}
function get_list ($sql,&$list) {
// Create connection
$connect = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($connect->connect_error) {
die(1);
} else {
$result = $connect->query($sql);
while ($row = $result->fetch_assoc()) {
$id = $row['id'];
$user_id = $row['user_id'];
$name = $row['name'];
$public = $row['public'];
$link = $row['link'];
$upload_time = $row['upload_time'];
$list[] = array($id, $user_id, $name, $public, $link, $upload_time);
}
}
}
if (!empty($data_type)) {
$list = array();
$userId = mysqli_real_escape_string($_SESSION['userId']);
if ($_POST['dataType'] !== 'start') {
$sql = "SELECT * FROM " . $data_type . " WHERE user_id = " . $userId;
get_list($sql,$list);
} else {
$data_types = explode(',',$data_type);
foreach($data_types as $type) {
$sql = "SELECT * FROM " . $type . " WHERE user_id = " . $userId;
get_list($sql,$list);
}
}
if(empty($list))
die(0);
else
echo json_encode($list);
} else {
header("Location: http://google.com");
}
}
?>
Related
I am trying to edit student's scores. like the image below. Each time I add the scores to be edited, my loop updates all the scores with only the last score in the form found below the picture of the form, my code and the SQL result when data has been edited.
Below is the code on my controller.
$fetch_session = $this->Home_model->SemesterSession();
$session = $fetch_session[0]->session;
$semester = $fetch_session[0]->semester;
// Form data
$unit = array();
$score = array();
$course = array();
$matno = $this->input->post('matno22');
$dept = $this->input->post('department22');
$level = $this->input->post('level22');
$score1 = $this->input->post('score');
$course1 = $this->input->post('c_code');
$unit1 = $this->input->post('unit');
// for each
for ($i=0;$i<count($course1);$i++) {
$data['score'] = $score1[$i]; //1
$data['unit'] = $unit1[$i];
$data['matno'] = $matno;
$data['level'] = $level;
$data['dept'] = $dept;
$data['course'] = $course1[$i];
$data['semester'] = $semester;
$data['session'] = $session;
if ($data['score'] >=69) {
$data['grade'] = 'A'; //2
$data['remark'] = 'Excellent'; //5
$data['grade_point'] = '5'; //3
$data['quality_p'] = $data['unit'] * $data['grade_point']; //4
} elseif ($data['score'] >= 59) {
$data['grade'] = 'B';
$data['remark'] = 'Very Good';
$data['grade_point'] = '4';
$data['quality_p'] = $data['unit'] * $data['grade_point'];
} elseif ($data['score'] >=49) {
$data['grade'] = 'C';
$data['remark'] = 'Good';
$data['grade_point'] = '3';
$data['quality_p'] = $data['unit'] * $data['grade_point'];
} elseif ($data['score'] >=44) {
$data['grade'] = 'D';
$data['remark'] = 'Fair';
$data['grade_point'] = '2';
$data['quality_p'] = $data['unit'] * $data['grade_point'];
} elseif ($data['score'] >=39) {
$data['grade'] = 'E';
$data['remark'] = 'Poor';
$data['grade_point'] = '1';
$data['quality_p'] = $data['unit'] * $data['grade_point'];
} else {
$data['grade'] = 'F';
$data['remark'] = 'Fail';
$data['grade_point'] = '0';
$data['quality_p'] = $data['unit'] * $data['grade_point'];
}
// Edit The Scores
$query = $this->Home_model->EditResult($data);
if ($query == true) {
$response['Error'] = 'false';
$response['Message'] = 'Result Successfully Modified';
} else {
$response['Error'] = 'true';
$response['Message'] = 'Error Modifying Result';
}
}
echo json_encode($response);
}
here is my model
public function EditResult($data) {
$condition = "matno = " . "'" . $data['matno'] . "' AND " . "course =" . "'" . $data['course'] . "' AND " . "semester =" . "'" . $data['semester'] . "' AND " . "session =" . "'" . $data['session'] . "'";
$this->db->where($condition);
$this->db->update('result', $data);
}
Lastly, This is what happens on my DB table when I update the scores
With my code below i have array item with multiple record i which to update each record into database with one query but only the last item of each array record was updated here is my code
:
<?php
require("init.php");
$sql = "SELECT item_name, quantity
FROM books WHERE book = 1644445";
$query = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($query))
{
$da = $row["item_name"];
$qty = $row["quantity"];
$sql = mysqli_query($conn, "SELECT * FROM promo WHERE code = '$da' LIMIT 1");
$productCount = mysqli_num_rows($sql);
if($productCount > 0)
{
while ($row = mysqli_fetch_array($sql))
{
$id = $row["id"];
$type = $row["name"];
$code = $row["recharge"];
}
}
$set="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$coe=substr(str_shuffle($set), 0, 12);
if(preg_match('/(65265)/i', $type))
$type = "20";
if(preg_match('/(562546)/i', $type))
$type = "13";
if(preg_match('/(MTN)/i', $type))
$type = "12";
if(preg_match('/(56556)/i', $type))
$type = "16";
$disp = str_split($code, $type);
for($b = 0; $b<$qty; $b++){
$pin = "$disp[$b]";
$gam = array(0 => array("post" => $pin));
foreach($gam as $gg)
{
$pp = $gg["post"];
$go = mysqli_query($conn, "UPDATE promo SET recharge='$coe$pp' WHERE id=$id");
if($go)
{
echo "<br/> $pp";
echo "<br/> $coe";
}
}
}
}
?>
i appliciate your impact
Try this:
<?php
require("init.php");
$sql = "SELECT item_name, quantity
FROM books WHERE book = 1644445";
$query = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($query))
{
$da = $row["item_name"];
$qty = $row["quantity"];
$sql = mysqli_query($conn, "SELECT * FROM promo WHERE code = '$da' LIMIT 1");
$productCount = mysqli_num_rows($sql);
if($productCount > 0)
{
while ($row = mysqli_fetch_array($sql))
{
$id = $row["id"];
$type = $row["name"];
$code = $row["recharge"];
}
$set="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$coe=substr(str_shuffle($set), 0, 12);
if(preg_match('/(65265)/i', $type))
$type = "20";
if(preg_match('/(562546)/i', $type))
$type = "13";
if(preg_match('/(MTN)/i', $type))
$type = "12";
if(preg_match('/(56556)/i', $type))
$type = "16";
$disp = str_split($code, $type);
for($b = 0; $b<$qty; $b++){
$pin = "$disp[$b]";
$gam = array(0 => array("post" => $pin));
foreach($gam as $gg)
{
$pp = $gg["post"];
$go = mysqli_query($conn, "UPDATE promo SET recharge='$coe$pp' WHERE id=$id");
if($go)
{
echo "<br/> $pp";
echo "<br/> $coe";
}
}
}
}
}
?>
The update is only executed if $productCount > 0.
it seem like i get stocked in loop ,i didn't know why this is my code-
$db = new mysqli("localhost", "root", "", "gdwal");
$sub = mysqli_query($db, "SELECT *,priority FROM subjects,teacher WHERE teach =techID ");
$stack = array();
$num = mysqli_query($db, "SELECT count(capacity)'h' FROM rooms ");
$table[][] = array();
$x = mysqli_fetch_array($num);
$table[0][0] = 0;
if ($db) {
echo 'connected';
}
/* function seet()
{
global $db;
$a=mysqli_query($db,"SELECT * from options ");
while ($row = mysqli_fetch_array($a)) {$z=$row['choices'];
echo($z);
$e=mysqli_query($db,"SELECT * from timeslot where sname=$z ");
$y=mysqli_fetch_array($e);
$x=$y['sindex'];
echo"//////$x/////+";
$b=mysqli_query($db,"UPDATE options SET `choices`=$x WHERE choices=$z ");
if($db->query($b)===true)
{
echo "lk";
}
}
}
seet(); */
for ($u = 0; $u <= 70; $u++) {
for ($g = 0; $g < 10; $g++) {
$table[$u][$g] = 0;
}
}
choose();
function choose() {
$sum = 0;
$sums = 0;
$best = array();
$prev = 0;
$best[0] = 0;
$best[1] = 0;
$best[2] = 100;
$best[3] = 0;
$best[4] = 0;
global $sub;
global $table;
global $stack;
global $db;
$ee = mysqli_query($db, "SELECT a.cid,c.NOstd,t.priority,c.hours,a.choices ,class,c.teacher_id FROM options a LEFT JOIN subjects c ON c.subject_id = a.cid LEFT JOIN teachers t ON t.id = c.teacher_id ");
while ($row = mysqli_fetch_array($ee)) {
if (!in_array($row['cid'], $stack)) {
$r = $row['cid'];
echo "$r-----";
$new = $r;
if ($prev===$new) {
} else {
$sum = 0;
$prev =$new;
}
$z = mysqli_query($db, "SELECT ind FROM rooms where capacity>='$r'");
while ($j = mysqli_fetch_array($z)) {
$hh = $row['choices'];
$uu = $j['ind'];
if ($table[$hh][$uu] == 0) {
$sum++;
}
}
if ($sum == 0) {
break;
}
$sums = $sum;
if ($best[2] == $sum && $best[3] < $row['priority']) {
echo $row['cid'];
echo '09090909090909';
$best[0] = $row['cid'];
$best[1] = $row['NOstd'];
$best[2] = $sums;
$best[3] = $row['priority'];
$best[4] = $row['teacher_id'];
$best[5] = $row['hours'];
$best[6] = $row['class'];
} else {
if ($best[2] > $sum) {
$best[0] = $row['cid'];
$best[1] = $row['NOstd'];
$best[2] = $sums;
$best[3] = $row['priority'];
$best[4] = $row['teacher_id'];
$best[5] = $row['hours'];
$best[6] = $row['class'];
}
}
}
}
back($best);
}
function back($courses) {
global $stack;
global $db;
global $table;
$y =$courses[0];
$i = 0;
global$x;
$numsub = mysqli_query($db, "SELECT COUNT(DISTINCT cid)'jj' FROM options ");
$nn = mysqli_fetch_array($numsub);
$t = 0;
echo "XXX";
echo "//$y//";
echo "SELECT * FROM options WHERE cid='$y'";
echo "XXX";
$slot = mysqli_query($db, "SELECT * FROM options WHERE cid='$y'");
while ($rows = mysqli_fetch_array($slot)) {
$rom = mysqli_query($db, "SELECT * FROM rooms where capacity>='$courses[1]'");
$j = mysqli_query($db, "SELECT * FROM rooms where capacity>='$courses[1]'");
while ($D = mysqli_fetch_array($rom)) {
if ($courses[5] == 3) {
echo "22";
if ($table[$rows['choices']][$D['ind']] != 0 && $table[($rows['choices'] + 1)][$D['ind']] != 0) {
$z = $table[$rows['choices']][$D['ind']];
$ff = mysqli_query($db, "SELECT teacher FROM subjects where course_id=$z ");
$selec = mysqli_fetch_array($ff);
$b = mysqli_query($db, "SELECT COUNT(`class`)'kk'FROM `subjects` WHERE `class` IN(SELECT `class` FROM subjects WHERE `course_id`=$z ) AND( course_id =$y OR`ssubject`=$y");
$count = mysqli_fetch_array($b);
if ($count['kk'] != 0 || $selec['teacher'] == $courses[4]) {
$t++;
}
}
} else
if ($table[$rows['choices']][$D['ind']] != 0) {
$z = $table[$rows['choices']][$D['ind']];
$ff = mysqli_query($db, "SELECT teacher FROM subjects where course_id=$z ");
$selec = mysqli_fetch_array($ff);
$b = mysqli_query($db, "SELECT COUNT(`class`)'kk'FROM `subjects` WHERE `class` IN(SELECT `class` FROM subjects WHERE `course_id`=$z ) AND( course_id =$y OR`ssubject`=$y");
$count = mysqli_fetch_array($b);
if ($count['kk'] != 0 || $selec['teacher'] == $courses[4]) {
$t++;
if ($t != 0) {
break;
}
}
echo "1";
}
if ($t != 0) {
break;
}
}
while ($colmn = mysqli_fetch_array($j)) {
if ($courses[5] == 3) {
echo "uuuuuu";
$w = $table[$rows['choices']][$colmn['ind']];
$y = mysqli_query($db, "SELECT hours FROM subjects where course_id='$w' ");
$op = mysqli_fetch_array($y);
if ($op['hours'] == 3) {
$i = $table[($rows['choices'] - 1)][$colmn['ind']];
$q = mysqli_query($db, "SELECT hours ,course_id , FROM subjects WHERE course_id=$i");
$opi = mysqli_fetch_array($q);
if ($opi['hours'] == 3 && $opi['course_id'] == $w) {
array_push($stack, $courses[0]);
$table[($rows['choices'] + 1)][$colmn['ind']] = $courses[0];
if (count($stack) == $nn['jj']) {
database($table);
break;
}
choose();
$table[($rows['choices']) + 1][$colmn['ind']] = 0;
array_pop($stack);
}
} elseif ($table[$rows['choices']][$colmn['ind']] == 0) {
array_push($stack, $courses[0]);
$table[$rows['choices']][$colmn['ind']] = $courses[0];
$table[($rows['choices'] + 1)][$colmn['ind']] = $courses[0];
if (count($stack) == $nn['jj']) {
database($table);
break;
}
choose();
$table[$rows['choices']][$colmn['ind']] = 0;
$table[($rows['choices'] + 1)][$colmn['ind']] = 0;
array_pop($stack);
}
//end of t
}//end of courses 3
else {
if ($t == 0 && $table[$rows['choices']][$colmn['ind']] == 0) {
array_push($stack, $courses[0]);
$table[$rows['choices']][$colmn['ind']] = $courses[0];
if (count($stack) == $nn['jj']) {
database($table);
break;
}
choose();
$table[$rows['choices']][$colmn['ind']] = 0;
array_pop($stack);
}
}
}
}
}
global $sub;
function database($tab) { // print_r($tab);
global $db;
$g = mysqli_query($db, "SELECT * FROM timeslot");
$r = mysqli_query($db, "SELECT * FROM rooms");
while ($ro = mysqli_fetch_array($g)) {
while ($co = mysqli_fetch_array($r)) {
if ($tab[$ro['sindex']][$co['ind']] === 0) {
} else {
echo 'iam in 2';
$x = $tab[$ro['sindex']][$co['ind']];
$u = mysqli_query($db, "select subject_id,hours,teacher_id,class from subjects WHERE subject_id='$x'");
$cor = mysqli_fetch_array($u);
$na = $cor['subject_id'];
$ho = $cor['hours'];
$tea = $cor['teacher_id'];
$clas = $cor['class'];
$tim = $ro['sindex'];
$km = $co['ind'];
$rmm = mysqli_query($db, "SELECT name FROM rooms where ind=$km");
$rom = mysqli_fetch_array($rmm);
$romm = $rom['name'];
$n = mysqli_query($db, "INSERT INTO ttable(name, teacher,class, timeslot, room, hours) VALUES ($na,$tea,$clas,$tim,$romm,$ho)");
$t = "INSERT INTO ttable(name, teacher, timeslot, room, hours) VALUES ('$na','$tea','$tim','$romm','$ho')";
echo "uuututyttuy";
if ($db->query($t) === true) {
echo "lklklklklklklklkl";
}
}
}
}
}
It seems your "back" function calls "choose" function.
And your "choose" function calls your "back" function.
The loop is complete.
I have marked it with //////// to make it easy to find.
Edit I see now that there is several places in back you call choose. I have only marked one.
It's not to hard to find it with search function of any developer app.
$db = new mysqli("localhost", "root", "", "gdwal");
$sub = mysqli_query($db, "SELECT *,priority FROM subjects,teacher WHERE teach =techID ");
$stack = array();
$num = mysqli_query($db, "SELECT count(capacity)'h' FROM rooms ");
$table[][] = array();
$x = mysqli_fetch_array($num);
$table[0][0] = 0;
if ($db) {
echo 'connected';
}
/* function seet()
{
global $db;
$a=mysqli_query($db,"SELECT * from options ");
while ($row = mysqli_fetch_array($a)) {$z=$row['choices'];
echo($z);
$e=mysqli_query($db,"SELECT * from timeslot where sname=$z ");
$y=mysqli_fetch_array($e);
$x=$y['sindex'];
echo"//////$x/////+";
$b=mysqli_query($db,"UPDATE options SET `choices`=$x WHERE choices=$z ");
if($db->query($b)===true)
{
echo "lk";
}
}
}
seet(); */
for ($u = 0; $u <= 70; $u++) {
for ($g = 0; $g < 10; $g++) {
$table[$u][$g] = 0;
}
}
choose();
function choose() {
$sum = 0;
$sums = 0;
$best = array();
$prev = 0;
$best[0] = 0;
$best[1] = 0;
$best[2] = 100;
$best[3] = 0;
$best[4] = 0;
global $sub;
global $table;
global $stack;
global $db;
$ee = mysqli_query($db, "SELECT a.cid,c.NOstd,t.priority,c.hours,a.choices ,class,c.teacher_id FROM options a LEFT JOIN subjects c ON c.subject_id = a.cid LEFT JOIN teachers t ON t.id = c.teacher_id ");
while ($row = mysqli_fetch_array($ee)) {
if (!in_array($row['cid'], $stack)) {
$r = $row['cid'];
echo "$r-----";
$new = $r;
if ($prev===$new) {
} else {
$sum = 0;
$prev =$new;
}
$z = mysqli_query($db, "SELECT ind FROM rooms where capacity>='$r'");
while ($j = mysqli_fetch_array($z)) {
$hh = $row['choices'];
$uu = $j['ind'];
if ($table[$hh][$uu] == 0) {
$sum++;
}
}
if ($sum == 0) {
break;
}
$sums = $sum;
if ($best[2] == $sum && $best[3] < $row['priority']) {
echo $row['cid'];
echo '09090909090909';
$best[0] = $row['cid'];
$best[1] = $row['NOstd'];
$best[2] = $sums;
$best[3] = $row['priority'];
$best[4] = $row['teacher_id'];
$best[5] = $row['hours'];
$best[6] = $row['class'];
} else {
if ($best[2] > $sum) {
$best[0] = $row['cid'];
$best[1] = $row['NOstd'];
$best[2] = $sums;
$best[3] = $row['priority'];
$best[4] = $row['teacher_id'];
$best[5] = $row['hours'];
$best[6] = $row['class'];
}
}
}
}
/////////////////
/////////////////
/////////////////
back($best);
}
function back($courses) {
global $stack;
global $db;
global $table;
$y =$courses[0];
$i = 0;
global$x;
$numsub = mysqli_query($db, "SELECT COUNT(DISTINCT cid)'jj' FROM options ");
$nn = mysqli_fetch_array($numsub);
$t = 0;
echo "XXX";
echo "//$y//";
echo "SELECT * FROM options WHERE cid='$y'";
echo "XXX";
$slot = mysqli_query($db, "SELECT * FROM options WHERE cid='$y'");
while ($rows = mysqli_fetch_array($slot)) {
$rom = mysqli_query($db, "SELECT * FROM rooms where capacity>='$courses[1]'");
$j = mysqli_query($db, "SELECT * FROM rooms where capacity>='$courses[1]'");
while ($D = mysqli_fetch_array($rom)) {
if ($courses[5] == 3) {
echo "22";
if ($table[$rows['choices']][$D['ind']] != 0 && $table[($rows['choices'] + 1)][$D['ind']] != 0) {
$z = $table[$rows['choices']][$D['ind']];
$ff = mysqli_query($db, "SELECT teacher FROM subjects where course_id=$z ");
$selec = mysqli_fetch_array($ff);
$b = mysqli_query($db, "SELECT COUNT(`class`)'kk'FROM `subjects` WHERE `class` IN(SELECT `class` FROM subjects WHERE `course_id`=$z ) AND( course_id =$y OR`ssubject`=$y");
$count = mysqli_fetch_array($b);
if ($count['kk'] != 0 || $selec['teacher'] == $courses[4]) {
$t++;
}
}
} else
if ($table[$rows['choices']][$D['ind']] != 0) {
$z = $table[$rows['choices']][$D['ind']];
$ff = mysqli_query($db, "SELECT teacher FROM subjects where course_id=$z ");
$selec = mysqli_fetch_array($ff);
$b = mysqli_query($db, "SELECT COUNT(`class`)'kk'FROM `subjects` WHERE `class` IN(SELECT `class` FROM subjects WHERE `course_id`=$z ) AND( course_id =$y OR`ssubject`=$y");
$count = mysqli_fetch_array($b);
if ($count['kk'] != 0 || $selec['teacher'] == $courses[4]) {
$t++;
if ($t != 0) {
break;
}
}
echo "1";
}
if ($t != 0) {
break;
}
}
while ($colmn = mysqli_fetch_array($j)) {
if ($courses[5] == 3) {
echo "uuuuuu";
$w = $table[$rows['choices']][$colmn['ind']];
$y = mysqli_query($db, "SELECT hours FROM subjects where course_id='$w' ");
$op = mysqli_fetch_array($y);
if ($op['hours'] == 3) {
$i = $table[($rows['choices'] - 1)][$colmn['ind']];
$q = mysqli_query($db, "SELECT hours ,course_id , FROM subjects WHERE course_id=$i");
$opi = mysqli_fetch_array($q);
if ($opi['hours'] == 3 && $opi['course_id'] == $w) {
array_push($stack, $courses[0]);
$table[($rows['choices'] + 1)][$colmn['ind']] = $courses[0];
if (count($stack) == $nn['jj']) {
database($table);
break;
}
choose();
$table[($rows['choices']) + 1][$colmn['ind']] = 0;
array_pop($stack);
}
} elseif ($table[$rows['choices']][$colmn['ind']] == 0) {
array_push($stack, $courses[0]);
$table[$rows['choices']][$colmn['ind']] = $courses[0];
$table[($rows['choices'] + 1)][$colmn['ind']] = $courses[0];
if (count($stack) == $nn['jj']) {
database($table);
break;
}
choose();
$table[$rows['choices']][$colmn['ind']] = 0;
$table[($rows['choices'] + 1)][$colmn['ind']] = 0;
array_pop($stack);
}
//end of t
}//end of courses 3
else {
if ($t == 0 && $table[$rows['choices']][$colmn['ind']] == 0) {
array_push($stack, $courses[0]);
$table[$rows['choices']][$colmn['ind']] = $courses[0];
if (count($stack) == $nn['jj']) {
database($table);
break;
}
///////////////////////
///////////////////////
///////////////////////
choose();
$table[$rows['choices']][$colmn['ind']] = 0;
array_pop($stack);
}
}
}
}
}
global $sub;
function database($tab) { // print_r($tab);
global $db;
$g = mysqli_query($db, "SELECT * FROM timeslot");
$r = mysqli_query($db, "SELECT * FROM rooms");
while ($ro = mysqli_fetch_array($g)) {
while ($co = mysqli_fetch_array($r)) {
if ($tab[$ro['sindex']][$co['ind']] === 0) {
} else {
echo 'iam in 2';
$x = $tab[$ro['sindex']][$co['ind']];
$u = mysqli_query($db, "select subject_id,hours,teacher_id,class from subjects WHERE subject_id='$x'");
$cor = mysqli_fetch_array($u);
$na = $cor['subject_id'];
$ho = $cor['hours'];
$tea = $cor['teacher_id'];
$clas = $cor['class'];
$tim = $ro['sindex'];
$km = $co['ind'];
$rmm = mysqli_query($db, "SELECT name FROM rooms where ind=$km");
$rom = mysqli_fetch_array($rmm);
$romm = $rom['name'];
$n = mysqli_query($db, "INSERT INTO ttable(name, teacher,class, timeslot, room, hours) VALUES ($na,$tea,$clas,$tim,$romm,$ho)");
$t = "INSERT INTO ttable(name, teacher, timeslot, room, hours) VALUES ('$na','$tea','$tim','$romm','$ho')";
echo "uuututyttuy";
if ($db->query($t) === true) {
echo "lklklklklklklklkl";
}
}
}
}
}
I have a simple upload script that has some validation on the form. The idea behind the upload form is to upload 2 images, one a thumbnail and one a larger image. Both need to be the correct dimensions and require an image to be selected in order for the form to validate and successfully upload the images.
However, I have been tasked to remove the first upload part, the thumbnail. We now only need the larger image. Though I'm unsure how to remove the validation part of the process. I have tried to remove the input field from the HTML, but obviously the upload script sees this as not upload the first image and throws an error.
Anyway the files:
Upload.php
<?php
// Edit upload location here
$thumb_destination_path = "../storyslide_thumbs/";
$large_destination_path = "../storyslide_large/";
$type = $_POST['type'];
if (isset($_POST['ID'])) {
$ID = $_POST['ID'];
}
$caption = mysql_real_escape_string($_POST['caption']);
$caption2 = mysql_real_escape_string($_POST['caption2']);
if ($type == "article" || $type == "editarticle") {
$sql="select a.title, a.category, c.title as cattitle, s.section as stitle, c.type from article a, category c, section s WHERE c.catID=a.category AND c.sectionid=s.sectionid AND a.articleID='$ID'";
$result = mysql_query($sql) or die ("Error! bad select statement");
$row = mysql_fetch_array($result);
extract($row);
$stitle = html_entity_decode($stitle);
$stitle = punct_remove($stitle);
$linktitle = html_entity_decode($title);
$linktitle = punct_remove($linktitle);
$cattitle = html_entity_decode($cattitle);
$cattitle = punct_remove($cattitle);
if ($category=='43') {
$link = "/fans/obituaries/$ID-$linktitle..html";
} else {
if ($type=="Blog") {
$ID = "b$ID";
$cattitle = $cattitle . "-" . $category;
} else {
$cattitle = $category . "-" . $cattitle;
}
$link = "/$stitle/$cattitle/$ID-$linktitle.html";
}
} elseif ($type == "player") {
$sql = "SELECT name FROM player WHERE playerID='$ID'";
$result = mysql_query($sql) or die ("Error! bad select statement");
$row = mysql_fetch_array($result);
extract($row);
$name = html_entity_decode($name);
$name = punct_remove($name);
$link = "/players/squad/$ID-$name.html";
} elseif ($type == "match") {
$sql="select r.versus, r.venue, s.year FROM regmatch r, season s WHERE r.matchID='$ID' AND r.season=s.seasonID";
$result = mysql_query($sql) or die ("Error! bad select statement");
$row = mysql_fetch_array($result);
extract($row);
if ($venue=='Home') {
$teams = "Stanlow V $versus";
$teams2 = "Stanlow_vs_" . str_replace(" ", "_", strtolower($versus));
}
else {
$teams = "$versus V Stanlow";
$teams2 = str_replace(" ", "_", strtolower($versus)) . "_vs_Stanlow";
}
$year = str_replace("/", "-", $year);
$sql="select count(*) as num3 FROM loungeimages WHERE matchID='$ID'";
$result = mysql_query($sql) or die ("Error! bad select statement");
$row = mysql_fetch_array($result);
extract($row);
if ($_POST['p']=="ao") {
$link = "/match/$year/$ID-$teams2/" . strtolower($venue) . "/awayteam.html";
} elseif ($_POST['p']=="bb") {
$link = "/match/$year/$ID-$teams2/" . strtolower($venue) . "/bookiekiller.html";
} elseif ($_POST['p']=="tn") {
$link = "/match/$year/$ID-$teams2/" . strtolower($venue) . "/teamnews.html";
} elseif ($_POST['p']=="s") {
$link = "/match/$year/$ID-$teams2/" . strtolower($venue) . "/scores.html";
} elseif ($_POST['p']=="l") {
if ($num3>0) {
$sql="select MIN(imgID) as minumumimage FROM loungeimages WHERE matchID='$ID' GROUP BY matchID";
$result = mysql_query($sql) or die ("Error! bad select statement");
$row = mysql_fetch_array($result);
extract($row);
$link = "/match/$year/$ID-$teams2/" . strtolower($venue) . "/lounge/$minumumimage.html";
}
else {
$link = "/match/$year/$ID-$teams2/" . strtolower($venue) . "/lounge.html";
}
} elseif ($_POST['p']=="fv") {
$link = "/match/$year/$ID-$teams2/" . strtolower($venue) . "/fansviews.html";
} elseif ($_POST['p']=="fr") {
$link = "/match/$year/$ID-$teams2/" . strtolower($venue) . "/fansmatchreport.html";
} elseif ($_POST['p']=="ob") {
$link = "/match/$year/$ID-$teams2/" . strtolower($venue) . "/offtheball.html";
} elseif ($_POST['p']=="mq") {
$link = "/match/$year/$ID-$teams2/" . strtolower($venue) . "/matchquotes.html";
} elseif ($_POST['p']=="mr") {
$link = "/match/$year/$ID-$teams2/" . strtolower($venue) . "/matchreport.html";
}
}
elseif ($type == "match2") {
$sql="select r.versus, r.venue FROM regmatch2 r WHERE r.matchID='$ID'";
$result = mysql_query($sql) or die ("Error! bad select statement");
$row = mysql_fetch_array($result);
extract($row);
if ($venue=='Home') {
$teams = "Stanlow V $versus";
$teams2 = "Stanlow_vs_" . str_replace(" ", "_", strtolower($versus));
}
else {
$teams = "$versus V Stanlow";
$teams2 = str_replace(" ", "_", strtolower($versus)) . "_vs_Stanlow";
}
if ($_POST['p']=="ao") {
$link = "/match/perfectseason/$ID-$teams2/aboutoppo.html";
}
elseif ($_POST['p']=="bb") {
$link = "/match/perfectseason/$ID-$teams2/de_ja_lards_best_bet.html";
}
elseif ($_POST['p']=="tn") {
$link = "/match/perfectseason/$ID-$teams2/teamnews.html";
}
elseif ($_POST['p']=="mr") {
$link = "/match/perfectseason/$ID-$teams2/matchreport.html";
}
elseif ($_POST['p']=="rank") {
$link = "/match/perfectseason/$ID-$teams2/andys_old_rankin.html";
}
}
elseif ($type == "event") {
$link = "/fans/diary.html";
} elseif ($type == "picsubcat") {
$sql = "SELECT s.title as stitle, c.catID, c.title as ctitle, MIN(p.imgID) as imgID, se.section FROM picturesubcategory s, category c, picturetable p, section se WHERE c.sectionid=se.sectionid AND s.piccatID='$ID' AND s.catID=c.catID AND p.piccatID=s.piccatID";
$result = mysql_query($sql) or die ("<script language='javascript'>alert('" . $sql . "');</script>");
$row = mysql_fetch_array($result);
extract($row);
$ctitle = html_entity_decode($ctitle);
$ctitle = punct_remove($ctitle);
$stitle = html_entity_decode($stitle);
$stitle = punct_remove($stitle);
$section = strtolower($section);
$link = "/$section/$catID-$ctitle/$stitle/$imgID.html";
} elseif ($type == "paypal") {
$sql = "SELECT name FROM paypalitems WHERE itemID='$ID'";
$result = mysql_query($sql) or die ("Error! bad select statement");
$row = mysql_fetch_array($result);
extract($row);
$name = str_replace(" ", "_", $name);
$name = urlencode($name);
$link = "/products/" . $ID . "-" . $name . ".html";
} elseif ($type == "lookalike") {
$link = "/funnies/lookalikes/1.html";
} elseif ($type == "wallpaper") {
$link = "/gear/wallpapers/1.html";
}
$result = 0;
$time = time();
while(file_exists($time.'-'.$_FILES['myfile']['name']))
{
$time++;
}
while (file_exists($time.'-'.$_FILES['myfile2']['name']))
{
$time++;
}
$thumb_target_path = $thumb_destination_path . $time.'-'.$_FILES['myfile']['name'];
$large_target_path = $large_destination_path . $time.'-'.$_FILES['myfile2']['name'];
$filename = $time.'-'.$_FILES['myfile']['name'];
$filename2 = $time.'-'.$_FILES['myfile2']['name'];
if ((!isset($_FILES['myfile']['tmp_name']) || $_FILES['myfile']['tmp_name'] == "") || (!isset($_FILES['myfile2']['tmp_name']) || $_FILES['myfile2']['tmp_name'] == "")) {
$result = 3;
} else {
if (is_uploaded_file($_FILES['myfile']['tmp_name']) && is_uploaded_file($_FILES['myfile2']['tmp_name'])) {
if (getimagesize($_FILES['myfile']['tmp_name']) && getimagesize($_FILES['myfile2']['tmp_name'])) {
if ((move_uploaded_file($_FILES['myfile']['tmp_name'], $thumb_target_path)) && (move_uploaded_file($_FILES['myfile2']['tmp_name'], $large_target_path))) {
$result = 1;
$image_dim = getimagesize($thumb_target_path);
$image_dim2 = getimagesize($large_target_path);
if (($image_dim[0] != 75 || $image_dim[1] != 100) || ($image_dim2[0] != 230 || $image_dim2[1] != 199)) {
$result = 4;
unlink($thumb_target_path);
unlink($large_target_path);
} else {
if (isset($_POST['f'])) {
$publishingdate = $_POST['date'];
$sql2 = "INSERT INTO storyslide_future (thumb, large, thumbcaption, largecaption, link, publishingdate) VALUES ('$filename', '$filename2', '$caption', '$caption2', '$link', '$publishingdate')";
$res2 = mysql_query($sql2) or die ('<script language="javascript" type="text/javascript">alert("Error! bad insert statement");</script>');
} else {
$sql = "DELETE FROM storyslide WHERE thumbID='16'";
$res = mysql_query($sql) or die ("Error! bad delete statement");
$sql1 = "UPDATE storyslide SET thumbID=thumbID+1";
$res1 = mysql_query($sql1) or die ('<script language="javascript" type="text/javascript">alert("Error! bad update statement");</script>');
$sql2 = "INSERT INTO storyslide (thumbID, thumb, large, thumbcaption, largecaption, link) VALUES ('1', '$filename', '$filename2', '$caption', '$caption2', '$link')";
$res2 = mysql_query($sql2) or die ('<script language="javascript" type="text/javascript">alert("Error! bad insert statement");</script>');
}
}
}
} else {
$result = 2;
}
} else {
$result = 5;
}
}
sleep(1);
?>
<script language="javascript" type="text/javascript">window.top.window.stopUpload(<?php echo $result; ?>);</script>
<?php } ?>
And now the form:
<script src='upload_handler.js' language="javascript" type="text/javascript"></script>
</head>
<body>
<div id='wrapper'> <!-- start wrapper -->
<?php include("top.php"); ?>
<div id='pagetitle'> <!-- start pagetitle -->
<div id='pageimage'><img src='adminimages/note.jpg'/></div>
<div id='title'>Add to Thumbnails</div>
</div> <!-- end pagetitle -->
<div id='admincontrols'> <!-- start admincontrols -->
<center>
<div id='container' style='margin:0 0 0 240px;'>
<div id="content">
<form action='upload.php' method='post' enctype='multipart/form-data' target='upload_target' onSubmit='startUpload();'>
<input type='hidden' name='type' value='<?php echo $type; ?>' />
<?php
if (isset($_GET['ID'])) {
?>
<input type='hidden' name='ID' value='<?php echo $ID; ?>' />
<?php
}
?>
<?php
if (isset($_GET['p'])) {
?>
<input type='hidden' name='p' value='<?php echo $_GET['p']; ?>' />
<?php
}
?>
<?php
if (isset($_GET['f'])) {
?>
<input type='hidden' name='f' value='<?php echo $_GET['f']; ?>' />
<input type='hidden' name='date' value='<?php echo $_GET['date']; ?>' />
<?php
}
?>
<p id="f1_upload_process">Loading...<br/><img src="images/loader.gif" width="200" height="20" /><br/></p>
<div id='f1_upload_form'>
<div id='thumbnail_title' style='font-family:georgia;'>Thumbnail (This Image must be 75px in width and 100px in height):</div>
<div class='input_container'>
<div class='label_image'>File:</div>
<div class='input_image'><input name='myfile' type='file' size='70' class='inputbox'/></div>
</div>
<div class='input_container'>
<div class='label_image'>Caption:</div>
<div class='input_image'><input name='caption' type='text' maxlength='30' class='inputbox'/></div>
</div>
<div id='largerimage_title' style='font-family:georgia;'>Main Image (Only one image required. Minimum dimensions: 230px in width and 199px):</div>
<div class='input_container'>
<div class='label_image'>File:</div>
<div class='input_image'><input name='myfile2' type='file' size='70' class='inputbox'/></div>
</div>
<div class='input_container'>
<div class='label_image'>Caption:</div>
<div class='input_image'><input name='caption2' type='text' maxlength='200' class='inputbox'/></div>
</div>
<label><input type='submit' name='submitBtn' class='sbtn' value='Upload' /></label>
</div>
<iframe id='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px solid #fff;'></iframe>
</form>
</div>
</div>
</center>
</div>
<div id='controlbuttons'>
<a href='storyslide_write.php?type=<?php echo $type; if (isset($_GET['ID'])) { echo "&ID=" . $ID; } if (isset($_GET['n'])) { echo '&n=c'; } if (isset($_GET['revised'])) { echo '&revised=' . $_GET['revised']; } if (isset($_GET['c'])) { echo '&c=' . $_GET['c']; } ?>' id='savebutton' style='visibility:hidden;'><img src='adminimages/save.jpg' alt='Done' border='0' /></a>
<a href='admin.php'><img src='adminimages/home.jpg' border='0' alt='Main Menu'/></a></div>
</div> <!-- end wrapper -->
</body>
</html>
<?php } ?>
The input that I want to remove so we only have 1 image upload input is:
<input name='myfile' type='file' size='70' class='inputbox'/>
The validation needs to be removed from the first file in order to do this successfully.
I had a few stabs at this myself and noticed that the input field was being referenced in upload.php by the name of the input "myfile", so I searched the upload.php for anhything relating to this input name I found the following and tried to remove:
while(file_exists($time.'-'.$_FILES['myfile']['name']))
{
$time++;
}
$thumb_target_path = $thumb_destination_path . $time.'-'.$_FILES['myfile']['name'];
$filename = $time.'-'.$_FILES['myfile']['name'];
To no avail however...
Any pointers would be greatly appreciated :)
Try with the following code, it removes $_FILES['myfile'] from everywhere, including if statements, SQL queries, etc.:
Upload.php
// Edit upload location here
$thumb_destination_path = "../storyslide_thumbs/";
$large_destination_path = "../storyslide_large/";
$type = $_POST['type'];
if (isset($_POST['ID'])) {
$ID = (int) $_POST['ID'];
}
$caption = mysql_real_escape_string($_POST['caption']);
$caption2 = mysql_real_escape_string($_POST['caption2']);
if ($type == "article" || $type == "editarticle") {
$sql="select a.title, a.category, c.title as cattitle, s.section as stitle, c.type from article a, category c, section s WHERE c.catID=a.category AND c.sectionid=s.sectionid AND a.articleID='$ID'";
$result = mysql_query($sql) or die ("Error! bad select statement");
$row = mysql_fetch_array($result);
extract($row);
$stitle = html_entity_decode($stitle);
$stitle = punct_remove($stitle);
$linktitle = html_entity_decode($title);
$linktitle = punct_remove($linktitle);
$cattitle = html_entity_decode($cattitle);
$cattitle = punct_remove($cattitle);
if ($category=='43') {
$link = "/fans/obituaries/$ID-$linktitle..html";
} else {
if ($type=="Blog") {
$ID = "b$ID";
$cattitle = $cattitle . "-" . $category;
} else {
$cattitle = $category . "-" . $cattitle;
}
$link = "/$stitle/$cattitle/$ID-$linktitle.html";
}
} elseif ($type == "player") {
$sql = "SELECT name FROM player WHERE playerID='$ID'";
$result = mysql_query($sql) or die ("Error! bad select statement");
$row = mysql_fetch_array($result);
extract($row);
$name = html_entity_decode($name);
$name = punct_remove($name);
$link = "/players/squad/$ID-$name.html";
} elseif ($type == "match") {
$sql="select r.versus, r.venue, s.year FROM regmatch r, season s WHERE r.matchID='$ID' AND r.season=s.seasonID";
$result = mysql_query($sql) or die ("Error! bad select statement");
$row = mysql_fetch_array($result);
extract($row);
if ($venue=='Home') {
$teams = "Stanlow V $versus";
$teams2 = "Stanlow_vs_" . str_replace(" ", "_", strtolower($versus));
}
else {
$teams = "$versus V Stanlow";
$teams2 = str_replace(" ", "_", strtolower($versus)) . "_vs_Stanlow";
}
$year = str_replace("/", "-", $year);
$sql="select count(*) as num3 FROM loungeimages WHERE matchID='$ID'";
$result = mysql_query($sql) or die ("Error! bad select statement");
$row = mysql_fetch_array($result);
extract($row);
if ($_POST['p']=="ao") {
$link = "/match/$year/$ID-$teams2/" . strtolower($venue) . "/awayteam.html";
} elseif ($_POST['p']=="bb") {
$link = "/match/$year/$ID-$teams2/" . strtolower($venue) . "/bookiekiller.html";
} elseif ($_POST['p']=="tn") {
$link = "/match/$year/$ID-$teams2/" . strtolower($venue) . "/teamnews.html";
} elseif ($_POST['p']=="s") {
$link = "/match/$year/$ID-$teams2/" . strtolower($venue) . "/scores.html";
} elseif ($_POST['p']=="l") {
if ($num3>0) {
$sql="select MIN(imgID) as minumumimage FROM loungeimages WHERE matchID='$ID' GROUP BY matchID";
$result = mysql_query($sql) or die ("Error! bad select statement");
$row = mysql_fetch_array($result);
extract($row);
$link = "/match/$year/$ID-$teams2/" . strtolower($venue) . "/lounge/$minumumimage.html";
}
else {
$link = "/match/$year/$ID-$teams2/" . strtolower($venue) . "/lounge.html";
}
} elseif ($_POST['p']=="fv") {
$link = "/match/$year/$ID-$teams2/" . strtolower($venue) . "/fansviews.html";
} elseif ($_POST['p']=="fr") {
$link = "/match/$year/$ID-$teams2/" . strtolower($venue) . "/fansmatchreport.html";
} elseif ($_POST['p']=="ob") {
$link = "/match/$year/$ID-$teams2/" . strtolower($venue) . "/offtheball.html";
} elseif ($_POST['p']=="mq") {
$link = "/match/$year/$ID-$teams2/" . strtolower($venue) . "/matchquotes.html";
} elseif ($_POST['p']=="mr") {
$link = "/match/$year/$ID-$teams2/" . strtolower($venue) . "/matchreport.html";
}
}
elseif ($type == "match2") {
$sql="select r.versus, r.venue FROM regmatch2 r WHERE r.matchID='$ID'";
$result = mysql_query($sql) or die ("Error! bad select statement");
$row = mysql_fetch_array($result);
extract($row);
if ($venue=='Home') {
$teams = "Stanlow V $versus";
$teams2 = "Stanlow_vs_" . str_replace(" ", "_", strtolower($versus));
}
else {
$teams = "$versus V Stanlow";
$teams2 = str_replace(" ", "_", strtolower($versus)) . "_vs_Stanlow";
}
if ($_POST['p']=="ao") {
$link = "/match/perfectseason/$ID-$teams2/aboutoppo.html";
}
elseif ($_POST['p']=="bb") {
$link = "/match/perfectseason/$ID-$teams2/de_ja_lards_best_bet.html";
}
elseif ($_POST['p']=="tn") {
$link = "/match/perfectseason/$ID-$teams2/teamnews.html";
}
elseif ($_POST['p']=="mr") {
$link = "/match/perfectseason/$ID-$teams2/matchreport.html";
}
elseif ($_POST['p']=="rank") {
$link = "/match/perfectseason/$ID-$teams2/andys_old_rankin.html";
}
}
elseif ($type == "event") {
$link = "/fans/diary.html";
} elseif ($type == "picsubcat") {
$sql = "SELECT s.title as stitle, c.catID, c.title as ctitle, MIN(p.imgID) as imgID, se.section FROM picturesubcategory s, category c, picturetable p, section se WHERE c.sectionid=se.sectionid AND s.piccatID='$ID' AND s.catID=c.catID AND p.piccatID=s.piccatID";
$result = mysql_query($sql) or die ("<script language='javascript'>alert('" . $sql . "');</script>");
$row = mysql_fetch_array($result);
extract($row);
$ctitle = html_entity_decode($ctitle);
$ctitle = punct_remove($ctitle);
$stitle = html_entity_decode($stitle);
$stitle = punct_remove($stitle);
$section = strtolower($section);
$link = "/$section/$catID-$ctitle/$stitle/$imgID.html";
} elseif ($type == "paypal") {
$sql = "SELECT name FROM paypalitems WHERE itemID='$ID'";
$result = mysql_query($sql) or die ("Error! bad select statement");
$row = mysql_fetch_array($result);
extract($row);
$name = str_replace(" ", "_", $name);
$name = urlencode($name);
$link = "/products/" . $ID . "-" . $name . ".html";
} elseif ($type == "lookalike") {
$link = "/funnies/lookalikes/1.html";
} elseif ($type == "wallpaper") {
$link = "/gear/wallpapers/1.html";
}
$result = 0;
$time = time();
while (file_exists($time.'-'.$_FILES['myfile2']['name']))
{
$time++;
}
$large_target_path = $large_destination_path . $time.'-'.$_FILES['myfile2']['name'];
$filename = '';
$filename2 = $time.'-'.$_FILES['myfile2']['name'];
if ((!isset($_FILES['myfile2']['tmp_name']) || $_FILES['myfile2']['tmp_name'] == "")) {
$result = 3;
} else {
if (is_uploaded_file($_FILES['myfile2']['tmp_name'])) {
if (getimagesize($_FILES['myfile2']['tmp_name'])) {
if (((move_uploaded_file($_FILES['myfile2']['tmp_name'], $large_target_path))) {
$result = 1;
$image_dim2 = getimagesize($large_target_path);
if (($image_dim2[0] != 230 || $image_dim2[1] != 199)) {
$result = 4;
unlink($large_target_path);
} else {
if (isset($_POST['f'])) {
$publishingdate = $_POST['date'];
$sql2 = "INSERT INTO storyslide_future (thumb, large, thumbcaption, largecaption, link, publishingdate) VALUES ('$filename', '$filename2', '$caption', '$caption2', '$link', '$publishingdate')";
$res2 = mysql_query($sql2) or die ('<script language="javascript" type="text/javascript">alert("Error! bad insert statement");</script>');
} else {
$sql = "DELETE FROM storyslide WHERE thumbID='16'";
$res = mysql_query($sql) or die ("Error! bad delete statement");
$sql1 = "UPDATE storyslide SET thumbID=thumbID+1";
$res1 = mysql_query($sql1) or die ('<script language="javascript" type="text/javascript">alert("Error! bad update statement");</script>');
$sql2 = "INSERT INTO storyslide (thumbID, thumb, large, thumbcaption, largecaption, link) VALUES ('1', '$filename', '$filename2', '$caption', '$caption2', '$link')";
$res2 = mysql_query($sql2) or die ('<script language="javascript" type="text/javascript">alert("Error! bad insert statement");</script>');
}
}
}
} else {
$result = 2;
}
} else {
$result = 5;
}
}
sleep(1);
?>
<script language="javascript" type="text/javascript">window.top.window.stopUpload(<?php echo $result; ?>);</script>
<?php } ?>
public function GetRoomTotalForDay($room, $date = null) {
if(!isset($date)) {
$date = date("Y-m-d");
}
// This function is going to return the number of shoes processed that day
// First of all work out which scanner number is required for the room
$scanner = $this->GetScannerNumber($room);
// Next generate the SQL
$sql = "SELECT `scanners.KordNo`, `scanners.BundleNumber`
FROM `scanners`
WHERE `scanners.Date` = '" . $date . "'
AND `scanners.Scanner` IN (";
foreach($scanner as $x) {
$sql .= $x . ",";
}
$sql .= "0);";
// And query the database
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
$return[] = $row;
}
// It is more complicated for Kettering, Closing & Rushden, we need to filter the list
if(in_array($room, array(3,4,5))) {
foreach($return as $x) {
$sql = "SELECT `scanners.Scanner`
FROM `scanners`
WHERE `scanners.KordNo` = " . $x['scanners.KordNo'] . "
AND `scanners.BundleNumber` = " . $x['scanner.BundleNumber'] . "
ORDER BY `scanners.Date` DESC
LIMIT 1,1;";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
// If scanner 7, it's been through bottom stock so need to find previous
if($row[0] == 7) {
$sql = "SELECT `scanners.Scanner`
FROM `scanners`
WHERE `scanners.KordNo` = " . $x['scanners.KordNo'] . "
AND `scanners.BundleNumber` = " . $x['scanners.BundleNumber'] . "
ORDER BY `scanners.Date` DESC
LIMIT 2,1;";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
}
if($row[0] == 10 && $room == 3) {
$finalReturn[] = $x;
} elseif($row[0] == 11 && $room == 4) {
$finalReturn[] = $x;
} elseif($row[0] == 15 && $room == 5) {
$finalReturn[] = $x;
}
}
$return = $finalReturn;
}
// Now we have a list of tickets, we need to query how many pairs are in each ticket
$total = 0;
foreach($return as $x) {
$sql = "SELECT `QtyIssued`
FROM `ArchiveBundle`
WHERE `ArchiveBundle.KordNo` = '" . $x['scanners.KordNo'] . "'
AND `ArchiveBundle.BundleNumber` = '" . $x['scanners.BundleNumber'] . "';";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
$total += $row[0];
}
return $total;
}
I have edited the class above which pulls no results. However the original class below pulls results out. Please can someone help.
public function GetRoomTotalForDay($room, $date = null) {
if(!isset($date)) {
$date = date("Y-m-d");
}
// This function is going to return the number of shoes processed that day
// First of all work out which scanner number is required for the room
$scanner = $this->GetScannerNumber($room);
// Next generate the SQL
$sql = "SELECT `KordNo`, `BundleNumber`
FROM `scanners`
WHERE `Date` = '" . $date . "'
AND `Scanner` IN (";
foreach($scanner as $x) {
$sql .= $x . ",";
}
$sql .= "0);";
// And query the database
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
$return[] = $row;
}
// It is more complicated for Kettering, Closing & Rushden, we need to filter the list
if(in_array($room, array(3,4,5))) {
foreach($return as $x) {
$sql = "SELECT `Scanner`
FROM `scanners`
WHERE `KordNo` = " . $x['KordNo'] . "
AND `BundleNumber` = " . $x['BundleNumber'] . "
ORDER BY `Date` DESC
LIMIT 1,1;";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
// If scanner 7, it's been through bottom stock so need to find previous
if($row[0] == 7) {
$sql = "SELECT `Scanner`
FROM `scanners`
WHERE `KordNo` = " . $x['KordNo'] . "
AND `BundleNumber` = " . $x['BundleNumber'] . "
ORDER BY `Date` DESC
LIMIT 2,1;";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
}
if($row[0] == 10 && $room == 3) {
$finalReturn[] = $x;
} elseif($row[0] == 11 && $room == 4) {
$finalReturn[] = $x;
} elseif($row[0] == 15 && $room == 5) {
$finalReturn[] = $x;
}
}
$return = $finalReturn;
}
// Now we have a list of tickets, we need to query how many pairs are in each ticket
$total = 0;
foreach($return as $x) {
$sql = "SELECT `QtyIssued`
FROM `ArchiveBundle`
WHERE `KordNo` = '" . $x['KordNo'] . "'
AND `BundleNumber` = '" . $x['BundleNumber'] . "';";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
$total += $row[0];
}
return $total;
}
The class above counts the amount of shoes produced. I have had to edit this class so it can exclude certain types of shoes but it does not seem to pull any results for some reason.
UPDATE.
This is the class scanners. This is what its currently at the moment. I'm fairly new to php and this code was writted by my predecessor.
<?php
class CHScanners {
var $conn;
// Constructor, connect to the database
public function __construct() {
require_once "/var/www/reporting/settings.php";
define("DAY", 86400);
if(!$this->conn = mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD)) die(mysql_error());
if(!mysql_select_db(DB_DATABASE_NAME, $this->conn)) die(mysql_error());
}
public function ListRoomBundles($room, $date, $dateTo = null) {
// If dateTo hasn't been set, make it now
if(!isset($dateTo) or $dateTo == "") {
$dateTo = $date;
}
// Return an array with each bundle number and the quantity for each day
$scanner = $this->GetScannerNumber($room);
$sql = "SELECT * FROM `scanners` WHERE `Scanner` IN (";
foreach($scanner as $x) {
$sql .= $x . ",";
}
$sql .= "0)
AND `Date` BETWEEN '" . $date . "' AND '" . $dateTo . "'
GROUP BY `KordNo`, `BundleNumber`;";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
$sql = "SELECT `BundleReference`, `QtyIssued`, `WorksOrder`
FROM `ArchiveBundle`
WHERE `KordNo` = '" . $row['KordNo'] . "'
AND `BundleNumber` = '" . $row['BundleNumber'] . "';";
$result2 = mysql_query($sql);
while($row = mysql_fetch_array($result2)) {
if($row[0] != "") {
$final[] = $row;
} else {
$final[] = array("Can't find bundle number", "N/A");
}
}
}
return $final;
}
public function GetRoomTotalForDay($room, $date = null) {
if(!isset($date)) {
$date = date("Y-m-d");
}
// This function is going to return the number of shoes processed that day
// First of all work out which scanner number is required for the room
$scanner = $this->GetScannerNumber($room);
// Next generate the SQL
$sql = "SELECT `scanners.KordNo`, `scanners.BundleNumber`
FROM `scanners,TWOrder,Stock`
INNER JOIN TWORDER ON `scanners.KordNo` = `TWOrder.KOrdNo`
AND `scanners.Date` = '" . $date . "'
INNER JOIN Stock ON `TWOrder.Product` = `Stock.ProductCode`
AND `Stock.ProductGroup` NOT BETWEEN 400 AND 650
AND `scanners.Scanner` IN (
ORDER BY `scanners.KordNo' ASC";
foreach($scanner as $x) {
$sql .= $x . ",";
}
$sql .= "0);";
// And query the database
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
$return[] = $row;
}
// It is more complicated for Kettering, Closing & Rushden, we need to filter the list
if(in_array($room, array(3,4,5))) {
foreach($return as $x) {
$sql = "SELECT `scanners.Scanner`
FROM `scanners`
WHERE `scanners.KordNo` = " . $x['scanners.KordNo'] . "
AND `scanners.BundleNumber` = " . $x['scanners.BundleNumber'] . "
ORDER BY `scanners.Date` DESC
LIMIT 1,1;";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
// If scanner 7, it's been through bottom stock so need to find previous
if($row[0] == 7) {
$sql = "SELECT `scanners.Scanner`
FROM `scanners`
WHERE `scanners.KordNo` = " . $x['scanners.KordNo'] . "
AND `scanners.BundleNumber` = " . $x['scanners.BundleNumber'] . "
ORDER BY `Date` DESC
LIMIT 2,1;";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
}
if($row[0] == 10 && $room == 3) {
$finalReturn[] = $x;
} elseif($row[0] == 11 && $room == 4) {
$finalReturn[] = $x;
} elseif($row[0] == 15 && $room == 5) {
$finalReturn[] = $x;
}
}
$return = $finalReturn;
}
// Now we have a list of tickets, we need to query how many pairs are in each ticket
$total = 0;
foreach($return as $x) {
$sql = "SELECT `QtyIssued`
FROM `ArchiveBundle`
WHERE `KordNo` = '" . $x['scanners.KordNo'] . "'
AND `BundleNumber` = '" . $x['scanners.BundleNumber'] . "';";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
$total += $row[0];
}
return $total;
}
// We need a function to select the previous Monday from a given date
public function GetPreviousMonday($timestamp) {
if(date("N", $timestamp) == 1) {
return $timestamp;
} elseif(in_array(date("N", $timestamp), array(2, 3, 4, 5))) {
return $timestamp - (date("N", $timestamp)-1)*DAY;
} elseif(in_array(date("N", $timestamp), array(6, 7))) {
return $timestamp + (date("N", $timestamp)*(-1)+8)*DAY;
} else {
return false;
}
}
public function GetRoomName($room) {
// Return the room name from the room number
switch($room) {
case 1:
return "Skin Room";
case 2:
return "Clicking Room";
case 3:
return "Kettering";
case 4:
return "Closing Room";
case 5:
return "Rushden";
case 6:
return "Assembly Room";
case 7:
return "Lasting Room";
case 8:
return "Making Room";
case 9:
return "Finishing Room";
case 10:
return "Shoe Room";
}
}
public function GetDueDateForWorksOrder($worksOrderNumber) {
$sql = "SELECT `DueDate`
FROM `TWOrder`
WHERE `WorksOrderNumber` = '" . $worksOrderNumber . "';";
mysql_select_db(DB_DATABASE_NAME, $this->conn);
$result = mysql_query($sql, $this->conn);
$row = mysql_fetch_row($result);
return $row[0];
}
private function GetScannerNumber($room) {
// Get the room number from the scanner number
switch($room) {
case 1:
$scanner = array(3);
break;
case 2:
$scanner = array(10,11,15);
break;
case 3:
$scanner = array(5);
break;
case 4:
$scanner = array(5);
break;
case 5:
$scanner = array(5);
break;
case 6:
$scanner = array(6);
break;
case 7:
$scanner = array(9);
break;
case 8:
$scanner = array(8);
break;
case 9:
$scanner = array(12);
break;
case 10:
$scanner = array(14);
break;
default:
$scanner = array(0);
break;
}
return $scanner;
}
}
?>
You have a typo - a letter is missing in the last line of this block of code:
if(in_array($room, array(3,4,5))) {
foreach($return as $x) {
$sql = "SELECT `scanners.Scanner`
FROM `scanners`
WHERE `scanners.KordNo` = " . $x['scanners.KordNo'] . "
AND `scanners.BundleNumber` = " . $x['scanner.BundleNumber'] .
Here the array item should be $x['scanners.BundleNumber'].