Reputation: 17
<?php
$con3=mysqli_connect("localhost","root","","test");
if (mysqli_connect_errno())
{
echo "Connection Failed: " . mysqli_connect_error();
}
//$result = mysqli_query($con3,"SELECT * FROM servers");
$updateln = $_POST ['LoggedIn'];
$updateloc = $_POST ['Location'];
$updateos = $_POST ['OperatingSystem'];
$updatesn = $_POST ['ServerName'];
$updatesql="UPDATE servers SET LoggedIn='$updateln', Location='$updateloc'"
. " OperatingSystem = '$updateos' WHERE ServerName = '$updatesn'";
if (!mysqli_query($con3,$updatesql))
{
die('Error: ' . mysqli_error($con3));
}
echo "Record Updated";
I am fairly new to PHP and SQL so I am not really sure what is wrong with the UPDATE sql. This is the error I am getting
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OperatingSystem = 'ht' WHERE ServerName = 'hr'' at line 1
I have tried other stackoverflow questions and although some people have had problems with this before I can't really see where my code has gone wrong.
Upvotes: 0
Views: 50
Reputation: 43434
You seem to be missing a comma. Replace this:
"UPDATE servers SET LoggedIn='$updateln', Location='$updateloc'"
With this:
"UPDATE servers SET LoggedIn='$updateln', Location='$updateloc',"
Upvotes: 3