Insert Mutiple Record into Database Using Php Mysql

$arr = array(); foreach($_POST[‘sj’] as $key => $value) { $eflt = $_POST[‘sflt’][$key]; $emodel = $_POST[‘smodel’][$key]; $eengine =$_POST[‘sengine’][$key]; $eloc = $_POST[‘sloc’][$key]; $estye = $_POST[‘sstye’][$key]; $ensvr = $_POST[‘snsvr’][$key]; $eehd = $_POST[‘sehd’][$key]; array_push($arr,”(‘$eflt’,’$emodel’,’$eengine’,’$eloc’,’$estye’,’$ensvr’,’$eehd’)”); } $inExp = mysqli_query($link,”INSERT INTO table_name(fltno,model,engine,loc,serviceType,nextSvr,usageHr) VALUES “.implode(‘,’,$arr)); Do it with one query. Also you can do it with prepared statements easily..

Pagination data

You need to study their code more, dont just copy&paste. You told the program to echo those variables and it echoed them for you. In the tutorial they seem to store all the ‘paginatable’ data in the $list, so you need to look into that. $id = $row[“id”]; prints id column from the current table … Read more

inserting information and image in php and mysql

This would combine the two inserts into one action. But I would advise against storing the images in the db. Store the path relative to your site of the image instead. <?php require ‘db.php’; $message=””; $Error=””; if(isset($_POST[‘Attendee_id’]) && isset($_POST[‘RFID_number’]) && isset($_POST[‘Attendee_Name’]) && isset($_POST[‘CourseOrDepartment’]) && isset($_POST[‘Status’]) && isset($_FILES[‘Image’][‘tmp_name’]) && $_SERVER[‘REQUEST_METHOD’]==’POST’) { $Attendee_id = $_POST[‘Attendee_id’]; $RFID_number = … Read more

Save the data into a database and return another value from database using PHP

U can use the normal php code to insert the data to mysql ex: <?php if($_SERVER[“REQUEST_METHOD”] == “POST”) { $servername=”localhost”; $username=”root”; $password=””; $db=”login”; //connection $conn=new mysqli($servername,$username,$password,$db); //fetch from form $myusername = mysqli_real_escape_string($conn,$_POST[‘usernam’]); $mypassword = mysqli_real_escape_string($conn,$_POST[‘password’]); $myemail=mysqli_real_escape_string($conn,$_POST[’email’]); $sql=$conn->query(“INSERT INTO su values(‘$myusername’,’$mypassword’,’$myemail’,0)”); } ?> This inserts the data into mysql and the sql design needs to be … Read more

About how does mysqli_query() Function and mysqli_fetch_array($result) work?

As already said it is all in the manuals, you should read these sites: http://php.net/manual/en/mysqli.query.php, http://php.net/manual/en/mysqli-result.fetch-array.php and http://php.net/manual/en/mysqli-result.fetch-assoc.php In general you start doing the mysqli_query which may return a result object. Then you use the result with mysqli_fetch_array or mysqli_fetch_assoc (I personally prefer assoc) to get the rows. You get one row each time you … Read more

two person chat room

As you are not provided much information about your requirement,I am assuming that you what to create a chat room for two users and these two users can only participate in this room.For this you should not user this schema. You need to create different tables of different entities and there relationship. Here you have … Read more

How to insert database rows if there are no answers

Simply do not insert anything into Answer table when there is no answer. Rest of your solution is basically correct. When displaying questions with answer, check if there is answer (empty select result or null in left joined column) to show and if not, show “No answer”. But there is no “No answer” in database.

Turning a SQL row into an array

If you only want specific associative properties from all columns queried from the MySQL call, just set them in an array with their respective properties: $categoriesTest = array(); $sql = “SELECT * FROM `respondent_data` WHERE `respondent_firstname` = ‘John'”; $result = mysqli_query($conn, $sql); while($row = mysqli_fetch_assoc($result)) { $categoriesTest[] = array( ‘respondent_sdo’ => $row[‘respondent_sdo’], ‘respondent_dcto’ => $row[‘respondent_dcto’], … Read more

PHP create new array by value

<?php $techArray = array( “level_1” => array ( “0” => “Computer”, “level_2” => array ( “0” => “SmartPhone”, “level_3” => array( “0” => “Laptop” ) ) ) ); ?> You can try this, it will work!