0

i need your help.

i have some input with a button like this.

<input type="text" name="cmsperso" id="cmsperso" />
<input type="text" name="chefdequart" id="chefdequart" />
<input type="text" name="adjoint" id="adjoint" />
<button type="submit" name="perso" onClick="perso()">envoyer</button>

the onClick call an ajax function.

function perso() {
$.ajax({
  type: "POST",
  url: "form/perso.php",
});}

and in my perso.php, i have this update.

$cnx = mysql_connect( "localhost", "root", "" );
$db = mysql_select_db( "maincourante" );
$req = mysql_query("SELECT idops FROM ops ORDER BY idops DESC LIMIT 1");
$data = mysql_fetch_array($req);

$cmsperso = $_POST["cmsperso"];
$chefdequart = $_POST["chefdequart"];
$adjoint = $_POST["adjoint"];

$perso = utf8_decode("UPDATE `Opérations n°".$data['idops']."` SET cmsperso='$cmsperso', chefdequart='$chefdequart', adjoint='$adjoint'");

mysql_query($perso, $cnx) or die(mysql_error());
mysql_close();

all is working fine exept the update. In phpmyadmin none of the value is update.

please help

11
  • 1
    Where is the insert query to the database? Commented Nov 29, 2012 at 19:04
  • what about all the mysql connections and queries, do you have it as well? Commented Nov 29, 2012 at 19:04
  • i don't have insert query, just update query in this script. and i have the mysql connection. Commented Nov 29, 2012 at 19:09
  • i try to replace my update query to an insert query and it doesn't work too Commented Nov 29, 2012 at 19:11
  • You should show more context around your query (like where you actually make the query). Also, are you getting a specific MySQL error back? You also realize that your update query is going to change ALL rows in the table to those values? Commented Nov 29, 2012 at 19:13

3 Answers 3

1

you are not sending the variable values in your post,

function perso() {
$.ajax({
  type: "POST",
  url: "form/perso.php",
});}

need to add the variable and value to this call like:

function perso() {
$.post("form/perso.php", { adjoint: $("#adjoint").val(), cmsperso: $("#cmsperso").val(), chefdequart: $("#chefdequart").val() } );
});}

also take a look at PDO for managing your data objects as your query can be injected into

finaly it seems you have no where clause, this means that ALL lines in your table will be updated which probably not what you were after.

another think i would consider is naming you table something simpler than it is now having spaces and special charaters in there is asking for trouble.

Sign up to request clarification or add additional context in comments.

7 Comments

ok that solves the actual values, what about the where clause?
i don't need to specify where clause cause i have just one id
then i suggest some simple debugging ... print out the sql query before you try to execute it and see what it is exactly
ok print return this. UPDATE Op�rations n�1 SET cmsperso='', chefdequart='', adjoint=''
it was not sent because you did not send it, the post command you created dosent know which form it came from or what variables it has in it, you have to specify the data you want to send
|
0

Are you sure Opérations n°".$data['idops']." is the correct table you are trying to update?

2 Comments

Can you open up phpMyAdmin and run your sql query in there? Just fill in the variables with some test placeholders and see if it udpates there. Just paste the below in and see if it udpates. UPDATE Opérations n°".$data['idops']." SET cmsperso='test', chefdequart='test2', adjoint='test3'
If you haven't tried printing out the variables that you post then try that and make sure your variables are correct. You could also try editing: mysql_query($perso, $cnx) or die(mysql_error()); to: mysql_query($perso) or die(mysql_error()); Since you didn't use ,$cnx in your first query.
0

good morning,

i think, i partially resolve my problem

this is my code

function getXMLHttpRequest() {
var xhr2 = null;

if (window.XMLHttpRequest || window.ActiveXObject) {
    if (window.ActiveXObject) {
      try {
        xhr2 = new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch(e) {
        xhr2 = new ActiveXObject("Microsoft.XMLHTTP");
      }
    } 
    else {
      xhr2 = new XMLHttpRequest();
    }
  } 
  else {
    alert("Votre navigateur ne supporte pas l'objet XMLHTTPRequest...");
    return null;
  }
  return xhr2;
}

/* ressources */
function perso() {
  $.post("form/perso.php", { 
    cmsperso: $("#cmsperso").val(), 
    chefdequart: $("#chefdequart").val(),
    adjoint: $("#adjoint").val()
  });

  var xhr2 = getXMLHttpRequest();

  xhr2.open("POST", "form/perso.php", false);
}

and this return in firebug

firebug 302 found

any idea?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.