Question

I must be doing something wrong in this code....

<? 
$codeid=$_GET["codeid"];
$tablecode=$_GET["tablecode"];
$description=$_GET["description"];
$code=$_GET["code"];
$groupcode=$_GET["groupcode"];
$t1=$_GET["t1"];
$t2=$_GET["t2"];
$t3=$_GET["t3"];

$mysqli = new mysqli(dbhost,dbuser,dbpass,dbc);
if ($mysqli->connect_error) {
    die('Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);
    }

$q="call spUpdateCodeTable(?,?,?,?,?,?,?,?)";
$stmt = $mysqli->prepare($q);
$stmt->bind_param($codeid,$tablecode,$description,$code,$groupcode,$t1,$t2,$t3);
$stmt->execute();

mysql_close($mysqli);
?>

Absolutely nothing happens...no error message or any other indication of a problem. It just does not run the procedure. (it's an update/insert routine).

I am using this URL...

updateCodeTable.php?codeid=0&codetable=TABLE&desription=testing2%20entry&code=TEST1&groupcode=gcode&t1=t1&t2=t2&t3=t3

...but, if I run the this query in phpMyAdmin, it runs perfectly....

call spUpdateCodeTable(0,'TABLE','testing2','TEST1','group','','','');

I could include the stored procedure code, but it runs fine anytime I run it directly, but just not running successfully from my php code.

Était-ce utile?

La solution

Each mysqli* function/method can fail. Either test the return values and/or switch the reporting mechanism to exceptions, see http://docs.php.net/mysqli-driver.report-mode

<?php
// probably better done with http://docs.php.net/filter but anyway ...just check whether all those parameters are really there
// you are positive that GET is the correct method for this action?
if ( !isset($_GET["codeid"], $_GET["tablecode"], $_GET["description"], $_GET["code"], $_GET["groupcode"], $_GET["t1"], $_GET["t2"], $_GET["t3"]) ) {
    // die() is such a crude method
    // but bare me, it's just an example....
    // see e.g. http://docs.php.net/trigger_error
    die('missing parameter');
}
else {
    $mysqli = new mysqli(dbhost,dbuser,dbpass,dbc); 
    if ($mysqli->connect_error) {
        die('Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);
    }

    $q="call spUpdateCodeTable(?,?,?,?,?,?,?,?)";
    $stmt = $mysqli->prepare($q);
    if ( !$stmt ) {
        // $mysqli->error has more info
        die('prepare failed');
    }
    // you have to provide the format of each parameter in the first parameter to bind_param
    // I just set them all to strings, better check that
    if ( !$stmt->bind_param('ssssssss', $_GET['codeid'], $_GET['tablecode'], $_GET['description'], $_GET['code'], $_GET['groupcode'], $_GET['t1'], $_GET['t2'], $_GET['t3']) ) {
        // $stmt->error has more info
        die('bind failed');
    }

    if ( !$stmt->execute() ) {
        // $stmt->error has more info
        die('execute failed');
    }
}

Autres conseils

May you have a try to this?

mysqli->query("call spUpdateCodeTable($codeid,'$tablecode',
 '$description','$code','$groupcode','$t1','$t2','$t3')");
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top