-1

I am bit lost, I just try to do an update over all columns which exists in a SQL table, but somehow it allways show me the following error message:

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in

My Update looks like the following:

    if(isset($_POST["send"])) {

    $time = time();

    $airdrop=$_REQUEST['airdroptitel'];
    $airdropcapped=$_REQUEST['airdropcapped'];
    $airdrop_rating=$_REQUEST['airdroprating'];
    $airdrop_type=$_REQUEST['airdroptype'];
    $airdrop_freetext=$_REQUEST['airdrop_freetext'];
    $airdrop_freetext_de=$_REQUEST['airdrop_freetext_de'];
    $enddate_distribution=$_REQUEST['enddate_distribution'];

    $projectdescription=$_REQUEST['projectdescribtion'];
    $projecturl=$_REQUEST['projecturl'];
    $reflink_layer=$_REQUEST['reflink_layer'];
    $reflink_possible=$_REQUEST['reflink_possible'];
    $projectname=$_REQUEST['projectname'];
    $projectplattform=$_REQUEST['plattform'];
    $bounty_usd=$_REQUEST['bounty'];
    $bounty_cry=$_REQUEST['shortform'];
    $bounty_cry_amount=$_REQUEST['bountyamount'];
    $bounty_cry_refamount=$_REQUEST['refamount'];

    $status=$_REQUEST['airdropstatus'];
    $enddate=$_REQUEST['enddate'];
    $who_change=$session_userid;
    $timestamp_change=time();
    $visible=$_REQUEST['showable'];
    $ip_lastchange=$_SERVER['REMOTE_ADDR'];

    $validation=$_REQUEST['validation'];
    $totalsupply=$_REQUEST['totalsupply'];
    $priceoftoken=$_REQUEST['priceoftoken'];
    $telegramurl=$_REQUEST['telegramurl'];
    $twitterurl=$_REQUEST['twitterurl'];
    $mediumurl=$_REQUEST['mediumurl'];
    $githuburl=$_REQUEST['githuburl'];
    $facebookurl=$_REQUEST['facebookurl'];

    $estimatedtime=$_REQUEST['estimatedtime'];
    $hot=$_REQUEST['hot'];


    $tool_telegram  =$_REQUEST['tool_telegram'];
    $tool_twitter   =$_REQUEST['tool_twitter'];
    $tool_facebook  =$_REQUEST['tool_facebook'];
    $tool_bitcointalk=$_REQUEST['tool_bitcointalk'];
    $tool_mail  =$_REQUEST['tool_mail'];
    $tool_medium    =$_REQUEST['tool_medium'];
    $tool_linkedin  =$_REQUEST['tool_linkedin'];
    $tool_reddit    =$_REQUEST['tool_reddit'];
    $tool_register  =$_REQUEST['tool_register'];
    $tool_kyc   =$_REQUEST['tool_kyc'];
    $tool_other =$_REQUEST['tool_other'];

    $statement = $pdo->prepare("UPDATE ad_airdrops SET airdrop =: airdrop, airdropcapped =: airdropcapped, airdrop_rating =: airdrop_rating, projectdescription =: projectdescription, projecturl =: projecturl, projectname =: projectname, projectplattform =: projectplattform, bounty_usd =: bounty_usd, bounty_cry =: bounty_cry, bounty_cry_amount =: bounty_cry_amount, bounty_cry_refamount =: bounty_cry_refamount, tool_other =: tool_other, status =: status, enddate =: enddate, who_change =: who_change, timestamp_change =: timestamp_change, visible =: visible, reflink_layer =: reflink_layer, reflink_possible =: reflink_possible, airdrop_type =: airdrop_type, facebookurl =: facebookurl, airdrop_freetext =: airdrop_freetext, enddate_distribution =: enddate_distribution, validation =: validation, totalsupply =: totalsupply, priceoftoken =: priceoftoken, telegramurl =: telegramurl, twitterurl =: twitterurl, mediumurl =: mediumurl, githuburl =: githuburl, airdrop_freetext_de =: airdrop_freetext_de, estimatedtime =: estimatedtime, hot =: hot, tool_telegram =: tool_telegram, tool_twitter =: tool_twitter, tool_facebook =: tool_facebook, tool_bitcointalk =: tool_bitcointalk, tool_mail =: tool_mail, tool_medium =: tool_medium, tool_linkedin =: tool_linkedin, tool_reddit =: tool_reddit, tool_register =: tool_register, tool_kyc =: tool_kyc WHERE id =: id");


$statement->execute(array('airdrop' => $airdrop, 'airdropcapped' => $airdropcapped, 'airdrop_rating' => $airdrop_rating, 'projectdescription' => $projectdescription, 'projecturl' => $projecturl, 'projectname' => $projectname, 'projectplattform' => $projectplattform, 'bounty_usd' => $bounty_usd, 'bounty_cry' => $bounty_cry, 'bounty_cry_amount' => $bounty_cry_amount, 'bounty_cry_refamount' => $bounty_cry_refamount, 'tool_other' => $tool_other, 'status' => $status, 'enddate' => $enddate, 'who_change' => $who_change, 'timestamp_change' => $timestamp_change, 'visible' => $visible, 'reflink_layer' => $reflink_layer, 'reflink_possible' => $reflink_possible, 'airdrop_type' => $airdrop_type, 'facebookurl' => $facebookurl, 'airdrop_freetext' => $airdrop_freetext, 'enddate_distribution' => $enddate_distribution, 'validation' => $validation,'totalsupply' => $totalsupply, 'priceoftoken' => $priceoftoken, 'telegramurl' => $telegramurl, 'twitterurl' => $twitterurl, 'mediumurl' => $mediumurl, 'githuburl' => $githuburl, 'airdrop_freetext_de' => $airdrop_freetext_de, 'estimatedtime' => $estimatedtime, 'hot' => $hot, 'tool_telegram' => $tool_telegram, 'tool_twitter' => $tool_twitter, 'tool_facebook' => $tool_facebook, 'tool_bitcointalk' => $tool_bitcointalk, 'tool_mail' => $tool_mail, 'tool_medium' => $tool_medium, 'tool_linkedin' => $tool_linkedin, 'tool_reddit' => $tool_reddit, 'tool_register' => $tool_register, 'tool_kyc' => $tool_kyc, 'id' => $id));
}

Would be very happy if someone can help me, seraching like 2 hours allready on this problem :/ Thank you.

Tom Aranda
  • 5,919
  • 11
  • 35
  • 51
Frostyz
  • 23
  • 4
  • What are those spaces between the colons and param names (e.g. `...githuburl =: githuburl` instead of `...githuburl = :githuburl`)? – Matt Gibson Mar 31 '18 at 15:17
  • Good question, i am not a proffesional ;) I am just trying to learn it by doing. I removed them now but didnt changed, same Error Message. Edit. Actually it helped but its not saving now... Hmm – Frostyz Mar 31 '18 at 15:20
  • You should edit your question to include your updated code. That way we can home in on what's actually wrong. (One handy way of trying your own debugging: rewrite your code temporarily so only *one* column is updated. Does it work?) – Matt Gibson Mar 31 '18 at 15:23
  • I am quite new to stackoverflow. This page just helped me allready a lot to fix my problems. I will try your trick and update my question - thank you! – Frostyz Mar 31 '18 at 15:25

1 Answers1

0

You've used endate_distribution in the query string and enddate_distribution in the parameter list.

Matt Gibson
  • 37,886
  • 9
  • 99
  • 128
  • Thank you! But still not saving, i will check again all columns on their spelling. – Frostyz Mar 31 '18 at 15:46
  • Do you still get the same error message, or has that changed? – Matt Gibson Mar 31 '18 at 15:47
  • I dont get any error message now - my problem with this error message was solved with changing the "= : ". I am sorry to confuse you guys, just my first question here ;) Thank you for your help – Frostyz Mar 31 '18 at 15:48
  • If you don't get an error message now, that suggests that your execute worked. It's possible for a "successful" update statement not to change anything in the database. For example, if your `id` value doesn't match an existing row in the database, nothing will be updated, though the query will report success. What is the value of `$id`? Are you sure there's a row with that `id` in the database? – Matt Gibson Mar 31 '18 at 15:56
  • Hi, thank you. I just reduced my update query and he still dont update: $statement = $pdo->prepare("UPDATE ad_airdrops SET airdrop =: airdrop WHERE id =: id"); $statement->execute(array('id' => $id, 'airdrop' => $airdrop)); For me everything looks good? Do you see here a mistake? I also tried allready to but the id in the statement but he was not updating anything... I miss here some basics i think :D And yes i am sure there is some row with that id. – Frostyz Mar 31 '18 at 15:58
  • What is the return value from the `execute`? You should check that; [it returns `true` if the statement was successful, `false` otherwise](http://php.net/manual/en/pdostatement.execute.php). – Matt Gibson Mar 31 '18 at 17:03
  • 1
    (PS: make sure you keep those colons next to the parameter names. You want `:airdrop` and `:id`, not `: airdrop` and `: id`.) – Matt Gibson Mar 31 '18 at 17:07
  • 1
    oh it was really just the space - thank you for the last advice this solved my problem :) – Frostyz Mar 31 '18 at 22:33