Jump to content

newone

New Members
  • Posts

    4
  • Joined

  • Last visited

newone's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. hi , thanks in advance guys for your help I am preparing a quiz which has question and multiple options i am currently working to fetch data from database as radio buttons for which i am successful but on inserting that into a database gives me a blank value and on top of it the radio button is not sticky for each mcqs code for fetching the data <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $db='tutorial'; $conn = mysqli_connect($dbhost, $dbuser, $dbpass,$db); if(isset($_POST['value'])){ $value = $_POST['value']; } if(! $conn ) { die('Could not connect: ' . error); } $sql = 'SELECT q1,option1,option2,option3 FROM questions '; $result = mysqli_query( $conn, $sql); if(! $result ) { die('Could not get data: ' ); } while($row = mysqli_fetch_array($result)) { echo "{$row['q1']}" .'</br></br>'. " A <input type='radio' name='RadioGroup1' value='ans' id ='ans' 'checked=checked'>" . $row['option1'] . '<br> ' . " B <input type='radio' name='RadioGroup1' value='ans'>" . $row['option2'] . '<br> '. " C <input type='radio' name='RadioGroup1' value='option3']}'>" . $row['option3'] . '<br> '.'<br>'; //"--------------------------------<br>"); } echo "<form name=\"insert\" action=\"dbinsert.php\" method=\"post\">"; echo "<input type=\"submit\" value=\"submit\">"; echo "</form>"; mysqli_close($conn)?> the insertion part code is here if(isset($_POST['value'])){ $value = $_POST['ans'];} if(! $link ) { die('Could not link: ' . error); } $id='null'; $ans = mysqli_real_escape_string($link, $_POST['ans']); //$first_name = mysqli_real_escape_string($link, $_POST['first_name']); $sql = "INSERT into base (ans)VALUES ('$ans')"; if(mysqli_query($link, $sql)){ echo '<a href="quiz2.html">BEGIN TEST</a>'; } else{ echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } mysqli_close($link);
  2. i am able to fetch data in radio buttons format but not able to insert in the mysql db anyhelp would be very highly appreciated thanks in advance this is the code <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $db='tutorial'; $conn = mysqli_connect($dbhost, $dbuser, $dbpass,$db); //global $value; if(isset($_POST['value'])){ $value = $_POST['value']; } if(! $conn ) { die('Could not connect: ' . error); } $sql = 'SELECT q1,option1,option2,option3 FROM questions '; //mysqli_select_db('tutorial'); $result = mysqli_query( $conn, $sql); if(! $result ) { die('Could not get data: ' ); } while($row = mysqli_fetch_array($result)) { echo "{$row['q1']}" .'</br></br>'. " A <input type='radio' name='ans' value='{$row['option1']}'>" . $row['option1'] . '<br> ' . " B <input type='radio' name='ans' value='{$row['option2']}'>" . $row['option2'] . '<br> '. " C <input type='radio' name='ans' value='{$row['option3']}'>" . $row['option3'] . '<br> '.'<br>'; mysqli_close($conn) ?>
  3. if(! $conn ) { die('Could not connect: ' . error); } $sql = 'SELECT q1,option1,option2,option3 FROM questions'; //mysqli_select_db('tutorial'); $result = mysqli_query( $conn, $sql); if(! $result ) { die('Could not get data: ' ); } while($row = mysqli_fetch_array($result)) { echo('<input type="radio" name="q1" value="q1'.$row[0].'"/>'.//$row1[0] :$row[0]} <br><br> ". " {$row[1]} <br> ". " B {$row[2]} <br> ". " C {$row[3]} <br> ". "--------------------------------<br>"); } basically i am fetching the data from mysql using the above command and want to display theses options as radio button but instead the output is showing radio button but no fetched data from mysql the lline is highlighted kindly help , thanks in advance i am trying to learning php
  4. <?php $link = mysqli_connect("localhost", "root", "", "tutorial"); if($link === false){ die("ERROR: Could not connect. " . mysqli_real_escape_string_error()); } $jawab = mysqli_real_escape_string($link, $_POST['jawab']);//unidentified index error $sql = "INSERT into answers (jawab) VALUES ('$jawab' )"; //$link_address='quiz2.php'; if(mysqli_query($link, $sql)){ echo '<a href="quiz55.php">link</a>'; //<include q6.php> } else{ echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } // close connection mysqli_close($link); ?> <!DOCTYPE HTML> <head> <title></title></head> <body> <?php include 'q5.php' ?><!-- for fetching data --> jawab: <?php include 'insert11.php' ?><!--for inserting data --> <input type="radio" name="jawab" value="A">Saudia Arabia <input type="radio" value="Karachi"> Karachi <input type="radio" name="jawab" value="Lahore">Lahore <input type="radio" name="jawab" value="UAE">UAE <input type="submit"value="SUBMIT"> <body> </html> As i am a newbie in php please pardon me for these simple errors, thanks in advance i need to resolve the following issues which are currently occurring errors which are faced are not correct value of radio button is inserted in to MySQL db secondly the html form which I have keeps on loading even after submit , unidentified index in line, lastly the data is fetched correctly but without radio buttons ( as this is an mcq quiz ) the files which I have made are as follows q5.php // for fetching the data q55.php// form and for including q5.php and insert11.php for the data insertion in db insert11.php //for storing the data in db through radio button the code are as follows q55.php
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.