I have done that when I push button it should insert data into mysql database but it only inserts it when I reload page. Here Is the code:  &lt;script&gt; function minuscredits() {     alert("hah");     &lt;?php     mysql_query("UPDATE `users` SET credits=credits-1 WHERE user_id=".$_SESSION['user']);     ?&gt; } &lt;/script&gt;   When I push button I get alert but not insert into database only if I reload page it inserts successfully.
53497
Is it possible to call a function from PHP using onsubmit from JavaScript? If so could someone give me an example of how it would be done?  function addOrder(){     $con = mysql_connect("localhost", "146687", "password");     if(!$con){         die('Could not connect: ' . mysql_error())     }      $sql = "INSERT INTO orders ((user, 1st row, 2nd row, 3rd row, 4th row)     VALUES ($session-&gt;username,1st variable, 2nd variable, 3rd variable, 4th variable))";      mysql_query($sql,$con)     if(mysql_query($sql,$con)){         echo "Your order has been added";     }else{         echo "There was an error adding your order to the databse: " . mysql_error();     } }   That's the function I am wanting to call. Its an ordering system, you type in how much of each item you want, hit submit and it should add the order to the table.
51549
What's wrong with this query: INSERT INTO Users( weight, desiredWeight ) VALUES ( 160, 145 ) WHERE id = 1;  It works without the WHERE clause. I've seemed to have forgot my SQL.
37250
I have create a form with form_validate and form_submit functions.  Using Firefox, everything is OK so the problem is not about an error in functions names.  Using Chrome, when I click on submit the page is just reloaded. I have added to my code drupal_debug to track the process into validate function and submit function. System not going into these functions.  I have no ideas about how form_validate function could be linked with choice of browser.  UPDATE : I have found more details about the cause of the problem :  To submit the form, user not click on the submit button directly. He have to click on an other button which launch js function.  At the end of the js function, I use jQuery( "#edit-continue" ).trigger( 'click' ) to simulate click on the real submit button.  I have tried to click directly on the real submit button and it is working but with trigger I see the ajax GIF of drupal but there is no passage to my form_validate function.  So, I really need to know how drupal can make the difference between a real click and an emulated one. And the most important how can I do to fix or skirt this problem.
89886
According to the , in order to make code more portable, they recommend using something like the following for escaping data:  if (!get_magic_quotes_gpc()) {     $lastname = addslashes($_POST['lastname']); } else {     $lastname = $_POST['lastname']; }   I have other validation checks that I will be performing, but how secure is the above strictly in terms of escaping data? I also saw that magic quotes will be deprecated in PHP 6. How will that affect the above code? I would prefer not to have to rely on a database-specific escaping function like mysql_real_escape_string().
76064
I want to implement something similar to Stack Exchange's reputation system. What would be the better practice: using an SQL aggregate function to recalculate every time it changes, or storing reputations in a table and manually altering it every time reputation goes up or comes down? How does Stack Exchange's implementation work?
91212
I am trying to create a form that will allow users to update their information on the front end.  I am just starting to learn PHP (I know C# very well).  If I use this code to create a form on a WordPress page, how do I get the information from the user when they press the 'Update' button and then update the database?  function Insert_AccountTable_1() {     $current_user = wp_get_current_user();      if ($current_user-&gt;ID != 0)     {         return &lt;&lt;&lt;HTML             &lt;form class="AlumniForm" method="post"&gt;             &lt;h3&gt;Name&lt;/h3&gt;             &lt;br&gt;             &lt;table&gt;                 &lt;tbody&gt;                     &lt;tr&gt;                         &lt;th&gt;&lt;label for="Username"&gt;Username&lt;/label&gt;&lt;/th&gt;                         &lt;td&gt;&lt;span&gt;$current_user-&gt;user_login&lt;/span&gt;&lt;/td&gt;                         &lt;td&gt;&lt;span class="description"&gt;Usernames cannot be changed.&lt;/span&gt;&lt;/td&gt;                     &lt;/tr&gt;                     &lt;tr&gt;                         &lt;th&gt;&lt;label for="current_user_firstname"&gt;First Name&lt;/label&gt;&lt;/th&gt;                         &lt;td&gt;&lt;input id="current_user_firstname" type="text" name="current_user_firstname" value="$current_user-&gt;user_firstname"/&gt;&lt;/td&gt;                     &lt;/tr&gt;                     &lt;tr&gt;                         &lt;th&gt;&lt;label for="current_user_lastname"&gt;Last Name&lt;/label&gt;&lt;/th&gt;                         &lt;td&gt;&lt;input id="current_user_lastname" name="current_user_lastname" type="text" value="$current_user-&gt;user_lastname"/&gt;&lt;/td&gt;                     &lt;/tr&gt;                     &lt;tr&gt;                         &lt;th&gt;&lt;label for="current_user_displayname"&gt;Display Name&lt;span class="description"&gt;(required)&lt;/span&gt;&lt;/label&gt;&lt;/th&gt;                         &lt;td&gt;&lt;input id="current_user_displayname" type="text" value="$current_user-&gt;display_name"/&gt;&lt;/td&gt;                     &lt;/tr&gt;                 &lt;/tbody&gt;             &lt;/table&gt;              &lt;h3&gt;Contact Info&lt;/h3&gt;             &lt;br&gt;             &lt;table&gt;                 &lt;tbody&gt;                     &lt;tr&gt;                         &lt;th&gt;&lt;label for="current_user_email"&gt;E-mail&lt;span class="description"&gt;(Required)&lt;/span&gt;&lt;/label&gt;&lt;/th&gt;                         &lt;td&gt;&lt;input id="current_user_email" type="text" value="$current_user-&gt;user_email"/&gt;&lt;/td&gt;                     &lt;/tr&gt;                     &lt;tr&gt;                         &lt;th&gt;&lt;label for="current_user_url"&gt;Website&lt;/label&gt;&lt;/th&gt;                         &lt;td&gt;&lt;input id="current_user_email" type="text" value="$current_user-&gt;user_url"/&gt;&lt;/td&gt;                     &lt;/tr&gt;                 &lt;/tbody&gt;             &lt;/table&gt;             &lt;input type="submit" name="current_user_submitupdates"&gt;Update&lt;/input&gt;             &lt;/form&gt; HTML;     }     else     {         return &lt;&lt;&lt;HTML         &lt;h3&gt;Error - User not logged in&lt;/h3&gt; HTML;     } }  add_shortcode('InsertAccountTableI', 'Insert_AccountTable_1');
86157
I was trying to add the column of MYSQL Timestamp to the Database Table, the Query seems to be working correctly in mysql console.But when I execute the same in db_query() the following error is thrown.     Failed: PDOException: SQLSTATE[42000]: Syntax error or access   violation: 1067 Invalid default value for 'last_update_date': ALTER   TABLE stores ADD last_update_date TIMESTAMP NOT NULL DEFAULT   '0000-00-00 00:00:00';; Array ( ) in store_update_7100() (line 254 of   /var/www/slocamo_app/sites/all/modules/store/store.install).   Is the Query.  ALTER TABLE  `stores` ADD  `last_update_date` TIMESTAMP NOT NULL DEFAULT  '0000-00-00 00:00:00');
81200
Im having a VF page it has some text fields and one button . On clicking the button , the values in the text field should be passed to the controller class to save in the database . Can this be achieved . If yes , direct me .
25421
I recently read that because of how InnoDB recalculates the AUTO_INCREMENT value when the server restarts, any records on the high end of the ID list may have their IDs reused.  Normally, this isn't a problem, because when a user is deleted everything associated with the ID is deleted from other tables too.  But I'm deliberately leaving their forum posts orphaned, labelled as "Posted by =User #123=", so that past conversations are retained. Clearly, should an ID be reused, this will be a problem.  I've never had this issue before because there were always enough new users to make it unlikely for an ID to be reused in this way. However on my new project signups are rare and inactive user deletions frequent (especially since the "Open Alpha" accounts only last for three days as a preview), and such ID reuse has happened three for three now.  I have "fixed" the issue by saving the correct value for AUTO_INCREMENT elsewhere and using that instead of relying on the internal value. Is there an actual way to have InnoDB remember the actual last value?
1458
I tried running the following statement:  INSERT INTO VOUCHER (VOUCHER_NUMBER, BOOK_ID, DENOMINATION) SELECT (a.number, b.ID, b.DENOMINATION)  FROM temp_cheques a, BOOK b WHERE a.number BETWEEN b.START_NUMBER AND b.START_NUMBER+b.UNITS-1;   which, as I understand it, should insert into VOUCHER each record from temp_cheques with the ID and DENOMINATION fields corresponding to entries in the BOOK table (temp_cheques comes from a database backup, which I'm trying to recreate in a different format). However, when I run it, I get an error:  Error: Operand should contain 1 column(s) SQLState:  21000 ErrorCode: 1241   I'm running this in SQuirrel and have not had issues with any other queries. Is there something wrong with the syntax of my query?  EDIT:  The structure of BOOK is:  ID  int(11) START_NUMBER    int(11) UNITS   int(11) DENOMINATION    double(5,2)   The structure of temp_cheques is:  ID  int(11) number  varchar(20)
31743
I am converting some module from d5 to d7, and in old code there is an update query like this:  &lt;?php db_query("UPDATE {a_table} SET count = count + 1 WHERE field1 = %d", $some_value);   As we see, it is incrementing a field value (AFAIK it is a mysql feature). But, if I use new style of update it won't work.  &lt;?php db_update('a_table')     -&gt;fields(array('count' =&gt; 'count + 1',))     -&gt;condition('field1', $some_value)     -&gt;execute();   Are there any workaround within new style of db update without running an extra query to get existing field value to increment it?
89834
I have:  &lt;?php  $file=fopen(date("Y-m-d").".txt","r+") or exit("Unable to open file!");  if ($_POST["lastname"] &lt;&gt; "") {    fwrite($file,$_POST["lastname"]."\n"); }  fclose($file);  ?&gt;   but it overwrites the beginning of the file.  How do I make it insert?
6322
I'm using Drupal v7.22 and whenever I try to Modify the Display on views, and press the 'Add and configure' button on adding a field, or any button that sends data to the server, the page reloads and I just get a long JSON String returned in Chrome, or IE will try to download the return...  Sometimes it'll accept my change, but more often than not, it won't.  It was doing this on 7.21 and then I updated to 7.22 and it stopped for a day or two, now it's doing it again.  I am extremely new to Drupal, but I am a quick learner and most things are going smoothly.  What did I break and how can I fix it?
110595
I am trying to save multiple values from a textarea to a database table.  I use the following code, but I feel it is the wrong way.   foreach ($user_emails as $key =&gt; $value) {   $insert_banned_emails = db_insert('banned_users');   $insert_banned_emails     -&gt;fields(array(       'email' =&gt; $value,     ))     -&gt;execute(); }   Is there a different way for achieving the same result?
102568
There are many questions about a custom form submit handler not being called, but in my case, the handler is being called; however, the entity is not being saved.  Specifically, I have a custom submit handler on a content type; when I press the button to call the handler, nothing is saved in the database:  function MYMODULE_form_node_CONTENTTYPE_form_alter(&amp;$form, FormStateInterface $form_state, $form_id) {    $form['actions']['submit_publish'] = array(     '#type' =&gt; 'submit',     '#weight' =&gt; 999,     '#button-type' =&gt; 'danger',     '#value' =&gt; t('Submit for approval'),     '#submit' =&gt; array('MYMODULE_draft2submit_callback'),   ); }  function MYMODULE_draft2submit_callback(array &amp;$form, FormStateInterface &amp;$form_state) {   $form_state-&gt;setValue('moderation_state', 'submitted'); }   So I thought since the node is not being saved, maybe I have to do it manually.  , I did this:  function MYMODULE_draft2submit_callback(array &amp;$form, FormStateInterface &amp;$form_state) {   $form_state-&gt;setValue('moderation_state', 'submitted');   $node = $form_state-&gt;getFormObject()-&gt;getEntity();   $node-&gt;save(); }   However, in this case, the node is saved, but none of the submitted values (the node body, for example) are saved; everything added by the user is ignored, as is the setValue() in my callback.  I only want to set the moderation_state in my custom form submit handler; in all other ways, I want my custom submit handler to be the same as the normal submit handler (i.e., I want it to save the node).  What am I doing wrong?
82000
I am trying to create the following trigger:      CREATE TRIGGER update_customers AFTER INSERT ON wp_usermeta     FOR EACH ROW      BEGIN             if new.wp_metakey = first_name then insert into test_customer(first_name) values (new.wp_meta_value);     END   I keep getting a 1064 error that says, "You have an error in your SQL syntax; check the manual that corresopons to your MySQL server version for the right syntaxt to use near " at line 5"  What am I doing wrong?
87988
I have Data in JSON format, and I want to insert and update that data into Drupal. I have to update all the records which I got from an external link.  How can I achieve this?