Home > database >  I am trying to pass a html color input into mysql but in the database it shows up as 0
I am trying to pass a html color input into mysql but in the database it shows up as 0

Time:12-28

I am trying to pass the color input into the data base with it showing the hex code of a color that the user selects but it shows 0. I tried chaning the type inside the sql from INT to VARCHAR but it didnt change anything.

I dont really know why this is happening,i have tried everything and havent managed to figure anything out. I will provide the html,php and a screenshot of the sql column.

mysql column

HTML CODE

<div >
  <p style="font-family: system-ui; font-size: 15pt;">
  <label for="favcolor">Επιλέξετε το χρώμα του δίσκου σερβιρίσματος:</label>
  <input type="color" id="favcolor" name="favcolor" value="#ff0000">
  </p>
</div>

And the key parts of the php code

$favcolor = $_POST['favcolor'];
$stmt = $conn->prepare("INSERT INTO registration (titlos, onoma, eponimo, bdate, statistiko, xores, tilefono, email, yphkootita, address, poli, taxidromikos, peri, geuma, favcolor, airport, password, aksiologisi,aksiologisi2, hid, review) 

VALUES (? ,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
        
$stmt->bind_param("ssssssisssssssissiiis", $titlos, $onoma, $eponimo, $bdate, $statistiko, $xores, $tilefono, $email, $yphkootita, $address, $poli, $taxidromikos, $peri, $geuma, $favcolor, $airport, $password, $aksiologisi,$aksiologisi2, $hid, $review);

CodePudding user response:

I see your problem trying to insert the value -> value="#ff0000"

to database with $stmt->bind_param("ssssssisssssssissiiis")

$stmt->bind_param("ssssssisssssss -> i <- ssiiis") //<--integer

Integer, you were inserting invalid integer value="#ff0000" which is #ff0000 as that is why it is always 0 inserted.

  • Related