Feb 10, 2020 03:21 PM
(This post was last modified: Feb 10, 2020 03:36 PM by Alex.)
Hey.
Currently doing a example to have something to show, but I just can't get this to work.
Error I get when trying this code:
I'm not really great at this and just wanted to set up a example. Anyone have any idea what I did wrong? The code is to change RGB colors in a mysql table.
It also shows the current RGB in the form
PHP code:
Form:
mysqlConfig.php:
Currently doing a example to have something to show, but I just can't get this to work.
Error I get when trying this code:
Code
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' g, b = '-3', '213', '8' WHERE id = '4'' at line 1 in C:\xampp\htdocs\mysqlConfig.php:13 Stack trace: #0 C:\xampp\htdocs\mysqlConfig.php(13): PDOStatement->execute(Array) #1 C:\xampp\htdocs\example.php(333): query('UPDATE char SET...', Array) #2 {main} thrown in C:\xampp\htdocs\mysqlConfig.php on line 13I'm not really great at this and just wanted to set up a example. Anyone have any idea what I did wrong? The code is to change RGB colors in a mysql table.
It also shows the current RGB in the form
PHP code:
PHP Code
<?php
if(isset($_SESSION['userID'])){
$data = query("SELECT r, g, b FROM char WHERE id = :uid LIMIT 1", array(
"uid" => $_SESSION['userID']
));
if($data->rowCount() > 0)
{
$data = $data->fetch(PDO::FETCH_ASSOC);
$r = $data['r'];
$g = $data['g'];
$b = $data['b'];
}else{
$_SESSION['userID'] = false;
session_destroy();
}
}
if(isset($_GET['changecolor_char1']))
{
if(count($_POST) > 0)
{
{
$ins = query("UPDATE char SET r, g, b = :r, :g, :b WHERE id = :uid", array(
"r" => $_POST['r'],
"g" => $_POST['g'],
"b" => $_POST['b'],
"uid" => $_SESSION['userID']
));
header("Refresh:0");
}
}
?>Form:
PHP Code
<?php
<form action="" method="post">
R:
<input required="" name="r" autocomplete="off" value="<?php echo $r; ?>"/><br/><br/>
G:
<input required="" name="g" autocomplete="off" value="<?php echo $g; ?>"/><br/><br/>
B:
<input required="" name="b" autocomplete="off" value="<?php echo $b; ?>"/><br/><br/>
</form>
mysqlConfig.php:
PHP Code
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
$conn = new PDO('mysql:host=localhost;dbname=removed;charset=utf8', 'removed', 'removed');
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
function query($query = "", $params = array())
{
global $conn;
$stmt = $conn->prepare($query);
$stmt->execute($params);
return $stmt;
}
?>![[Image: cpJG5qD.png]](https://i.imgur.com/cpJG5qD.png)


