0

hi i have a major problem with updating my mysql database...

i have a form which has multiple arrays in the database printing out various

bits of information - the issue I am having is with the "Edit" function which results in an error message. The pic of the table can be seen in the image below.

You can see the "Delete" function or link besides "Edit" which seems to be working just fine. The error message(s) can be seen in the image below.

The error message is printed below:

Notice: Undefined index: idz in C:\xampp\htdocs\rajib\editeducation.php on line 23

Notice: Undefined index: full_name in C:\xampp\htdocs\rajib\editeducation.php on line 24

Notice: Undefined index: name_1 in C:\xampp\htdocs\rajib\editeducation.php on line 25

Notice: Undefined index: institution_1 in C:\xampp\htdocs\rajib\editeducation.php on line 26

Notice: Undefined index: instaddress_1 in C:\xampp\htdocs\rajib\editeducation.php on line 27

Notice: Undefined index: monthto_1 in C:\xampp\htdocs\rajib\editeducation.php on line 28

Notice: Undefined index: toyear_1 in C:\xampp\htdocs\rajib\editeducation.php on line 29

Notice: Undefined index: monthto_1_1 in C:\xampp\htdocs\rajib\editeducation.php on line 30

Notice: Undefined index: toyear_1_1 in C:\xampp\htdocs\rajib\editeducation.php on line 31

Notice: Undefined index: graduate_1 in C:\xampp\htdocs\rajib\editeducation.php on line 32

Notice: Undefined index: averages_1 in C:\xampp\htdocs\rajib\editeducation.php on line 33

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens' in C:\xampp\htdocs\rajib\editeducation.php:37 Stack trace: #0 C:\xampp\htdocs\rajib\editeducation.php(37): PDOStatement->execute(Array) #1 {main} thrown in C:\xampp\htdocs\rajib\editeducation.php on line 37

The code for the "Edit" link is printed below:

    <?php

include('dbcategory.php');

$full_name = $_GET["full_name"];
$idz = $_GET["idz"];

$query1 = "SELECT * FROM education WHERE idz ='$idz' AND full_name = '$full_name'";
$record_set1 = $dbs->prepare($query1);
$record_set1 -> execute();
$row1 = $record_set1->fetch(PDO::FETCH_ASSOC);
//if ($_SERVER["REQUEST_METHOD"] == "POST")
//{
/* $name_1s = "";
$institution_1s = "";
$instaddress_1s = "";
$monthto_1s = "";
$toyear_1s = "";
$monthto_1_1s = "";
$toyear_1_1s = "";
$graduate_1s = "";
$averages_1s = ""; */
$idz = $_POST["idz"];
$full_name = $_POST["full_name"];
$name_1s = $_POST["name_1"];
$institution_1s = $_POST["institution_1"];
$instaddress_1s = $_POST["instaddress_1"];
$monthto_1s = $_POST["monthto_1"];
$toyear_1s = $_POST["toyear_1"];
$monthto_1_1s = $_POST["monthto_1_1"];
$toyear_1_1s = $_POST["toyear_1_1"];
$graduate_1s = $_POST["graduate_1"];
$averages_1s = $_POST["averages_1"];

$query12 = "UPDATE education SET `full_name`=?,`name_1`=?,`institution_1`=?,`instaddress_1`=?,`monthto_1`=?,`toyear_1`,`monthto_1_1`=?, `toyear_1_1`=?, `graduate_1`=?, `averages_1`=? WHERE `idz`=?";
$bb = $dbs->prepare($query12);
$bb ->execute(array($full_name, $name_1s, $institution_1s, $instaddress_1s,$monthto_1s,$toyear_1s,$monthto_1_1s,$toyear_1_1s,$graduate_1s,$averages_1s, $idz));
//}
if (isset($_SERVER["HTTP_REFERER"])) {
        header("Location: " . $_SERVER["HTTP_REFERER"]);
}   

//header("location:editjapplications.php?id=$id");

?>

Here is the database for "Education"- and the order of all the columns which correspond with the code above when the various fields are updated when the "Edit link" is clicked :

I am confused as to why the code gives such errors when the "Delete" button seems to be working just fine. Anyone willing to lend a hand?

UPDATE:The code seems to be giving errors that I cant seem to make sense of. The Delete link works and it runs off the same database...

UPDATE #2: the result should have an update when i change the data in the fields...anyone get it now?

UPDATE #3: here is the updated code to the Edit function below -

    <?php

include('dbcategory.php');

$full_name = $_GET["full_name"];
$idz = $_GET["idz"];

$query1 = "SELECT * FROM education WHERE idz ='$idz' AND full_name = '$full_name'";
$record_set1 = $dbs->prepare($query1);
$record_set1 -> execute();
$row1 = $record_set1->fetch(PDO::FETCH_ASSOC);
//if ($_SERVER["REQUEST_METHOD"] == "POST")
//{
/* $name_1s = "";
$institution_1s = "";
$instaddress_1s = "";
$monthto_1s = "";
$toyear_1s = "";
$monthto_1_1s = "";
$toyear_1_1s = "";
$graduate_1s = "";
$averages_1s = ""; */
$idz = isset($_POST['idz']) ? $_POST['idz'] : '';;
$full_name = isset($_POST['full_name']) ? $_POST['full_name'] : '';
$name_1s = isset($_POST['name_1']) ? $_POST['name_1'] : '';
$institution_1s = isset($_POST['institution_1']) ? $_POST['institution_1'] : '';
$instaddress_1s = isset($_POST['instaddress_1']) ? $_POST['instaddress_1'] : '';
$monthto_1s = isset($_POST['monthto_1']) ? $_POST['monthto_1'] : '';
$toyear_1s = isset($_POST['toyear_1']) ? $_POST['toyear_1'] : '';
$monthto_1_1s = isset($_POST['monthto_1_1']) ? $_POST['monthto_1_1'] : '';
$toyear_1_1s = isset($_POST['toyear_1_1']) ? $_POST['toyear_1_1'] : '';
$graduate_1s = isset($_POST['graduate_1']) ? $_POST['graduate_1'] : '';
$averages_1s = isset($_POST['averages_1']) ? $_POST['averages_1'] : '';

$query12 = "UPDATE education SET `full_name`=?,`name_1`=?,`institution_1`=?,`instaddress_1`=?,`monthto_1`=?,`toyear_1`,`monthto_1_1`=?, `toyear_1_1`=?, `graduate_1`=?, `averages_1`=? WHERE `idz`=?";
$bb = $dbs->prepare($query12);
$bb ->execute(array($full_name, $name_1s, $institution_1s, $instaddress_1s,$monthto_1s,$toyear_1s,$monthto_1_1s,$toyear_1_1s,$graduate_1s,$averages_1s, $idz));
//}
if (isset($_SERVER["HTTP_REFERER"])) {
        header("Location: " . $_SERVER["HTTP_REFERER"]);
}   

//header("location:editjapplications.php?id=$id");

?>

I only get one error now -

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens' in C:\xampp\htdocs\rajib\editeducation.php:37 Stack trace: #0 C:\xampp\htdocs\rajib\editeducation.php(37): PDOStatement->execute(Array) #1 {main} thrown in C:\xampp\htdocs\rajib\editeducation.php on line 37

HOwever the tokens do seem to be matching...so what could be the problem then? Any takers on this one example?

0 Answers0