snowymasta Posted August 24, 2020 Share Posted August 24, 2020 Hey Guys, I'm really struggling to find whats wrong with this code. The form before submit has several checkboxes as part of an array which is below <?php $conn = new mysqli($servername, $username, $password, $dbname); $sql = "SELECT * FROM `engineers`"; $result = $conn->query($sql); while($row = mysqli_fetch_assoc($result)) { $endid = $row["endid"]; $resource_name = $row["resource_name"]; $resource_email = $row["resource_email"]; $picture = $row["picture"]; echo "<label>".$resource_name."</label><input type='checkbox' class='form-control' name='engineers[]' value=''.$endid.''><br>"; } ?> The next page then goes to this and I get the error "Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /homepages/39/d837976904/htdocs/Scheduler/add_job3.php:10 Stack trace: #0 {main} thrown in /homepages/39/d837976904/htdocs/Scheduler/add_job3.php on line 10" <?php // Initialize the session session_start(); $process = $_GET["process"]; include "Includes/config.php"; include "Includes/db.php"; mysql_connect($servername, $username, $password) or die(mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $checkBox = implode(',', $_POST['engineers']); if(isset($_POST['submit'])) { $query1="INSERT INTO job_activity (endid) VALUES ('" . $checkBox . "')"; mysql_query($query1) or die (mysql_error() ); echo "Complete"; } ?> Can anyone help with the code please Quote Link to comment https://forums.phpfreaks.com/topic/311381-help-with-adding-checkbox-into-mysql/ Share on other sites More sharing options...
benanamen Posted August 25, 2020 Share Posted August 25, 2020 2 hours ago, snowymasta said: I'm really struggling to find whats wrong with this code. The first thing you need to do is stop mixing obsolete mysql_* code with mysqli. Quote Link to comment https://forums.phpfreaks.com/topic/311381-help-with-adding-checkbox-into-mysql/#findComment-1580939 Share on other sites More sharing options...
Barand Posted August 25, 2020 Share Posted August 25, 2020 Also, your data table design is wrong. Don't store data (particularly IDs) in comma separated lists. Quote Link to comment https://forums.phpfreaks.com/topic/311381-help-with-adding-checkbox-into-mysql/#findComment-1580947 Share on other sites More sharing options...
bakertaylor28 Posted September 4, 2020 Share Posted September 4, 2020 (edited) This seems to be because you're mixing obsolete sql with sqli. You can't use both in the same database call. The big problem I see with this is that you should be using prepared statements in the first place. Edited September 4, 2020 by bakertaylor28 Quote Link to comment https://forums.phpfreaks.com/topic/311381-help-with-adding-checkbox-into-mysql/#findComment-1581135 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.