Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

HTML CODE

<div class="text">
  <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);

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading