newone Posted December 18, 2016 Share Posted December 18, 2016 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/302765-php-radio-buttons-and-file-inclusions/ Share on other sites More sharing options...
benanamen Posted December 18, 2016 Share Posted December 18, 2016 (edited) Instead of doing the includes, why don't you start with a single page of code and get that to work first. The index error is because you are trying to use a POST variable before it is set. You need to make sure it is set before you try to use it. Your code is so all over the place I can't even follow it well. I will leave it to others to take it from here unless you can post revised single page code. Edited December 18, 2016 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/302765-php-radio-buttons-and-file-inclusions/#findComment-1540463 Share on other sites More sharing options...
ginerjm Posted December 19, 2016 Share Posted December 19, 2016 Write a script in pieces - design the html page and add to it some needed php vars where you want to place dynamic stuff/data, etc. Then write the php code to do what needs to be done to populate those vars. Put it all together with the php at the beginning and the html/js/css at the end. Check to see if your POST data has been received before just using it. Do not put 'includes' in your html. When programming in any language - DESIGN is key! Quote Link to comment https://forums.phpfreaks.com/topic/302765-php-radio-buttons-and-file-inclusions/#findComment-1540483 Share on other sites More sharing options...
newone Posted January 9, 2017 Author Share Posted January 9, 2017 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) ?> Quote Link to comment https://forums.phpfreaks.com/topic/302765-php-radio-buttons-and-file-inclusions/#findComment-1541208 Share on other sites More sharing options...
ginerjm Posted January 9, 2017 Share Posted January 9, 2017 Looking at your latest code (#4) it seems that you are a bit haphazard with your thought process. You do your db connect well before you have a need for it. Plus you do the connect, go get an input value, and THEN decide to check if the connection succeeded. Hmmm.... You ask about doing an update to your db, but your code only shows an inquiry. Also your code is incomplete - in fact when I tried to run it I got an error because you left your while loop open. What am I missing? Quote Link to comment https://forums.phpfreaks.com/topic/302765-php-radio-buttons-and-file-inclusions/#findComment-1541222 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.