· 8 years ago · Aug 18, 2018, 12:46 AM
1what can make an update query not to update but return success
2class queryClass extends MYSQL{ //MYSQL is for connecting to database
3 //table fields
4 var $user_table = ''; //table names that will be used in all names, each query method will input its own table name
5
6 //connect to database
7 function dbconnect(){
8 MYSQL::dbconnect();
9 }
10 //prevent injection
11 function qry($query) {
12 $this->dbconnect();
13 $args = func_get_args();
14 $query = array_shift($args);
15 $query = str_replace("?", "%s", $query);
16 $args = array_map('mysql_real_escape_string', $args);
17 array_unshift($args,$query);
18 $query = call_user_func_array('sprintf',$args);
19 $result = mysql_query($query) or die(mysql_error());
20 if($result){
21 return $result;
22 }else{
23 $error = "Error";
24 return $result;
25 }
26 //update quote function
27 function updatequote($table, $message1, $message2, $column_name1, $column_name2, $column_name3, $quote_id){
28 $this->dbconnect();
29 $this->quote_id = $quote_id;
30 echo $message1, $message2;
31
32 //make sure table name is set
33 $this->user_table = $table;
34 $this->column_name1 = $column_name1;
35 $this->column_name2 = $column_name2;
36 $this->column_name3 = $column_name3;
37
38 //execute login via qry function that prevents MySQL injections
39 $result = $this->qry("UPDATE ".$this->user_table." SET ".$this->column_name2."='?', ".$this->column_name3."='?'
40 WHERE ".$this->column_name1."='?';", $message1, $message2, $this->quote_id );
41 // $result = mysql_query("INSERT INTO ".$this->user_table."(username, password) VALUES('$username', '$password')");
42 if($result){
43 $_SESSION['success'] = "The Update Was Successfully Saved";
44 header('location: edit_quotes.html');
45
46 exit();
47 return true;
48 }else{
49 $_SESSION['success'] = "The Update Was Not Saved".mysql_error();
50 header('location: edit_quotes.html');
51 exit(); //do something on FAILED login
52 return false;
53 }
54 }
55
56 //quote form
57 function quoteEditorform($formname, $formclass, $formaction, $helptext, $first, $second){
58 //conect to DB
59 $this->dbconnect();
60
61 echo"
62 <form name="$formname" method="post" id="$formname" class="$formclass" enctype="application/x-www-form-urlencoded" action="$formaction">
63
64 <h2>$helptext</h2>
65 <div><label for=qoute>NGWA QUOTE
66 <input type=button value='Quote' onclick="wrapInTags(this.form.message1,'quote')">insert [quote].[/quote]tags
67 </label>
68 <textarea name="message1" cols="40" rows="4" onclick="copySelection(this)">$first</textarea><br>
69 </div>
70 <div><label for="qoute">ENGLISH MEANING
71 <input type=button value='Meaning' onclick="wrapInTags(this.form.message2,'meaning')">
72 insert [meaning].[/meaning]tags
73 </label>
74 ".$record['meaning']."
75 <textarea name="message2" cols="40" rows="4" onclick="copySelection(this)">$second</textarea></div>
76 <input name="action" id="action" value="sendeditedquote" type="hidden">
77 <div>
78
79 <input name="submit" id="submitV value="Save" type="submit"></div>
80
81 </form>
82 <div align="center"><a href="edit_quotes.html?do=read_bb_codes">Read Before Posting</a></div>
83 "; }
84
85 function createquotetable($tablename){
86 //connect to DB
87 $this->dbconnect();
88 $qry = "CREATE TABLE IF NOT EXISTS ".$tablename."(
89 quote_id INT(8) NOT NULL AUTO_INCREMENT,
90 ngwaquote TEXT NOT NULL,
91 meaning TEXT NOT NULL,
92 saved_date date,
93 PRIMARY KEY (quote_id)
94 ) TYPE=INNODB
95 ";
96 $result = $this->qry($qry);
97 return;
98 }
99
100// instantiate all other needed classes
101$cleaner = new cleanPost();
102$connect = new MySQL();
103$connect->dbconnect();// connect to a database
104$bbcode = new BBCode();
105$log = new logmein();
106
107 if($_REQUEST['action'] == "sendeditedquote"){
108 //post all the values to the database using our main class
109
110/*topic field checking */
111 if($_REQUEST['message1'] == "" || $_REQUEST['topic'] > 600) {
112 $errmsg_arr[] = 'Sorry You Can't Send An Empty Qoute OR quote greater than 500 characters at a time';
113 $errflag = true;
114 }
115
116 if($_REQUEST['message2'] == "" ) {
117 $errmsg_arr[] = 'Sorry You Can't Update With An Empty Qoute';
118 $errflag = true;
119 }
120
121 //If there are input validations, redirect back
122 if($errflag) {
123 $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
124 session_write_close();
125 header("location: edit_quotes.html");
126 exit();
127 }
128 $log->updatequote("quotes", $_REQUEST['message1'], $_REQUEST['message2'], "quote_id", "ngwaquote", "meaning", $cleaner->clean($_GET['quote_id']));
129
130}
131
132function qry($query) {
133 $this->dbconnect();
134 $args = func_get_args();
135 $query = array_shift($args);
136 $query = str_replace("?", "%s", $query);
137 $args = array_map('mysql_real_escape_string', $args);
138 array_unshift($args,$query);
139 $query = call_user_func_array('sprintf',$args);
140 $result = mysql_query($query) or die(mysql_error());
141 if($result){
142 return $result;
143 }else{
144 $error = "Error";
145 return $result;
146 }
147
148 //update quote function using $this->qry()
149 function updatequote($table, $message1, $message2, $column_name1, $column_name2, $column_name3, $quote_id){
150 $this->dbconnect();
151 $this->quote_id = $quote_id;
152 echo $message1, $message2;
153
154 //make sure table name is set
155 $this->user_table = $table;
156 $this->column_name1 = $column_name1;
157 $this->column_name2 = $column_name2;
158 $this->column_name3 = $column_name3;
159
160 //execute login via ****qry function**** that prevents MySQL injections
161 $result = $this->qry("UPDATE ".$this->user_table." SET ".$this->column_name2."='?', ".$this->column_name3."='?'
162 WHERE ".$this->column_name1."='?';", $message1, $message2, $this->quote_id );
163 // $result = mysql_query("INSERT INTO ".$this->user_table."(username, password) VALUES('$username', '$password')");
164 if($result){
165 $_SESSION['success'] = "The Update Was Successfully Saved";
166 header('location: edit_quotes.html');
167
168 exit();
169 return true;
170 }else{
171 $_SESSION['success'] = "The Update Was Not Saved".mysql_error();
172 header('location: edit_quotes.html');
173 exit(); //do something on FAILED login
174 return false;
175 }
176 }
177
178UPDATE table1 SET col1 = 0 WHERE col1 = 0
179
180$rows_updated = mysql_affected_rows($this->connection);
181or
182$rows_updated = mysqli_affected_rows($this->connection); //if you're using mysqli