And I again I have to deal with PHP and MySQL :) So, I've got a mysql table and want to have "add" feature. So I can edit my table from browser easily. So far I have done nearly everything but the problem is that variable consisting "number" from my table (or id) won't _POST to other page. It won't _POST directly from textarea or even if I put it in a hidden field(well, have just understood that this is pretty much the same).
Let me show you some examples:
$a = mysql_query("SELECT number FROM peoples ORDER BY number DESC LIMIT 1");
$number_a = mysql_fetch_assoc($a);
$number = $number_a['number']+1;`
That's how I got this variable.
echo '<input name="id" type="hidden" value="'.$number.'" />';
That's how I pass it.
echo $number = mysql_escape_string( $_POST['id'] );
That's how I tried to get it in other php file.
Everything from other textareas passes just fine.
Full code as requested. ADD.PHP:
<?php
$dblocation = "127.0.0.1";
$dbname = "tvp";
$dbuser = "root";
$dbpasswd = "";
$dbcnx = #mysql_connect($dblocation,$dbuser,$dbpasswd);
if (!$dbcnx)
{
echo( "<P>В настоящий момент сервер базы данных не доступен, поэтому
корректное отображение страницы невозможно.</P>" );
exit();
}
if (!#mysql_select_db($dbname, $dbcnx))
{
echo( "<P>В настоящий момент база данных не доступна, поэтому
корректное отображение страницы невозможно.</P>" );
exit();
}
echo '<form name="editform" action="adder.php" method="POST">';
echo '<table>';
echo '<tr>';
echo '<td>Номер</td>';
$a = mysql_query("SELECT number FROM peoples ORDER BY number DESC LIMIT 1");
$number_a = mysql_fetch_assoc($a);
$number = $number_a['number']+1;
echo $number;
var_dump($number);
print_r($number);
echo '<td><textarea name="number" >'.$number.'</textarea></td>';
echo '<input name="id" type="hidden" value="'.$number.'" />';
echo '</tr>';
echo '<tr>';
echo '<td>Имя</td>';
echo '<td><textarea name="givenName">'.$man['givenName'].'</textarea></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Инициалы</td>';
echo '<td><textarea name="middleInitial">'.$man['middleInitial'].'</textarea></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Фамилия</td>';
echo '<td><textarea name="surname">'.$man['surname'].'</textarea></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Пол</td>';
echo '<td> <input type="radio" name="gender" value=1 >Man<Br>
<input type="radio" name="browser" value=0>Woman<Br> </td>';
echo '</tr>';
echo '<tr>';
echo '<td>Город</td>';
echo '<td><textarea name="city">'.$man['city'].'</textarea></td>';
echo '</tr>';
echo '<input name="id" type="hidden" value="'.$id.'" />';
echo '<input name="statee" type="hidden" value="'.$man['state'].'" />';
echo '<tr>';
echo '<td>Штат</td>';
?>
<td><select size="3" name="state">
<option disabled>Выберите штат</option>
<option value="AL"
<?php
if($man['state']=="AL"){
echo "selected";
}?>
>Alabama
</option>
//...and so on...
</select></td>
<?php
echo '</tr>';
echo '<tr>';
echo '<td>Телефон</td>';
echo '<td><textarea name="telephone">'.$man['telephone'].'</textarea></td>';
echo '</tr>';
echo '<tr>';
echo '<td>E-mail</td>';
echo '<td><textarea name="emailAddress">'.$man['emailAddress'].'</textarea></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Дата</td>';
echo '<td><textarea name="birthday">'.$man['birthday'].'</textarea></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Место работы</td>';
echo '<td><textarea name="occupation">'.$man['occupation'].'</textarea></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Компания</td>';
echo '<td><textarea name="company">'.$man['company'].'</textarea></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Вес</td>';
echo '<td><textarea name="weight">'.$man['weight'].'</textarea></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Рост</td>';
echo '<td><textarea name="length">'.$man['length'].'</textarea></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Адрес</td>';
echo '<td><textarea name="streetAddress">'.$man['streetAddress'].'</textarea></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Почтовый индекс</td>';
echo '<td><textarea name="zipCode">'.$man['zipCode'].'</textarea></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Страна</td>';
echo '<td><textarea name="country">'.$man['country'].'</textarea></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="submit" value="Сохранить"></td>';
echo '<td><button type="button" onClick="history.back();">Отменить</button></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
?>
And ADDER.PHP:
<?php
$dblocation = "127.0.0.1";
$dbname = "tvp";
$dbuser = "root";
$dbpasswd = "";
$dbcnx = #mysql_connect($dblocation,$dbuser,$dbpasswd);
if (!$dbcnx)
{
echo( "<P>В настоящий момент сервер базы данных не доступен, поэтому
корректное отображение страницы невозможно.</P>" );
exit();
}
if (!#mysql_select_db($dbname, $dbcnx))
{
echo( "<P>В настоящий момент база данных не доступна, поэтому
корректное отображение страницы невозможно.</P>" );
exit();
}
$number=$_POST["id"]; echo '<br>';
var_dump($_POST['id']);
print_r($POST['id']);
echo $number;
echo $givenName = mysql_escape_string( $_POST['givenName'] ); echo '<br>';
echo $middleInitial = mysql_escape_string( $_POST['middleInitial'] ); echo '<br>';
echo $surname = mysql_escape_string( $_POST['surname'] ); echo '<br>';
echo $gender = $_POST['gender'] ; echo '<br>';
echo $city = mysql_escape_string( $_POST['city'] ); echo '<br>';
echo $state = mysql_escape_string( $_POST['state'] );echo '<br>';
echo $emailAddress = mysql_escape_string( $_POST['emailAddress'] ); echo '<br>';
echo $telephone = mysql_escape_string( $_POST['telephone'] ); echo '<br>';
echo $birthday = mysql_escape_string( $_POST['birthday'] ); echo '<br>';
echo $occupation = mysql_escape_string( $_POST['occupation'] );echo '<br>';
echo $company = mysql_escape_string( $_POST['company'] ); echo '<br>';
echo $weight = mysql_escape_string( $_POST['weight'] ); echo '<br>';
echo $length = mysql_escape_string( $_POST['length'] ); echo '<br>';
echo $streetAddress = mysql_escape_string( $_POST['streetAddress'] ); echo '<br>';
echo $zipCode = mysql_escape_string( $_POST['zipCode'] ); echo '<br>';
echo $country = mysql_escape_string( $_POST['country'] ); echo '<br>';
$query = "INSERT INTO peoples (number,givenName, middleInitial, surname, gender, city, state, emailAddress, telephone, birthday, occupation, company, weight, length, streetAddress, zipCode, country) VALUES ( '".$number."', '".$givenName."', '".$middleInitial."', '".$surname."', '".$gender."', '".$city."', '".$state."', '".$emailAddress."', '".$telephone."', '".$birthday."', '".$occupation."', '".$company."', '".$weight."', '".$length."', '".$streetAddress."', '".$zipCode."', '".$country."');";
mysql_query ( $query );
?>
Thanks in advance!
first things first. make sure you are echoing out the number to the screen. the code you have written looks correct but it's just a snippet.
add var_dump($number) after you assign your number and see if it's showing the number. if it's not then theres a problem with your sql
the problem is your re-assigning the hidden field id at the bottom of your form
here
echo '<td><textarea name="city">'.$man['city'].'</textarea></td>';
echo '</tr>';
echo '<input name="id" type="hidden" value="'.$id.'" />'; <------- HERE
echo '<input name="statee" type="hidden" value="'.$man['state'].'" />';
echo '<tr>';
echo '<td>Штат</td>';
i'm assuming you never assigned $id to number so, at the top of your form, yours assigning the hidden field id to "$number" but at the bottom of the form your assigning the hidden field id to $id. overwriting the original id field from the top of the form
You are echoing!
echo $number = mysql_escape_string( $_POST['id'] );
Change that with:
$number = mysql_escape_string( $_POST['id'] );
echo $number;
If you wanna echo it.
Related
Alright, So I have 2 different tables in one DB, I am trying to use a while statement to echo out a name from one table and then echo out a selector for each name..
For instance, If there is only one name in the table, There would be only one selector, Else if there was two names, But the options selected value should be set to what it says in the DB... Right now everything is echoing out correctly but all the selected for the option are not being unique, They are staying the same as the one before it. So If I set one to disabled, The selector shows them all as disabled.. Here is the code
<?php
$userID = $_GET['uid']; // from the query string in the link
$_SESSION['userid'] = $userID;
$query = $con->prepare("SELECT * FROM users WHERE ID = '". $userID ."'") or die(mysqli_error());
$query->execute();
$user=$query->fetch(PDO::FETCH_ASSOC);
// echo out user details:
echo '<b>' . 'User Info:' . " " . '</b>';
echo '<br>';
echo $user['last']. "," . " " .$user['first'];
echo '<br>';
echo 'Business Unit';
echo '<br>';
echo $user['busunit'];
echo '<br>';
echo 'Location';
echo '<br>';
echo $user['location'];
echo '<br>';
echo 'Position';
echo '<br>';
echo $user['position'];
echo '<br>';
echo '<br>';
echo '<b>Access Info</b>';
echo '<br>';
$number = '1';
$number++;
$new = 'op' . $number;
$stmt = $con->prepare("SELECT * FROM access");
$stmt->execute();
$userIDi = $user['ident'];
$q = $con->prepare("SELECT * FROM priv WHERE ident = :ID ");
$q->bindparam(":ID", $userIDi);
$q->execute();
$priv=$q->fetch(PDO::FETCH_ASSOC);
$val1 = 'Yes';
$val2 = 'No';
echo '<form method="post">';
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
echo $row['name'];
echo ' ';
echo '
<select id='.$new.'>
<option value="Yes"';
if($priv[$new]==$val1){echo 'selected="selected"';} echo '>Enabled </option>';
echo '<option value="No"';
if($priv[$new]==$val2){echo 'selected="selected"'; } echo '>Disabled </option>';
echo '</select>';
echo '<br>';
}
echo '<br>';
echo '<input type="submit" name="submit"/>';
echo '</form>';
Updated code to this,
Still cannot get it to work.
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
echo $row['name'];
echo ' ';
echo '
<select id='.$new.'>';
while($priv=$q->fetch(PDO::FETCH_ASSOC)){
echo '<option value="Yes"'; if($priv[$new]==$val1){echo 'selected="selected"' . '>Enabled </option>';}
echo '<option value="No"'; if($priv[$new]==$val2){echo 'selected="selected"' . '>Disabled </option>'; }
}
echo '</select>';
echo '<br>';
}
Here is the third update..
Now the first selector is working dynamiclly, It will changed to enabled or disabled but the other ones just stay static.
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
echo $row['name'];
echo ' ';
echo '
<select id='.$new.'>
<option value="Yes"';
while($priv=$q->fetch(PDO::FETCH_ASSOC)){
if($priv[$new]==$val1){echo 'selected="selected"';} echo '>Enabled </option>';
echo '<option value="No"';
if($priv[$new]==$val2){echo 'selected="selected"'; }} echo '>Disabled </option>';
echo '</select>';
echo '<br>';
}
echo '<br>';
echo '<input type="submit" name="submit"/>';
echo '</form>';
I can't find where is the problem at my code. It only send single orders to the database. When I order in my cart 2 or more than items, it only sends the last order. I don't have any idea how I can change or add some syntax in my code.
Here is my code in checkout.php
<?php
session_start();
echo '<h3>Your Order</h3>';
$current_url = base64_encode($url='http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
if(isset($_SESSION['products'])){
echo '<ol>';
echo '<form action="checkout_with_us.php" method="POST">';
$total = 0;
$cart_items = 0;
foreach($_SESSION['products'] as $cart_itm){
$product_code = $cart_itm['code'];
$results = $mysqli->query("SELECT product_name,product_desc,price FROM products WHERE product_code='$product_code' LIMIT 1");
$obj = $results->fetch_object();
echo '<li>';
echo 'Price: '.$currency.$obj->price;
echo '<h4>'.$obj->product_name.'(Code: '.$product_code.')</h4>';
echo 'Qty: '.$cart_itm['qty'];
echo '</li>';
$subtotal = ($cart_itm['price'] * $cart_itm['qty']);
$total = ($total + $subtotal);
$cart_items++;
echo '<input type="hidden" name="item_name" value="'.$obj->product_name.'">';
echo '<input type="hidden" name="item_desc" value="'.$obj->product_desc.'">';
echo '<input type="hidden" name="item_qty" value="'.$cart_itm["qty"].'">';
echo '<input type="hidden" name="item_code" value="'.$product_code.'">';
}
echo '<strong>Sub Total: '.$currency.$total.'</strong>';
echo '<input type="hidden" name="price" value="'.$total.'">';
echo '</ol>';
}
//Here is the information of the customer
echo 'Firstname: <input type="text" name="firstname"><br />';
echo 'Lastname: <input type="text" name="lastname"><br />';
echo 'Email: <input type="text" name="email"><br />';
echo '<input type="submit" value="Send Step">';
echo '</form>';
?>
And here is my checkout.with_us.php codes. This code is the bridge to send the information to the database.
<?php
session_start();
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$order_name = $_POST['item_name'];
$order_code = $_POST['item_code'];
$order_qty = $_POST['item_qty'];
$sub_total = $_POST['price'];
$conn = mysqli_connect('localhost','root','','sampsix')or die('Could not connect');
$query = "INSERT INTO `sampsix`.`orders`(`firstname`,`lastname`,`email`,`OrderName`,`OrderCode`,`OrderQty`,`SubTotal`) VALUES('$firstname','$lastname','$email','$order_name','$order_code','$order_qty','$sub_total')";
mysqli_query($conn,$query);
mysqli_close($conn);
header('Location: checkout.php');
?>
Delete your other question, ok?
The problem is you loop through $_SESSION and use the same name value each time. You need to create an array of your inputs. Here is an example:
<?php
echo '<h3>Your Order</h3>';
$current_url = base64_encode($url='http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
if(isset($_SESSION['products'])){
echo '<ol>';
echo '<form action="checkout_with_us.php" method="POST">';
$total = 0;
$cart_items = 0;
foreach($_SESSION['products'] as $cart_itm){
$product_code = $cart_itm['code'];
$results = $mysqli->query("SELECT product_name,product_desc,price FROM products WHERE product_code='$product_code' LIMIT 1");
$obj = $results->fetch_object();
echo '<li>';
echo 'Price: '.$currency.$obj->price;
echo '<h4>'.$obj->product_name.'(Code: '.$product_code.')</h4>';
echo 'Qty: '.$cart_itm['qty'];
echo '</li>';
$subtotal = ($cart_itm['price'] * $cart_itm['qty']);
$total = ($total + $subtotal);
$cart_items++;
echo '<input type="hidden" name="product['.$product_code.'][item_name]" value="'.$obj->product_name.'">';
echo '<input type="hidden" name="product['.$product_code.'][item_desc]" value="'.$obj->product_desc.'">';
echo '<input type="hidden" name="product['.$product_code.'][item_qty]" value="'.$cart_itm["qty"].'">';
echo '<input type="hidden" name="product['.$product_code.'][item_code]" value="'.$product_code.'">';
}
echo '<strong>Sub Total: '.$currency.$total.'</strong>';
echo '<input type="hidden" name="product['.$product_code.'][price]" value="'.$total.'">';
echo '</ol>';
}
//Here is the information of the customer
echo 'Firstname: <input type="text" name="firstname"><br />';
echo 'Lastname: <input type="text" name="lastname"><br />';
echo 'Email: <input type="text" name="email"><br />';
echo '<input type="submit" value="Send Step">';
echo '</form>';
?>
You can catch this by looping in your product array:
<?php
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$conn = mysqli_connect('localhost','root','','sampsix')or die('Could not connect');
foreach($_POST['product'] as $product)
{
$order_name = $product['item_name'];
$order_code = $product['item_code'];
$order_qty = $product['item_qty'];
$sub_total = $product['price'];
$query = "INSERT INTO `sampsix`.`orders`(`firstname`,`lastname`,`email`,`OrderName`,`OrderCode`,`OrderQty`,`SubTotal`) VALUES('$firstname','$lastname','$email','$order_name','$order_code','$order_qty','$sub_total')";
mysqli_query($conn,$query);
}
mysqli_close($conn);
header('Location: checkout.php');
?>
I don't know what the purpose is of the table orders but with my example the products will be added to this table with the same firstname, lastname, etc.
I've been looking through many threads on here without finding a solution to my problem.
I've created a form that is supposed to show content of a database in input boxes, and when i change the content, it should be updated in the database.
No errors, nothing gets changed.
<?php
$con=mysqli_connect("localhost","root","","frontpage");
// Check connection
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM frontpage_left_links")
or die("Error: ".mysqli_error($con));
while($row = mysqli_fetch_array($result)){
echo '<form action="" method="post">';
echo '<div style="float:left">';
echo '<table border="1" bordercolor="#000000">';
echo '<tr>';
echo '<td>link</td>';
echo '<td><input type="text" name="linkid" value="'.$row['link'].'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td>img</td>';
echo '<td><input type="text" name="imgid" value="'.$row['img'].'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td>tekst</td>';
echo '<td><input type="text" name="imgid" value="'.$row['name'].'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="submit" id="update" name="gem" value="Gem"</td></td>';
echo '<td><input type="hidden" name="id" value="'.$row['id'].'"></td>';
echo '</tr>';
echo '</table></div>';
echo '<div style="float:left"><center><img src="img/'.$row['img'].'"><br />'.$row['name'].'</center></div>';
echo '</form><br /><br /><br /><br /><br /><br /><br /><br />';
}
if(isset($_POST['update'])){
$id = $_POST['id'];
$link = $_POST['linkid'];
$img = $_POST['imgid'];
$name = $_POST['nameid'];
$sql = mysqli_query("UPDATE frontpage_left_links SET link = '$link', img = '$img', name = '$name' WHERE id = '$id'");
$retval = mysqli_query( $sql, $con );
if(! $retval ){
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
}
mysqli_close($con);
?>
The form show the database content fine, but nothing happens when changed.
I appreciate any help I can get.
This is what it looks like now.
<?php
$con=mysqli_connect("localhost","root","","frontpage");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if(isset($_POST['gem']))
{
$id = $_POST['id'];
$link = $_POST['linkid'];
$img = $_POST['imgid'];
$name = $_POST['nameid'];
$sql = mysqli_query("UPDATE frontpage_left_links SET link = '$link', img = '$img', name = '$name' WHERE id = '$id'");
$retval = mysqli_query( $con, $sql );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
}
$result = mysqli_query($con,"SELECT * FROM frontpage_left_links")
or die("Error: ".mysqli_error($con));
while($row = mysqli_fetch_array($result))
{
echo '<form action="" method="post">';
echo '<div style="float:left">';
echo '<table border="1" bordercolor="#000000">';
echo '<tr>';
echo '<td>link</td>';
echo '<td><input type="text" name="linkid" value="'.$row['link'].'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td>img</td>';
echo '<td><input type="text" name="imgid" value="'.$row['img'].'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td>tekst</td>';
echo '<td><input type="text" name="nameid" value="'.$row['name'].'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="submit" id="update" name="gem" value="Gem"</td></td>';
echo '<td><input type="hidden" name="id" value="'.$row['id'].'"></td>';
echo '</tr>';
echo '</table></div>';
echo '<div style="float:left"><center><img src="img/'.$row['img'].'"><br />'.$row['name'].'</center></div>';
echo '</form><br /><br /><br /><br /><br /><br /><br /><br />';
}
mysqli_close($con);
?>
Now i get this error.
Warning: mysqli_query() expects at least 2 parameters, 1 given in /Applications/XAMPP/xamppfiles/htdocs/page/admin.php on line 17
Warning: mysqli_query(): Empty query in /Applications/XAMPP/xamppfiles/htdocs/page/admin.php on line 19
Could not update data:
Because your udate is at the end of the page put it above the rest.
And also change isset($_POST['update'] to isset($_POST['gem']
<?php
$con=mysqli_connect("localhost","root","","frontpage");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if(isset($_POST['gem']))
{
$id = $_POST['id'];
$link = $_POST['linkid'];
$img = $_POST['imgid'];
$name = $_POST['nameid'];
$sql = "UPDATE frontpage_left_links SET link = '$link', img = '$img', name = '$name' WHERE id = '$id'";
$retval = mysqli_query($con,$sql );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
}
$result = mysqli_query($con,"SELECT * FROM frontpage_left_links")
or die("Error: ".mysqli_error($con));
while($row = mysqli_fetch_array($result))
{
echo '<form action="" method="post">';
echo '<div style="float:left">';
echo '<table border="1" bordercolor="#000000">';
echo '<tr>';
echo '<td>link</td>';
echo '<td><input type="text" name="linkid" value="'.$row['link'].'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td>img</td>';
echo '<td><input type="text" name="imgid" value="'.$row['img'].'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td>tekst</td>';
echo '<td><input type="text" name="imgid" value="'.$row['name'].'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="submit" id="update" name="gem" value="Gem"</td></td>';
echo '<td><input type="hidden" name="id" value="'.$row['id'].'"></td>';
echo '</tr>';
echo '</table></div>';
echo '<div style="float:left"><center><img src="img/'.$row['img'].'"><br />'.$row['name'].'</center></div>';
echo '</form><br /><br /><br /><br /><br /><br /><br /><br />';
}
mysqli_close($con);
?>
try to replace :
echo '<td><input type="submit" id="update" name="gem" value="Gem"</td></td>';
with :
echo '<td><input type="submit" id="update" name="update" value="Gem"</td></td>';
In your form you are having update button name as gem but you are using if(isset($_POST['update'])) to run update query.
Change it to if(isset($_POST['gem']))
The easiest way would be to simply change the name attribute on your submit to the $_POST[] variable you used. name="update"The easiest way would be to simply change the name attribute on your submit to the $_POST[] variable you used. name="update"
Edit :: Answered already.
echo '<td><input type="submit" id="update" name="update" value="Gem"</td></td>';
Just delete the second td from above!!!
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'];
....
Hello I have a problem with a session. When I use a session to pass a variable to another page the values of that variable always still the same in the other page. No matter what row I selected. When I change the "action" to the same page where the variable is, the value shows correct. Sorry for my bad English if someone speak Spanish let my know to explain better. I really need help in this.
Here is my code:
<?php
include_once 'rnheader.php';
session_start();
$ticket_select = $_POST['serviceID'];
echo ' Create Service ';
echo '<table border="1" >';
echo '<tr>';
echo '<th>Service ID</th>';
echo '<th>Title</th>';
echo '<th>Description</th>';
echo '<th>Notes</th>';
echo '<th>Submit By</th>';
echo '<th>Assigned Employee</th>';
echo '<th>Assigned Group</th>';
echo '<th>Category</th>';
echo '<th>Status</th>';
echo '<th>Urgency</th>';
echo '<th>Customer</th>';
echo '<th>Day Created</th>';
echo '</tr>';
$query = ("SELECT ServiceID, Title, Description, Notes, SubmitBy, AssignedEmp, " .
"AssignedGroup, NameCategory, TipoStatus, TiposUrgencia, CustomerName, DayCreation FROM Service");
$result = queryMysql($query);
while ($row = mysql_fetch_assoc($result)) {
echo '<tr>';
echo '<td><form method ="post" action="rnservices1.php">';
?>
<input type="submit" name="serviceID" value=<?php echo $row['ServiceID']?>
<?php
echo '</form>';
echo '<td>'.$row['Title'].'</td>';
echo '<td>'.$row['Description'].'</td>';
echo '<td>'.$row['Notes'].'</td>';
echo '<td>'.$row['SubmitBy'].'</td>';
echo '<td>'.$row['AssignedEmp'].'</td>';
echo '<td>'.$row['AssignedGroup'].'</td>';
echo '<td>'.$row['NameCategory'].'</td>';
echo '<td>'.$row['TipoStatus'].'</td>';
echo '<td>'.$row['TiposUrgencia'].'</td>';
echo '<td>'.$row['CustomerName'].'</td>';
echo '<td>'.$row['DayCreation'].'</td>';
echo '</tr>';
}
mysqli_free_result($result);
echo $ticket_select;
$_SESSION['serviceID'] = $ticket_select;
'</table>';
?>
Is it a case issue?
$_SESSION['serviceID'] = $ticket_select;
<input type="submit" name="serviceID" value=<?php echo $row['ServiceID']?>
$ticket_select = $_POST['serviceID'];
Notice the middle one has a capital S on ServiceID and the other two are serviceID.