Hi all, i have difficulties in appending my sql query in php. Need some of your help to guide me along. Tell me where does my code goes who. Thanks.

for ($i = 1; $i<=$dayc; $i++){

        $daya[] = $_POST['day'.$i];

        $link = mysqli_connect($HOST,$USERNAME,$PASSWORD,$DB);
        $query = "UPDATE class SET Time_Slot_idTime_Slot = '$time',Course_idCourse = '$name',exam_date = '$exam',closing_date = '$closing',";
        $query = $query."day$1 = '$daya[$1]'";
        $query = $query."where idClass = ' ". $_GET['id'] ." '";
        $echo $query;
        $result = mysqli_query($link,$query) or die(mysqli_error($link));

am i doing a correct way of append? there seems to be error..Thanks for your help

Recommended Answers

All 5 Replies

$query = "UPDATE class SET Time_Slot_idTime_Slot = '$time',Course_idCourse = '$name',exam_date = '$exam',closing_date = '$closing',";
$query = $query . "day$1 = '$daya[$1]' "; // <-- you were missing a space here
$query = $query . "where idClass = '". $_GET['id'] . "'"; // <-- too many spaces here

Parse error: syntax error, unexpected '$', expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\FYP\doUpdateClass.php on line 24

this is the error i got

Member Avatar

What is this? Is thia a variable?

Change line 2:

$query = $query . "day$i = '$daya[$i]' ";

I guess you want to use $i, it could be another variable, but NOT $1

alright! thank you so much! i got it already..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.