php - How to solve this mysqli error -
code 1 works fine , updates attendance table:
<?php $date = $_post['date']; $subject = $_post['subject']; $con=mysqli_connect("localhost","root","","notifier"); if (mysqli_connect_errno()) { echo "failed connect mysql: " . mysqli_connect_error(); } $result = mysqli_query($con,"select * student"); echo "enter attendance. please untick 'absent' students , submit"; echo "<br>"; echo "<form action=\"d.php\" method=\"post\">"; while($row = mysqli_fetch_array($result)) { echo "<br>" .$row['classrollno'] . "   <input type=\"checkbox\" name=\"p[]\" value=\"" . $row['studentid'] . "\" checked>"; $sql="insert attendance (rollno, subjectid, date) values ('{$row['classrollno']}','$_post[subject]','$_post[date]')"; if (!mysqli_query($con,$sql)) { die('error: ' . mysqli_error($con)); } } mysqli_close($con); echo "<input type=\"hidden\" name=\"date\" value=\"" . $date . "\">"; echo "<input type=\"hidden\" name=\"subject\" value=\"" . $subject . "\">"; echo "<input type=\"submit\" name=\"submit\" value=\"submit\">"; echo "</form>"; ?>
code 2 giving error, supposed update table depending on checkboxes recieved previous page:
<?php $con=mysqli_connect("localhost","root","","notifier"); if (mysqli_connect_errno()) { echo "failed connect mysql: " . mysqli_connect_error(); } foreach($_post['p'] $value) { $sql="update attendance set presenty='p' studentid='{$value}' , subjectid='$_post[subject]' , date='$_post[date]')"; if (!mysqli_query($con,$sql)) { die('error: ' . mysqli_error($con)); } } mysqli_close($con); ?>
error: have error in sql syntax; check manual corresponds mysql server version right syntax use near ')' @ line 2
but line works fine in previous file.
line 1: update attendance set presenty='p' line 2: studentid='foo' , subjectid='bar' , date='baz')
error: ... near ')' @ line 2
the )
@ line 2 closing one. remove it.
+
Comments
Post a Comment