How to catch and save the second selected text in the database?

It is supposed to store a whole row in a database with a divided sentence and options and answers stored in their own columns.

$ example = 'She went to the store to buy ( buy , buy, buy, buy) some snacks when she (sees, sees, drank , watches ) an accident.';.

Manage the storage of the entire row in the database and store it in the appropriate columns and catch and store the first selected text in the database.

But it is not possible to catch and save the second bold text to its column in the database.

<?php 
define('DB_HOST', 'localhost');
define('DB_NAME', 'palmdatas'); 
define('DB_USER','root');
define('DB_PASSWORD',''); 

$con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error());
$db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL: " . mysql_error()); 
$mode = $_POST['mode']; 
$question = $_POST['editor1']; 
$text = $question;

echo "\n";

$text = strip_tags($text);


function multiexplode ($delimiters,$string) {

$ready = str_replace($delimiters, $delimiters[0], $string);
$launch = explode($delimiters[0], $ready);
return  $launch;
}

$exploded = multiexplode(array(",","(",")"),$text);
 $question = $_POST['editor1']; 

 $answer1 = extractString($question, '<strong>', '</strong>');

$sql="INSERT INTO strucquestions (part1,op1,op2,op3,op4,ans1,part2,op1a,op2a,op3a,op4a,ans2,part3,mode) VALUES ('$exploded[0]','$exploded[1]','$exploded[2]','$exploded[3]','$exploded[4]','$answer1','$exploded[5]','$exploded[6]','$exploded[7]','$exploded[8]','$exploded[9]','$answer2','$exploded[10]','$mode')";

echo "Successfully Inserted!";
$result = mysql_query($sql);
if (!$result) {
 die('Invalid query: ' . mysql_error());
}

function extractString($question, $start, $end) {
$question = " ".$question;
$ini = strpos($question, $start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($question, $end, $ini) - $ini;
return substr($question, $ini, $len);

echo "close";
        mysql_close($con);      

} 
?>
<button onclick="window.location.href='insertion.php'">Next</button><br>        <br>
+4
source share
1 answer
0

Source: https://habr.com/ru/post/1599782/


All Articles