mysqli

How To Insert data to database from multiple select list using PHP an MySQL

倖福魔咒の 提交于 2021-01-29 07:44:08
问题 I have a form with many multiple select lists. There are several multiple select lists(blocks) in the form. How can I submit the multiple select data to the database? I have tried to create a foreach statement but the problem is it only submits one option in the database. <?php $db = mysqli_connect('localhost','root','','trial') or die($db); if (isset($_POST['submit'])) { $marks = mysqli_real_escape_string($db,$_POST['marks']); $subjects= $_POST['subject']; $farming= $_POST['farming'];

Where should we use fetch_assoc method?

冷暖自知 提交于 2021-01-29 05:14:56
问题 I started this little blog project and I think I have just made a mistake by not including fetch_assoc method. This is the code: $data = new database(); $sql = "SELECT * FROM post "; $article = $data->select($sql); foreach ($article as $value) : ?> <div class="blog-post"> <h2 class="blog-post-title"><?= $value["blog_title"]; ?></h2> and this is how the select methode look like: public function select($sql){ $result = $this->con->query($sql) or die($this->con->error.__LINE__); if ($result->num

Binding values within a function to INSERT INTO DB

杀马特。学长 韩版系。学妹 提交于 2021-01-29 04:25:43
问题 Lets say I have this code: $array = array('one' => $one, 'two' => $two); $sql->sql_insert('table_name', $array); I have the class object $sql and the function sql_insert but how would I use the mysqli prepared statements to bind the values and insert it into the db? And lets say the mysqli connection is $this->connection Any advice would be great thanks. edited: function sql_insert_bind($table, $insert){ $count = count($insert); $bind_val = ''; for($i = 0; $i <= $count; $i++){ $bind_val .= '?

How to concatenate html stylized table with php and sql

只愿长相守 提交于 2021-01-28 07:59:28
问题 So, i have this code that returns me a simple table with the correct db values: <?php echo "<table border='1'> <tr> <th>Código</th> <th>Nome</th> <th>Indicou</th> </tr>"; while($coluna_bd_tabela = mysqli_fetch_array($sql_indicador_resul)){ echo "<tr>"; echo "<td>" . $coluna_bd_tabela['usu_codigo'] . "</td>"; echo "<td>" . $coluna_bd_tabela['usu_nome'] . "</td>"; echo "<td>" . $coluna_bd_tabela['usu_indicador_codigo'] . "</td>"; echo "</tr>"; } echo "</table>"; ?> And this one is the stylized

Best practice to update a row if exists otherwise insert [duplicate]

眉间皱痕 提交于 2021-01-28 06:33:57
问题 This question already has answers here : Insert into a MySQL table or update if exists (11 answers) Closed 2 years ago . I want to know more efficient way to update a row in table, if row not exists it must be inserted. My query is UPDATE MyGuests SET lastname='Doe' WHERE id=2 When this query is run and there is no row with id=2, a row must be inserted like INSERT INTO MyGuests (lastname, id) VALUES ('Doe', 2) Note: My primary intention is to update the row I don't want primary key change

Echo contents of JOIN SQL tables with MySQLi

馋奶兔 提交于 2021-01-28 06:07:59
问题 I'm working on a system, and this module is supposed to echo the contents of the database. It worked perfectly until I added some JOIN statements to it. I've checked and tested the SQL code, and it works perfectly. What's not working is that part where I echo the content of the JOINed table. My code looks like this: $query = "SELECT reg_students.*, courses.* FROM reg_students JOIN courses ON reg_students.course_id = courses.course_id WHERE reg_students.user_id = '".$user_id."'"; $result =

mySqli php - User input multiple choice checkboxes into 1 record

时光总嘲笑我的痴心妄想 提交于 2021-01-28 05:48:19
问题 beginner here. i have a nice mysqli user input going to where people fill out a form and it gets entered into my database. For example im using $category = $_POST['category']; and <input type="text" name="category" required placeholder="categories"> and its working great! So.. i have a record which is a drop down of checkboxes, so the user can choose multiple answers. looks like this <form> <div class="multiselect"> <div class="selectBox" onclick="showCheckboxes()"> <select> <option>Select an

using prepared mysqli statements to bind parameters into the SELECT section of a query

橙三吉。 提交于 2021-01-28 00:39:11
问题 I am building a web app that imports data from data feeds in php/mysql. I import the data into a buffer/temp holding table. As each data format is different I choose the column to select based on the particular source. I am having trouble getting this query to work in this context : $stmt = $this->dbObj->prepare("SELECT mk.PK_phone_maker, b.?, b.phoneDescription b.thumbPic, FROM buffer_table b left join mobile_phone pm on b.? = pm.phoneModel LEFT JOIN phone_maker mk on mk.CompanyName = b.?

How to use prepare statements / bind values in a query in Joomla 3?

此生再无相见时 提交于 2021-01-27 14:13:57
问题 I'd like to know how to bind values in where clause. I have understood that is something that MUST be done for security reasons. $db = JFactory::getDbo(); $query = $db->getQuery(true); $query ->select("*") ->from($db->quoteName("food")) ->where("taste = :taste") ->bind(':taste', 'sweet'); $db->setQuery($query); $rows = $db->loadAssocList(); I'm getting this 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

“Call to a member function fetch_assoc() on boolean” [duplicate]

。_饼干妹妹 提交于 2021-01-27 07:38:24
问题 This question already has an answer here : mysqli_fetch_assoc() expects parameter / Call to a member function bind_param() errors. How to get the actual mysql error and fix it? (1 answer) Closed 1 year ago . I've seen a bunch of questions about this error, but none of them seemed to have an answer that solved my problem... Sorry if I missed one. My script keeps giving me an error saying Call to a member function fetch_assoc() on boolean but I don't see how this is the case. Both $mysqli_query