I'm studying a way to use the Google Books API.
Using this code have the expected result.
$page = file_get_contents("https://www.googleapis.com/books/v1/volumes?q=julio+verne&maxResults=40");
$data = json_decode($page, true);
for($a = 0 ; $a <= 39 ; $a++) {
$img = $data['items'][$a]['volumeInfo']['imageLinks']['thumbnail'];
print '<img src="'.$img.'" alt="ScanLine"/>';
echo '<br>';
echo "Title = " . $data['items'][$a]['volumeInfo']['title'];
echo '<br>';
echo "Authors = " . #implode(",", $data['items'][$a]['volumeInfo']['authors']);
echo '<br>';
echo "Editora = " . $data['items'][$a]['volumeInfo']['publisher'];
echo '<br>';
echo "id = " . $data['items'][$a]['id'];
echo '<br>';
echo "Resumo = ";
echo "<p>" . $data['items'][$a]['volumeInfo']['description'];
echo '</p><br>';
}
On the other hand, implementing and using the code form the code does not work.
My page with form have this code:
<form action="action.php" method="POST">
<div class="form-group">
<div class="campos">
<label>
Search
</label>
<input type="text" name="search" style="margin-right: 10px; width:250px; float:left" class="input-field" placeholder="Title, Author..." />
<input type=hidden name=numResults value="&maxResults=40">
<button type="submit" id="search" class="btn btn-default">Search</button>
</div>
</div>
</form>
And my action have this code:
$var1 = "https://www.googleapis.com/books/v1/volumes?q=";
$var2 = urlencode($_POST['search']);
$var3 = "&maxResults=40";
$str = str_replace(" ", "+", $var2);
$page = $var1.$str.$var3;
$data = json_decode($page, true);
echo $page;
echo '<br>';
for($a = 0 ; $a <= 39 ; $a++) {
$img = $data['items'][$a]['volumeInfo']['imageLinks']['thumbnail'];
print '<img src="'.$img.'" alt="ScanLine"/>';
echo '<br>';
echo "Title = " . $data['items'][$a]['volumeInfo']['title'];
echo '<br>';
echo "Authors = " . #implode(",", $data['items'][$a]['volumeInfo']['authors']);
echo '<br>';
echo "Editora = " . $data['items'][$a]['volumeInfo']['publisher'];
echo '<br>';
echo "Resumo = ";
echo "<p>" . $data['items'][$a]['volumeInfo']['description'];
echo '</p><br>';
}
What must be wrong?
Any advise?
Thanks from Brazil
You are not calling file_get_contents() in the second example. So $page is just the url.
$page = file_get_contents($var1.$str.$var3);
Related
}
put returns between paragraphs
for linebreak add 2 spaces at end
italic or bold
indent code by 4 spaces
backtick escapes like _so_
quote by placing > at start of line
to make links (use https whenever possible)
You could have another session that stores the answers as an array, and add to it after each successful post
Something like this could work:
<?php
$totalQuestions = count($ques);
$_SESSION['answers'] = $_SESSION['answers'] ?? [];
// Get current question, default to 1
$currentQuestion = count($_SESSION['answers']) == $totalQuestions ?
$totalQuestions :
$_SESSION['answers'] + 1;
?>
<div class='questionHeader'>
<label>Question <?php echo $currentQuestion ?> of <?php echo $totalQuestions ?></label>
</div>
<br>
<div class='question'>
<?php echo $ques[$currentQuestion-1] ?>
</div>
Answer: <input type='text' id='answerOneSub' name='answerOneSub'>
<button type='submit' value='submit' name='submit'>Submit!</button>
<?php
if (isset($_POST['submit'])) {
$_SESSION['answers'][] = $_POST['answerOneSub'];
echo "<br>" . $_SESSION['answerOneSub'];
}
?>
You can use query param like this:
<?php
$page = 1;
if (isset($_GET["page"])) {
$page = (int)$_GET["page"];
}
$url = strtok($_SERVER["REQUEST_URI"], '?');
echo "<form method='post' action='" . $url . "?page=" . ($page + 1) . "'>";
echo "<div class='questionHeader'><label>Question [$page] of 6</label></div>";
echo "<br>";
echo "<div class='question'>" . $ques[$page - 1] . "</div>";
echo "<br>";
echo "Answer: ";
echo "<input type='text' id='answerOneSub' name='answerOneSub'>";
echo "<button type='submit' value='submit' name='submit'>Submit!</button>";
echo "</form>";
if (isset($_POST['submit'])) {
$_SESSION['answerOneSub'] = $_POST['answerOneSub'];
echo "<br>" . $_SESSION['answerOneSub'];
}
Here is my code and i need to insert array values in $testar in to the table patients_testings. But it doesn't work with this code, where is the error? if i can do this using one global variable. it will be more helpful. thank you.
<form role="form" method="post" action="" name="testing" onsubmit="return validate_form()">
<?php
$sqltestin = "SELECT * FROM testings";
$querytestin = mysqli_query($dbhandle, $sqltestin);
while ($rowtestin = mysqli_fetch_assoc($querytestin)) {
echo '<input type="checkbox" name="testingar[]" value="' . $rowtestin['TestId'] . '">' . $rowtestin['TestName'] . '<br>';
}
?>
<div class="modal-footer">
<input type="submit" name="submittestin" id="submittestin" class="btn btn-success" value="Add Tests">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</form>
</div>
</div>
</div></div>
<?php
$checkBox = '';
$testar = '';
if (isset($_POST['submittestin'])) {
global $checkBox;
global $testar;
$checkBox = $_POST['testingar'];
foreach ($checkBox as $testar1) {
$testar .= $testar1 . ",";
}
$tot = 0.00;
for ($i = 0; $i < sizeof($checkBox); $i++) {
$queryt2 = "SELECT * FROM testings WHERE TestId = $checkBox[$i] ";
$resultt2 = mysqli_query($dbhandle, $queryt2) or die (mysql_error());
while ($rowt2 = mysqli_fetch_assoc($resultt2)) {
echo "<tr><td>" . $rowt2['TestName'] . "</td>";
echo "<td width='100'>" . $rowt2['specimen'] . "</td>";
echo "<td>" . $rowt2['HopePrice'] . "</td></tr>";
//echo '<br/>';
$tot = $tot + $rowt2['HopePrice'];
}
}
echo "<tr><td><b>Total</b></td><td <b>:</b></td><td><b>" . number_format($tot, 2) . "</b></td></tr>";
echo "<tr><td><form role='form' method='post' action=''><input type='submit' name='printinv' id='printinv' class='btn btn-success' value='Print'></form></td></tr>";
//echo $testar;
if (isset($_POST['printinv'])) {
$sqltnum = "INSERT INTO patients_testings VALUES ('$ref_no','$testar')";
if (mysqli_query($dbhandle, $sqltnum) or die (mysql_error())) {
echo "Entered Successfully";
//}
}
}
}
?>
Why your code does not work:
I think the concept that you are missing is that when the page is requested, and on every subsequent form submission, the PHP code is executed then exits which throws out the values of the variables stored in memory. Making the variables global does not make them persist between requests.
Specifics to your code:
The first time the form is submitted isset($_POST['submittestin']) is true and it successfully populates the $testar variable with data. However, on the second post isset($_POST['submittestin']) is false and so you never hit the if (isset($_POST['printinv'])) section. Now, even if you move the if (isset($_POST['printinv'])) outside the first if ... submittestin you still have a problem because the $testar will no longer be populated with data.
Additionally, you use variables which are never initialized anywhere that I can see. $ref_no is an example.
I would also suggest echoing out your DB queries to see if they are properly formatted before you run them. I think that some of them may be missing 's in places.
How to make data persist between requests?
The best way is to start a session. By starting a session you can save variables in the $_SESSION array and then access them durring a different request.
Note: You cannot serialize resorces so you will need to reconnect to the database on each request. I.e., this won't work: $_SESSION['dbhandle'] = $dbhande;
Another way to set <input type=hidden ... elements in your form so that on the second post you can access them again through the $_POST variable.
Attempt to make your code use sessions:
<?php
session_start();
?>
<form role="form" method="post" action="" name="testing" onsubmit="return validate_form()">
<?php
$sqltestin = "SELECT * FROM testings";
$querytestin = mysqli_query($dbhandle, $sqltestin);
while ($rowtestin = mysqli_fetch_assoc($querytestin)) {
echo '<input type="checkbox" name="testingar[]" value="' . $rowtestin['TestId'] . '">' . $rowtestin['TestName'] . '<br>';
}
?>
<div class="modal-footer">
<input type="submit" name="submittestin" id="submittestin" class="btn btn-success" value="Add Tests">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</form>
</div>
</div>
</div></div>
<?php
$checkBox = '';
$testar = '';
if (isset($_POST['submittestin'])) {
global $checkBox;
global $testar;
$checkBox = $_POST['testingar'];
foreach ($checkBox as $testar1) {
$testar .= $testar1 . ",";
}
$_SESSION['testar'] = $testar;
$_SESSION['ref_no'] = "This gets used below but I don't see it initialized anywhere?";
$tot = 0.00;
for ($i = 0; $i < sizeof($checkBox); $i++) {
$queryt2 = "SELECT * FROM testings WHERE TestId = '".$checkBox[$i]."'"; // syntax issue here
$resultt2 = mysqli_query($dbhandle, $queryt2) or die (mysql_error());
while ($rowt2 = mysqli_fetch_assoc($resultt2)) {
echo "<tr><td>" . $rowt2['TestName'] . "</td>";
echo "<td width='100'>" . $rowt2['specimen'] . "</td>";
echo "<td>" . $rowt2['HopePrice'] . "</td></tr>";
//echo '<br/>';
$tot = $tot + $rowt2['HopePrice'];
}
}
echo "<tr><td><b>Total</b></td><td <b>:</b></td><td><b>" . number_format($tot, 2) . "</b></td></tr>";
echo "<tr><td><form role='form' method='post' action=''>";
echo "<input type='submit' name='printinv' id='printinv' class='btn btn-success' value='Print'>";
echo "</form></td></tr>";
}
//echo $testar;
if (isset($_POST['printinv'])) {
if(isset($_SESSION['testar']) {
$testar = $_SESSION['testar'];
$ref_no = $_SESSION['refno'];
$sqltnum = "INSERT INTO patients_testings VALUES ('$ref_no', '$testar')"; // Where is $ref_no set?
if (mysqli_query($dbhandle, $sqltnum) or die (mysql_error())) {
echo "Entered Successfully";
}
}
}
?>
My main question is why is PDO::exec not executing every iteration of my loop, and instead only executing in the first iteration.
I am trying to insert coordinates into my MySQL database.
My database structure is (number(primary key), x, y, z).
I ask the user to insert a number ($n), and then ask them to fill in $n sets of coordinates.
The users inputs are passed to another page with $_POST, then retrieved by dynamic variable names and inserted into the database.
Everything works, except the loop only writes to the database its first iteration. So I end up with results for x1,z1,y1 but nothing else.
Can anyone explain what I am doing wrong (other than not using arrays)?
<?php
require_once('db.php');
$n = $_POST['selectOption'];
for($i = 1; $i < $n+1;$i++){
${'x' . $i} = $_POST["x" . $i];
${'y' . $i} = $_POST["y" . $i];
${'z' . $i} = $_POST["z" . $i];
$rowsAffected = $db->exec("INSERT INTO coordinate3d (number,x,y,z)
VALUES ('$n', '${'x' . $i}', '${'y' . $i}', '${'z' . $i}')");
}
?>
Here is my form
<form action="aaron_stockdale_dynamic_process.php" method="post" name="coordinateForm">
<?php
for($i = 0; $i < $n; $i++)
{
?>
x<?php echo $i+1;?> <input name="x<?php echo $i+1;?>" type=text>, y<?php echo $i+1;?> <input name="y<?php echo $i+1;?>" type=text>, z<?php echo $i+1;?> <input name="z<?php echo $i+1;?>" type=text><br>
<?php
}
?>
<br>
<input type="hidden" name="selectOption" value="<?php echo $n;?>">
<input type="submit" oonClick="document.location.href='aaron_stockdale_dynamic_process.php'" value="Submit">
</form>
require_once('aaron_stockdale_database.php');
$n = $_POST['selectOption'];
for($i = 1; $i < $n+1;$i++){
$x = $_POST["x" . $i];
$y = $_POST["y" . $i];
$z = $_POST["z" . $i];
$rowsAffected = $db->exec("INSERT INTO coordinate3d (number,x,y,z)
VALUES ('$n', '$x', '$y', '$z')");
}
the rest is on you ;)
And also check if any of the fields a primary key, that will prevent insert it twice.
Since you have received an acceptable answer for your question, I'd like to give you a hint on your html code.
<form action="aaron_stockdale_dynamic_process.php" method="post" name="coordinateForm">
<?php
for($i = 0; $i < $n; $i++)
{
?>
x<?php echo $i+1;?> <input name="x<?php echo $i+1;?>" type=text>, y<?php echo $i+1;?> <input name="y<?php echo $i+1;?>" type=text>, z<?php echo $i+1;?> <input name="z<?php echo $i+1;?>" type=text><br>
<?php
}
?>
<br>
<input type="hidden" name="selectOption" value="<?php echo $n;?>">
<input type="submit" oonClick="document.location.href='aaron_stockdale_dynamic_process.php'" value="Submit">
</form>
Now, this code can be cleaned up a bit.
<form action="aaron_stockdale_dynamic_process.php" method="post" name="coordinateForm">
<?php
for($i = 0; $i < $n; $i++)
{
echo 'x' . $i+1 . '<input name="x' . $i+1 . '" type=text>, y' . $i+1 . ' <input name="y' . $i+1. '" type=text>, z' . $i+1 . '<input name="z' . $i+1 . '" type=text><br>'
}
?>
<br>
<input type="hidden" name="selectOption" value="<?php echo $n;?>">
<input type="submit" value="Submit">
</form>
I changed the "oonClick" to "onClick", and then afterwards I removed it, as when you submit, you don't need to navigate, as the browser will do this, upon submission.
And then I removed the repetitive opening and closing of php tags, and combined all the echos into one.
Here's my solution in one file:
<!DOCTYPE html>
<html lang=en>
<head>
<script>
function validcoord(e) {
var key;
var keychar;
if (window.event)
key = window.event.keyCode;
else if (e)
key = e.which;
else
return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
// control keys
if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
return true;
// Numeral Characters
else if ((("0123456789-.,").indexOf(keychar) > -1))
return true;
else
return false;
}
</script>
<style>
input[type="number"] { text-align: right; width: 50px; }
label { margin-left: 4em; }
</style>
</head>
<body>
<?php
define ("SELF", $_SERVER['PHP_SELF']);
define ("EOL", "\r\n");
// Modify as needed
define ("MINNUMCORDS" , "1");
define ("MAXNUMCORDS" , "10");
define ("DFLTNUMCORDS", "2");
$formSubmitted = (empty($_POST)) ? FALSE : TRUE;
if (!$formSubmitted) {
$htmlOutput = '
<form action="' . SELF . '" method=post name=foo id=foo>
<input type=hidden name=current value=0>
<label>Enter the number of Coordinates:
<input type=number autofocus onFocus="this.select()"' .
' min=' . MINNUMCORDS .
' max=' . MAXNUMCORDS .
' value=' . DFLTNUMCORDS .
' name=numcords /></label>
</form>' . EOL;
echo $htmlOutput;
} // end if not submitted
else { // a form HAS been submitted
foreach ($_POST as $key => $value) { $$key = $value; }
unset($_POST);
if (!empty($coord)) { // We got some input that may be a valid x,y,z coordinate
if ( substr_count($coord, ",") != 2 ) {
$error = "We're looking for THREE numbers seperated by TWO commas.";
} // end if we don't have three values
else { // We got three Values
$coord = trim($coord);
list($x,$y,$z) = explode(",", $coord);
if ( !(is_numeric($x) && is_numeric($y) && is_numeric($z)) ) {
$error = "We're looking for three VALID NUMBERS seperated by two commas.";
} // end if all three numbers are not valid
else { // We got three Values and each of them are numbers
require('db.php');
$rowsAffected = $db->exec("INSERT INTO coordinate3d (number,x,y,z)
VALUES ('$numcords', '$x', '$y', '$z')");
//echo "INSERT INTO coordinate3d (number,x,y,z) VALUES ('$numcords', '$x', '$y', '$z')<br />" . EOL;
} // end three valid numbers
} // end three values
} // end if we have some input in $coord
if ($error) {
echo "~~ " . $error . "<br /><br />" . EOL;
--$current;
} // end if error
if ( $current < $numcords ) {
$htmlOutput = 'Please enter the coordinate in the form: x,y,z (Ex: -.4,2,8.5)' . EOL;
$htmlOutput .= '<form action="' . SELF . '" method=post name=bar id=bar>' . EOL;
$htmlOutput .= ' <input type=hidden name=numcords value="' . $numcords . '" />' . EOL;
$htmlOutput .= ' <input type=hidden name=current value="' . ++$current . '" />' . EOL;
$htmlOutput .= ' <label>Coord #' . $current . ': ';
$htmlOutput .= '<input type=text name=coord size=12 maxlength=48 ' .
'autofocus onKeyPress="return validcoord(event);" /></label>' . EOL;
$htmlOutput .= '</form>' . EOL;
echo $htmlOutput;
} // end if we need to get another coord
} // end form was submitted
?>
</body>
</html>
I am trying to store multiple items into a session. I am posting an items from a form like so:
<?php
$product_id = $_GET['product_id'];
$sql = "SELECT * FROM Products WHERE product_id = $product_id";
$result = $conn->query($sql);
if($result->num_rows > 0){
while($row = $result->fetch_assoc()){
echo '<img src=' . $row['product_img'] . ' />';
echo '<div class="title">'. $row['product_name'] .'</div>';
echo '<div class="title">'. $row['product_price'] .'</div>';
echo '<div class="title">'. $row['product_sku'] .'</div>';
echo '<div class="title">'. $row['product_description'] .'</div>';
echo '<form action="addToCart.php" method="post">
<input type="hidden" name="product_img" value="' . $row['product_img'] . '" />
<input type="hidden" name="product_id" value="' . $row['product_id'] . '" />
<input type="hidden" name="product_name" value="' . $row['product_name'] . '" />
<input type="hidden" name="product_price" value="' . $row['product_price'] . '" />
<input type="hidden" name="product_sku" value="' . $row['product_sku'] . '" />
<input type="hidden" name="product_description" value="' . $row['product_description'] . '" />
<input type="submit" name="Submit">
</form>';
}
} else{
echo "0 Results";
}
?>
addToCart.php looks like this:
<?php
if (isset($_POST['Submit'])) {
$_SESSION['product_img'] = $_POST['product_img'];
$_SESSION['product_id'] = $_POST['product_id'];
$_SESSION['product_name'] = $_POST['product_name'];
$_SESSION['product_price'] = $_POST['product_price'];
$_SESSION['product_sku'] = $_POST['product_sku'];
$_SESSION['product_description'] = $_POST['product_description'];
}
?>
So the above is now setting the items into the session (So I believe). I am then outputting the item from the stored data in basket.php
<?php echo '<img src=' . $_SESSION['product_img'] . ' />'; ?>
<?php echo $_SESSION['product_id'];?>
<?php echo $_SESSION['product_name'];?>
<?php echo $_SESSION['product_price'] ?>
<?php echo $_SESSION['product_sku']; ?>
<?php echo $_SESSION['product_description']; ?>
the Issue I have is whenever I add another item it overrides the previous item? I know I need to use an array to store multiple items but I have tried a few different things but I am struggling to understand.
You can use [] to store them in array:
$_SESSION['product_img'][] = $_POST['product_img'];
$_SESSION['product_id'][] = $_POST['product_id'];
$_SESSION['product_name'][] = $_POST['product_name'];
$_SESSION['product_price'][] = $_POST['product_price'];
$_SESSION['product_sku'][] = $_POST['product_sku'];
$_SESSION['product_description'][] = $_POST['product_description']
Now, try to see what are in each array:
var_dump($_SESSION['product_id']);
It is possible to store your Session Data as nested array. In your case, since it is a Shopping Cart, you may want to build your Arrays using the ID of the Product; that way you are certain that no product will override the other (so long as they don't have the same product_id values.... Below is an example of how you may do that:
<?php
//FIRST CHECK IF SESSION EXIST BEFORE STARTING IT:
if (session_status() == PHP_SESSION_NONE || session_id() == '') {
session_start();
}
if (isset($_POST['Submit'])) {
$product_id = htmlspecialchars(trim($_POST['product_id']));
$product_img = htmlspecialchars(trim($_POST['product_img']));
$product_sku = htmlspecialchars(trim($_POST['product_sku']));
$product_name = htmlspecialchars(trim($_POST['product_name']));
$product_price = htmlspecialchars(trim($_POST['product_price']));
$product_description = htmlspecialchars(trim($_POST['product_description']));
if(!isset($_SESSION['products'])){
$_SESSION['products'] = array();
}
if(!isset($_SESSION['products'][$product_id])){
$_SESSION['products'][$product_id] = array();
}
$_SESSION['products'][$product_id]['product_id'] = $product_id;
$_SESSION['products'][$product_id]['product_img'] = $ $product_img;
$_SESSION['products'][$product_id]['product_name'] = $product_name;
$_SESSION['products'][$product_id]['product_price'] = $product_price;
$_SESSION['products'][$product_id]['product_sku'] = $product_sku;
$_SESSION['products'][$product_id]['product_description'] = $product_description;
}
And anywhere else (another Script perhaps) you could access your Data like so:
<?php
$output = "";
$storedProductData = $_SESSION['products'];
if(!empty($storedProductData)){
foreach($storedProductData as $product_id=>$productData){
$output .= "<img src='{$productData['product_img']}' />" . PHP_EOL;
$output .= "<span id='generic-class'>{$productData['product_id']}</span>" . PHP_EOL;
$output .= "<span id='generic-class'>{$productData['product_name']}</span>" . PHP_EOL;
$output .= "<span id='generic-class'>{$productData['product_price']}</span>" . PHP_EOL;
$output .= "<span id='generic-class'>{$productData['product_sku']}</span>" . PHP_EOL;
$output .= "<span id='generic-class'>{$productData['product_description']}</span>" . PHP_EOL;
}
}
I am working to show editable fields based on query results. I know the query is functioning properly, and it is returning an array. The array is populating the form fields properly, however, I am getting the "Invalid argument supplied for foreach()" warning. I am new at this, and at a loss as to what is happening. I appreciate any suggestions.
Here is the code:
// Grab the profile data from the database
$query8 = "SELECT * FROM EDUCATION WHERE ID_NUM = '" . $_SESSION['IDNUM'] . "' ORDER BY RECORD";
$data = mysqli_query($dbc, $query8);
echo '<pre>' . print_r($data, true) . '</pre>';
$rowcount = 1;
while ($row = mysqli_fetch_assoc($data))
{
if (is_array($row))
{
echo '<p> It is an Array</p>';
}
foreach($row as &$item)
{
$record = $row['RECORD'];
$school = $row['SCHOOL'];
$type = $row['TYPE'];
$degree = $row['DEGREE'];
$major = $row['MAJOR'];
$grad = $row['GRAD'];
?>
<form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<fieldset>
<legend>Education History </legend>
<?php
echo '<input type="hidden" id="record" name="record" value="' . $record . '">';
echo 'Rowcount' . $rowcount. '</br>';
// Insert Listbox here
$queryschool = "SELECT * FROM SCHOOL";
$list = mysqli_query($dbc, $queryschool);
if($list)
{
echo 'School Type? ';
echo '<select name="school_code">';
while($row = mysqli_fetch_assoc($list))
{
echo "<option value={$row['CODE']}>{$row['TYPE']}" ;
echo '</option>';
}
echo '</select>';
}
echo '<br />';
echo '<label for="school">School Name:</label>';
echo '<input type="text" id="school" name="school" size="40" maxlength="40" value="' . ( (!empty($school)) ? $school : "") . '" /><br />';
// Insert Listbox here
$querydegree = "SELECT * FROM DEGREE";
$list = mysqli_query($dbc, $querydegree);
if($list)
{
echo 'Degree Type? ';
echo '<select name="degree_code">';
while($row = mysqli_fetch_assoc($list))
{
echo "<option value={$row['CODE']}>{$row['DEGREE']}";
echo '</option>';
}
echo '</select>';
}
echo '<br />';
echo '<label for="major">Field of study:</label>';
echo '<input type="text" id="major" name="major" size="40" maxlength="40" value="' . ( (!empty($major)) ? $major : "") . '" /><br />';
echo '<label for="grad">Did you graduate?:</label>';
echo '<input type="radio" id="grad" name="grad" value="Y" ' . ($grad == "Y" ? 'checked="checked"':'') . '/>Yes ';
echo '<input type="radio" id="grad" name="grad" value="N" ' . ($grad == "N" ? 'checked="checked"':'') . '/>No<br />';
?>
</fieldset>
<?php
$rowcount++;
}
}
;
echo '<label for="another">Do you need to enter more educational experience?:</label>';
echo '<input type="radio" id="another" name="another" value="Y" ' . ($another == "Y" ? 'checked="checked"':'') . '/>Yes ';
echo '<input type="radio" id="another" name="another" value="N" ' . ($another == "N" ? 'checked="checked"':'') . '/>No<br />';
?>
<input type="submit" value="Save Profile" name="submit" />
</form>
foreach ($row as &$item)
replace this with:
foreach ($row as $item)
And then for each variable you should probably change
$record = $row['RECORD'];
to
$record = $item['RECORD'];
foreach($row as &$item) should be
foreach($row as $item)
there is no need to use the foreach here you can just do this like like
while ($row = mysqli_fetch_assoc($data))
{
$record = $row['RECORD'];
$school = $row['SCHOOL'];
$type = $row['TYPE'];
$degree = $row['DEGREE'];
$major = $row['MAJOR'];
$grad = $row['GRAD'];
}
You're not changing the row item, so don't pass by reference to the foreach. Also, shouldn't you be using $item instead of $row? Do this:
foreach($row as $item)
{
$record = $item['RECORD'];
$school = $item['SCHOOL'];
....
Don't do This:
foreach($row as &$item)
{
$record = $row['RECORD'];
$school = $row['SCHOOL'];
....