Author Topic: INSERT with PHP to mysql - no errors but no success  (Read 616 times)

Stryyder

  • New Member
  • *
  • Posts: 15
  • Karma: 0
    • View Profile
I had been avoiding that as I know how ugly some of it is  ;D

It's sort of a sketchpad of brainstorming and learning. My form display code is unnecessarily repetitive too. I certainly plan to clean it all up but I really just want basic functionality first haha  Oh boy, here's my dirty closet.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
    <?php 
   
if (isset($_GET['check'])){
   
header("Location: logRev.php");
   exit();
    }
    
?>

   
   <!DOCTYPE html>
   
  <html><head><meta charset="UTF-8"><title>fB: Rev Log</title><!-- ######### BASIC HEADER STUFF ######### -->   
  <?php include "sys/config.php"?>
      <link href="style.css" rel="stylesheet" type="text/css" media="all"> <!-- ######### INCLUDE BASIC STYLESHEET ######### -->
   <link href="styleSmall.css" rel="stylesheet" type="text/css" media="screen and (max-width: 320px)"></HEAD> <!-- ######### INCLUDE IPHONE SIZED STYLESHEET ######### -->
  <body><div id="container"><!-- ######### WRAP THE WHOLE PAGE IN A CONTAINER ######### -->
  <?php addMenu(); ?> <!-- ### INCLUDE MENU FROM CONFIG.PHP ### -->
  
   <div class="dbRev"><!-- ### DATA CONTAINER START ### -->
   <div class="logLeft"><!-- ### LEFT SIDE OF PAGE ### -->
   <TABLE align="right"><TR><th>.</th><th>Date</th><th>Minutes</th><th>Seconds</th><th>Paid</th></tr><!-- ### START A TABLE WITH HEADERS ### -->
   <?php 
  
// INITIALIZE VARIABLES WE'LL NEED FOR REPORTS AND WHAT-NOT
  
if (isset($_POST["ChooseYear"])) {
  
$ChosenYear $_POST["ChooseYear"];
  
}else{  
  
$ChosenYear "All";
  
}
  
  
// INITIALIZE VARIABLES USED FOR COUNTING DATA RECIEVED FROM MYSQL DATABASE
  
$totalMinutes 0;
  
$totalSeconds 0;
  
$totalTime 0;
  
$totalPay 0;
  
$optionSelected '';
  
  
/* #######################   CHOSEN YEAR IS 2017   ##################################### */
  
if ($ChosenYear == '2017'){ // USE THIS BRANCH IF USER SELECTED 2017 FROM FORM DROPDOWN
  
$logResult""; // WIPE OUT LOGRESULT FOR INCOMING STRING OPS
  
$optionSelected "2017";   // SET A VAR TO SHOW USER WHAT OPTION THEY SELECTED
  
  
// GET THE DATA FROM THE logrev TABLE ORDERED BY THE id COLUMN IN DESCENDING ORDER
  
$stmt $db->prepare("SELECT * FROM logrev WHERE YEAR(Date) = :Date ORDER BY id DESC"); //THIS IS THE SQL WE WILL RUN
  
$stmt->bindValue(':Date','2017'); // TELLS THE LINE ABOVE WHAT WE MEAN BY :DATE
  
$stmt->execute(); // FIRE THE MISSILES (RUN THE SQL STATEMENT WITH BINDINGS INCLUDED
  

  
while ($row $stmt->fetch(PDO::FETCH_ASSOC)){  // LOOP THROUGH THE DATABASE GRABBING VALUES
  
$logrevDate htmlentities($row['Date']);       // ASSIGN VALUES TO VARIABLES BASED ON CURRENT ITERATION OF WHILE LOOP
  
$logrevMinutes htmlentities($row['Minutes']);
  
$logrevSeconds htmlentities($row['Seconds']);
  
$logrevPaid htmlentities($row['Paid']);
  
$logrevTimestamp htmlentities($row['timestamp']);
  

  
// PUSH THE DATA OUT AND ADD UP VALUES AS WE GO TO CREATE TOTALS
  
$logResult "<TR><td class='timestamp'>" $logrevTimestamp "</td><TD>" $logrevDate "</TD><TD>" $logrevMinutes "</TD><TD>" $logrevSeconds "</TD><TD>" $logrevPaid "</TD></TR>";
  
$totalMinutes $totalMinutes + ($row['Minutes']); // ADD MINUTES AS WE GO
  
$totalSeconds $totalSeconds + ($row['Seconds']); // ADD SECONDS AS WE GO
  
$totalPay += ($row['Paid']);            // TOTAL UP PAY COLUMN
  
echo $logResult;
  
}}
  

  

  
/* #######################   CHOSEN YEAR IS 2016   ##################################### */
  
elseif ($ChosenYear == '2016') {
  
$logResult"";
  
$optionSelected "2016";
  

  
// GET THE DATA FROM THE logrev TABLE ORDERED BY THE id COLUMN IN DESCENDING ORDER
  
$stmt $db->prepare("SELECT * FROM logrev WHERE YEAR(Date) = :Date ORDER BY id DESC"); 
  
$stmt->bindValue(':Date','2016'); 
  
$stmt->execute(); 
  

  
while ($row $stmt->fetch(PDO::FETCH_ASSOC)){
  
$logrevDate htmlentities($row['Date']);
  
$logrevMinutes htmlentities($row['Minutes']);
  
$logrevSeconds htmlentities($row['Seconds']);
  
$logrevPaid htmlentities($row['Paid']);
  
$logrevTimestamp htmlentities($row['timestamp']);
  
$logResult "<TR><td class='timestamp'>" $logrevTimestamp "</td><TD>" $logrevDate "</TD><TD>" $logrevMinutes "</TD><TD>" $logrevSeconds "</TD><TD>" $logrevPaid "</TD></TR>";
  
$totalMinutes $totalMinutes + ($row['Minutes']);
  
$totalSeconds $totalSeconds + ($row['Seconds']);
  
$totalPay $totalPay + ($row['Paid']);
  
echo $logResult;
  
}}
  

  

  
/* #######################   CHOSEN YEAR IS CURRENT MONTH   ##################################### */
  
elseif ($ChosenYear == 'currentMonth') {
  
$logResult"";
  
$optionSelected "This Month";
  
  
// GET THE DATA FROM THE logrev TABLE ORDERED BY THE id COLUMN IN DESCENDING ORDER
  
$stmt $db->prepare("SELECT * FROM logrev WHERE MONTH(Date) = :Month ORDER BY id DESC"); 
  
$stmt->bindValue(':Month',$currentMonth); 
  
$stmt->execute(); 
  

  
while ($row $stmt->fetch(PDO::FETCH_ASSOC)){
  
$logrevDate htmlentities($row['Date']);
  
$logrevMinutes htmlentities($row['Minutes']);
  
$logrevSeconds htmlentities($row['Seconds']);
  
$logrevPaid htmlentities($row['Paid']);
 
$logrevTimestamp htmlentities($row['timestamp']);
 
$logResult "<TR><td class='timestamp'>" $logrevTimestamp "</td><TD>" $logrevDate "</TD><TD>" $logrevMinutes "</TD><TD>" $logrevSeconds "</TD><TD>" $logrevPaid "</TD></TR>";
 
$totalMinutes $totalMinutes + ($row['Minutes']);
 
$totalSeconds $totalSeconds + ($row['Seconds']);
 
$totalPay $totalPay + ($row['Paid']);
 
echo $logResult;
 
}}
 

 

 
/*  #######################   DEFAULT OPTION   ##################################### */
 
else {
 
$logResult"";
 
$optionSelected "All Data";
 

 
$stmt $db->query("SELECT * FROM logrev ORDER BY id DESC");
 
while ($row $stmt->fetch(PDO::FETCH_ASSOC)){
 
$logrevDate htmlentities($row['Date']);
 
$logrevMinutes htmlentities($row['Minutes']);
 
$logrevSeconds htmlentities($row['Seconds']);
 
$logrevPaid htmlentities($row['Paid']);
 
$logrevTimestamp htmlentities($row['timestamp']);
 
$logResult "<TR><td class='timestamp'>" $logrevTimestamp "</td><TD>" $logrevDate "</TD><TD>" $logrevMinutes "</TD><TD>" $logrevSeconds "</TD><TD>" $logrevPaid "</TD></TR>";
 
$totalMinutes $totalMinutes + ($row['Minutes']);
 
$totalSeconds $totalSeconds + ($row['Seconds']);
 
$totalPay $totalPay + ($row['Paid']);
 
echo $logResult;
 
}}
 
?>

 
 </TABLE> </div><!-- ### CLOSE MAIN TABLE AND LEFT SIDE OF PAGE ### -->
 
 
 <!-- ##################### DISPLAY THE STATS ###################-->
 <?php $totalTime = (integer)($totalMinutes + ($totalSeconds 60)); // CASTING RESULT TO AN INTEGER TO GET RID OF WEIRD EXTRA MATH  ?>
 <div class="logRight">
 <?php echo "<h3>Option Selected: " $optionSelected "</h3>" "<h3>Today is: " $queryDate "</h3><h4>TOTALS</h4> Minutes: " $totalMinutes "</br>Seconds: " $totalSeconds "</br>Total Time: " $totalTime "</br>Year Selected: " $ChosenYear "</br>Total Paid: $" $totalPay?>
 </br></br></br>
 
 <!-- ###################### BEGIN ADD RECORD FORM  ################################-->
 <form name="logRevAdd" action="logRev.php?check=1" method="POST">
 <input type="date" name="addDate" required class="formInput"></br>
 <input type="number" id="addMinutes" name="addMinutes" min="1" max="99" required placeholder="Add Minutes" class="formInput"></br>
 <input type="number" id="addSeconds" name="addSeconds" min="1" max="99" required placeholder="Add Seconds" class="formInput"></br>
 <input type="number" id="addPay" name="addPay" min="1" max="99" required placeholder="Add Pay" class="formInput" step="any"></br>
 </br>
 <input type="submit" name="Insert" value="Add Record" id="addRecord">
 </form>
 </br>
 
 <!-- ###################### BEGIN STATS ADJUST FORM DROPDOWN ######################-->
  REV LOG </br>
  <form id='selYear' action='' method='POST'>
      <select name='ChooseYear'>
  <option value=''>CHOOSE A YEAR</option>
  <option value='currentMonth'>Current Month</option>
      <option value='All'>All</option>
      <option value='2017'>2017</option>
      <option value='2016'>2016</option>
      </select>
      <input type='submit' name='Submit' value='Go'>
      </form>
 
  <!-- ###################### PROCESS OUR ADD RECORD ENTRIES ######################-->
 <?php
 
 
if(isset($_POST['Insert']))
 
{
 

 
//PREPARE THE INSERT OPERATION
 
$pdoQuery "INSERT INTO `logrev`(`Date`, `Minutes`, `Seconds`, `Paid`) VALUES (:addDate,:addMinutes,:addSeconds,:addPay)";
 
$pdoResult $db->prepare($pdoQuery);
 

 
//EXECUTE THE INSERT OPERATION
 
$pdoExec $pdoResult->execute(array(":addDate"=>$_POST['addDate'], ":addMinutes"=>$_POST['addMinutes'], ":addSeconds"=>$_POST['addSeconds'], ":addPay"=>$_POST['addPay']));
 

 
if($pdoExec)
 
{
 
echo 'Data Entered Successfully';
 

 
}else{
 
echo 'No Data Entered';
 

 
 }
 
}
 
 
?>

 </div></div></div></body></html><!-- ### CLOSE RIGHT SIDE OF PAGE, DBREV, CONTAINER DIVS AND THE WHOLE DOC ### -->
You only get about 100 years. What are you doing?

PHP Help Forum

Re: INSERT with PHP to mysql - no errors but no success
« Reply #15 on: March 20, 2017, 01:31:43 pm »


Kevin Rubio

  • Professional PHP Helper
  • Senior Member
  • *
  • Posts: 1780
  • Karma: 107
  • Programmer Available for hire
    • View Profile
    • Galaxy Internet
PDO Bumpstart Database

The XY Problem
The XY problem is asking about your attempted solution (X) rather than your actual problem (Y). This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help. http://xyproblem.info/

PHP Help Forum

Re: INSERT with PHP to mysql - no errors but no success
« Reply #16 on: March 20, 2017, 01:41:49 pm »



PHP Help Forum

Re: INSERT with PHP to mysql - no errors but no success
« Reply #17 on: March 20, 2017, 02:42:43 pm »