PHP and Session error - php

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.

Related

i need to break the line after a reach of 10 buttons

I need to break the line after a reach of 10 buttons.
Please be specific what are the code to be used for breaking the line.
Here is the code:
<?php
session_start();
require('connection.php');
$result = mysql_query("SELECT * FROM tbCandidates ");
if($result){
}
echo "select Project to Reward for";
$_SESSION['a']="project name-->";
echo "<body><form method='post' action='part1.php' ><input type='hidden' value='abhishek' name='aa'/>";
echo "<table><tr>";
while ($row=mysql_fetch_array($result)){
echo "<td>";
echo $row["project_id"];
echo '<input type="radio" name="n1" value="';echo $row["project_id"]; echo '">'; echo"</input>";
$_SESSION['b']=$row['candidate_name'];
$_SESSION['c']=$row['candidate_position'];
$_SESSION['c']=$row['candidate_nominee'];
echo "</td>";
}
echo "</tr></table><input type='submit'/></form></body>";
If you mean by BREAKING the line is creating another row for your table then try to use the following codes:
<?php
session_start();
require('connection.php');
$result = mysql_query("SELECT * FROM tbCandidates ");
if($result){
}
echo "select Project to Reward for";
$_SESSION['a']="project name-->";
echo "<body><form method='post' action='part1.php' ><input type='hidden' value='abhishek' name='aa'/>";
echo "<table>";
$counter = 0;
while ($row=mysql_fetch_array($result)){
$counter++;
if($counter==1){
echo "<tr>";
}
echo "<td>";
echo $row["project_id"];
echo '<input type="radio" name="n1" value="';echo $row["project_id"]; echo '">'; echo"</input>";
$_SESSION['b']=$row['candidate_name'];
$_SESSION['c']=$row['candidate_position'];
$_SESSION['c']=$row['candidate_nominee'];
echo "</td>";
if($counter==10){
echo "</tr>";
$counter = 0;
}
}
echo "</table><input type='submit'/></form></body>";
Let me know if it works.

In PHP and MySQL, how to view multiple order information in the other page

I've learned a lot from this question, on how to send multiple order information on the database. In my table rows of "order.php" is composed of rows about order information sent by the customers. My code is only for single order only. But I want to view in the other page the multiple orders sent by one customer.
Here is my code for "order.php"
<?php
session_start();
$conn = mysqli_connect('localhost','root','','sampsix');
if(mysqli_connect_errno()){
echo 'Failed to connect: '.mysqli_connect_error();
}
if(isset($_POST['delete'])){
$DeleteQuery = "DELETE FROM orders WHERE id='$_POST[hidden]'";
mysqli_query($conn,$DeleteQuery);
}
if(isset($_POST['view'])){
header('Location: view_order.php');
}
$query = "SELECT * FROM orders ORDER BY id";
$results = mysqli_query($conn,$query);
echo '<table border="1">';
echo '<tr>';
echo '<th>ID</th>';
echo '<th>Firstame</th>';
echo '<th>Lastname</th>';
echo '<th>Email</th>';
echo '<th>Order Name</th>';
echo '<th>Order Code</th>';
echo '<th>Order Qty</th>';
echo '<th>Sub Total</th>';
echo '</tr>';
while($orderData = mysqli_fetch_array($results)){
echo '<form action="order.php" method="POST">';
echo '<tr>';
echo '<td>'.$orderData['id'].'</td>';
echo '<td>'.$orderData['firstname'].'</td>';
echo '<td>'.$orderData['lastname'].'</td>';
echo '<td>'.$orderData['email'].'</td>';
echo '<td>'.$orderData['ordername'].'</td>';
echo '<td>'.$orderData['ordercode'].'</td>';
echo '<td>'.$orderData['orderqty'].'</td>';
echo '<td>'.$orderData['subtotal'].'</td>';
echo '<td><input type="hidden" name="hidden" value="'.$orderData['id'].'"></td>';
echo '<td><input type="submit" name="delete" value="Delete"></td>';
echo '</form>';
echo "<td><a href='view_order.php?id=".$orderData['id']."'>View</a></td>";
echo '</tr>';
}
echo '</table>';
mysqli_close($conn);
?>
And here is my "view_order.php" where in the order information is in there:
<?php
include_once('config.php');
if(isset($_GET['id'])){
$id = $_GET['id'];
$query = $mysqli->query("SELECT id,firstname,lastname,email,ordername,ordercode,orderqty,subtotal FROM orders WHERE id='$id'");
if($query){
while($obj = $query->fetch_object()){
echo 'ID: '.$obj->id;
echo 'Firstname: '.$obj->firstname;
echo 'Lastname: '.$obj->lastname;
echo 'Email: '.$obj->email;
echo 'Order Name: '.$obj->ordername;
echo 'Order Code: '.$obj->ordercode;
echo 'Order Qty: '.$obj->orderqty;
echo 'Sub total: '.$obj->subtotal;
}
}
}
?>
This code above also execute single order only. I just thinking what if the customers has multiple order and I want to view it all in the other page.
Now you use the id as identifier which refers to just one order. If you want all orders of a customer you should select by the identificator of the customer. In your case i think it is firstname and lastname. You should replace the id with firstname and lastname. You will get something like this:
<?php
session_start();
$conn = mysqli_connect('localhost','root','','sampsix');
if(mysqli_connect_errno()){
echo 'Failed to connect: '.mysqli_connect_error();
}
if(isset($_POST['delete'])){
$DeleteQuery = "DELETE FROM orders WHERE id='$_POST[hidden]'";
mysqli_query($conn,$DeleteQuery);
}
if(isset($_POST['view'])){
header('Location: view_order.php');
}
$query = "SELECT * FROM orders ORDER BY id";
$results = mysqli_query($conn,$query);
echo '<table border="1">';
echo '<tr>';
echo '<th>ID</th>';
echo '<th>Firstame</th>';
echo '<th>Lastname</th>';
echo '<th>Email</th>';
echo '<th>Order Name</th>';
echo '<th>Order Code</th>';
echo '<th>Order Qty</th>';
echo '<th>Sub Total</th>';
echo '</tr>';
while($orderData = mysqli_fetch_array($results)){
echo '<form action="order.php" method="POST">';
echo '<tr>';
echo '<td>'.$orderData['id'].'</td>';
echo '<td>'.$orderData['firstname'].'</td>';
echo '<td>'.$orderData['lastname'].'</td>';
echo '<td>'.$orderData['email'].'</td>';
echo '<td>'.$orderData['ordername'].'</td>';
echo '<td>'.$orderData['ordercode'].'</td>';
echo '<td>'.$orderData['orderqty'].'</td>';
echo '<td>'.$orderData['subtotal'].'</td>';
echo '<td><input type="hidden" name="hidden" value="'.$orderData['id'].'"></td>';
echo '<td><input type="submit" name="delete" value="Delete"></td>';
echo '</form>';
echo "<td><a href='view_order.php?firstname=".$orderData['firstname']."&lastname=".$orderData['lastname']."'>View</a></td>";
echo '</tr>';
}
echo '</table>';
mysqli_close($conn);
?>
And the view page:
<?php
include_once('config.php');
if(isset($_GET['firstname'])){
$firstname = $_GET['firstname'];
if(isset($_GET['lastname'])){
$lastname = $_GET['lastname'];
$query = $mysqli->query("SELECT id,firstname,lastname,email,ordername,ordercode,orderqty,subtotal FROM orders WHERE firstname='$firstname' and lastname='$lastname'");
if($query){
while($obj = $query->fetch_object()){
echo 'ID: '.$obj->id;
echo 'Firstname: '.$obj->firstname;
echo 'Lastname: '.$obj->lastname;
echo 'Email: '.$obj->email;
echo 'Order Name: '.$obj->ordername;
echo 'Order Code: '.$obj->ordercode;
echo 'Order Qty: '.$obj->orderqty;
echo 'Sub total: '.$obj->subtotal;
}
}
}
?>
Note that this structure isn't the best solution. I would store my customers in another table, because what happens if two people have the same first- and lastname?
In your other question you also create a row for each product in your order table. If you want to do it well you should create another table like order_rules and store your products in that table with an order id. You should normalize your tables. I think this is a good description and tutorial about normalizing tables.
Please note this code is not safe to use - it contains a number of SQL injection vulnerabilities. It has just been amended into a working state from the code in the original post.

echo with attribute name for query purposes php pdo

<form method="POST" action="include/crud.php" enctype="multipart/form-data" >
<?php
foreach (LoadAnouncements() as $value){
/*echo "<div id='bb'></div>";*/
echo "<hr/>";
echo $value['searchresultwhat'];
echo "<br/>\n";
echo $value['searchresultwhen'];
echo "<br/>\n";
echo $value['searchresultwhere'];
echo "<hr/>";
/*echo "<div id='bb'></div>";*/
}
?>
</form>
I have this form that show an echo is there a way that I can add the attribute name in this echo so I can use it to query the database? I search for ideas if putting attribute to echo is possible but I haven't found anything yet any suggestion is appreciated
You are looking it?
<input type="text" name="searchresultwhat[]" value="<?php echo $value['searchresultwhat']; ?>" />
<input type="text" name="searchresultwhen[]" value="<?php echo $value['searchresultwhen']; ?>" />
<input type="text" name="searchresultwhere[]" value="<?php echo $value['searchresultwhere']; ?>" />
Edited
<?php
echo '<table>';
echo '<tr><th>What </th><th> When</th><th> Where</th><tr>';
foreach (LoadAnouncements() as $value){
echo "<tr><td>".$value['searchresultwhat']."</td>
<td>"$value['searchresultwhen']."</td>
<td>".$value['searchresultwhere']."</td>
</tr>";
}
echo '</table>';
?>
Do you want to add attribute to certain value in PHP? But you can't do it because $value['searchresultwhat'] and others of the kind are simple strings - as is! They can't send separated data (or attributes) with themself.
EDIT:
You can send seprated data about certain value using array:
$value['searchresultwhat'] = array("name", "value");
$value['searchresultwhen'] = array("name2", "2014-09-01");
$value['searchresultwhere'] = array("name3", "kittens");
echo $value['searchresultwhat'][0] . " is " . $value['searchresultwhat'][1];
echo $value['searchresultwhen'][0] . " = " . $value['searchresultwhen'][1];
echo $value['searchresultwhere'][0] . " has " . $value['searchresultwhere'][1];

Can not get PHP to post info to database

I've written a script to post information into my database for I can't get it to post and need help pointing out what I'm missing.
my php post for looks like this:
$query = "SELECT * from departments";
$res = mysql_query($query);
echo '<div id="department" >';
echo '<form action="depedit.php" method="post">';
echo '<input type="text" placeholder="Search departments">';
echo '<br>';
echo '</form>';
echo '</div>';
echo '<div id="depadd">';
echo '<form>';
echo '<table width="0" border="0">';
echo '<tr>';
echo '<td>Name:</td>';
echo '</tr>';
echo '<tr>';
echo '<td>';
echo "<select name='depid'>";
while ($row = mysql_fetch_array($res)) {
echo "<option value='".$row['id']."'>".$row['depname']."</option>";
}
echo "</select>";
echo '</td>';
echo ' </tr>';
echo '<tr>';
echo '<td> </td>';
echo '</tr>';
echo ' <tr>';
echo '<td><label class="limit">Select Limit for active courses in Learning Locker:</label></td>';
echo ' </tr>';
echo ' <tr>';
echo '<td>';
echo "<select name='courselimit'>";
echo "<option value='1'>1</option>";
echo "<option value='2'>2</option>";
echo "<option value='3'>3</option>";
echo "<option value='4'>4</option>";
echo "<option value='5'>5</option>";
echo "<option value='0'>Unlimited</option>";
echo "</select>";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td> </td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="radio" id="1" name="senabled" value="1"/><label for="c1" class="required">Required<br>(Study Shredder Feature Enabled)</br></label></td>';
echo '<td><input type="radio" id="0" name="senabled" value="0"/><label for="c1" class="optional">Optional</label></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="hidden" name="orgid" value="'.$adminorgid.'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="hidden" name="createdby" value="'.$userid.'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="hidden" name="timecreated" value="'.time(now).'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td> </td>';
echo '</tr>';
echo ' <tr>';
echo ' <td><button type="submit" class="btn">Submit</button></td>';
echo ' </tr>';
echo '</table>';
echo "</form>";
echo '</div>';
depedit.php looks like this:
$adddep = "INSERT INTO organization_dep (orgid,depid,courselimit,senabled,createdby,timecreated) VALUES ('".$_POST["orgid"].",".$_POST["depid"].",".$_POST["courselimit"].",".$_POST["senabled"].",".$_POST["createdby"].",".$_POST["timecreated"]."')";
$res = mysql_query($adddep);
if ($res === TRUE) {
echo "Department added successfully";
} else{
printf("Could not create department");
}
the correct information seems like its getting passed as the url displays the following information in it:
/index.php?depid=6&courselimit=3&senabled=1&orgid=9&createdby=1129&timecreated=1364005206
any help with this would be greatly appreciated as I'm sure its something simple that I'm just over looking.
You want to get the values from the $_POST
('".$_POST["orgid"].",".$_POST["depid"].",".$_POST["courselimit"].",".$_POST["senabled"].",".$_POST["createdby"].",".$_POST["timecreated"]."')";
but your saying it is passed through the URL, this looks like you need to use $_GET to get the values
--- and one small tip you can use echo to print multiple lines it works. as long as you close it, in the end
e.g
echo " <html>
<body>
</body>
</html>
";
I think you have a bunch of things to get right before this will be working:
Only the first form, which seems to be for searching departments, have method and action attributes
Since the second form does not have the action attribute, it is not submitting to depedit.php but to the same page that has the form.
Since the second form does not have the method attribute, it defaults to GET, and you are trying to read out POST variables in your PHP. If it was not using GET, you would not see those params in the resulting URL.
In your SQL insert statement, you must have single quotes around every single text value but not around int values. Now you have one single quote before the first value and one before the last which makes no sense.
First: this portion will not be POSTed "depedit.php" because there is no submit
echo '<form action="depedit.php" method="post">';
echo '<input type="text" placeholder="Search departments">';
echo '<br>';
echo '</form>';
Second: this will never be POSTed to depedit.php, since your <form> does not have an action specifying "depedit.php"
echo '<form>';
echo '<table width="0" border="0">';
echo '<tr>';
//other codes
echo "</form>";
maybe you mean to remove the first echo '</form>'(line 7) and the second <form>(line 10)

Dependent dropdown PHP

Hello I want to show a table that have all the values from a mysql table but depending on the values that I will select from a dropdown menu. For example the dropdown list menu have a value named open. I just want to see the rows from the table that have that status. I will need to use Ajax for this?
Here is my code?
$status = $_POST['TipoStatus'];
echo ' Create Service ';
echo '</br>';
echo '</tr><tr><td><label for="TipoStatus"> Status:</label></td><td>';
$query = "SELECT TipoStatus FROM status"; // First Remar
$result = queryMysql($query);
if (!queryMysql($query)) {
echo "Query fail: $query<br />" .
mysql_error() . "<br /><br />";
}
else
{
echo '<select name = "TipoStatus" size = "1">'; // or name="toinsert[]"
// echo '<option value="none" selected="selected">None</option>';
while ($row_1 = mysql_fetch_array($result)) {
echo '<option value="' . htmlspecialchars($row_1['TipoStatus']) . ' selected="$row_1[9]" >' // Third remark
. htmlspecialchars($row_1['TipoStatus'])
. '</option>';
}
echo '</select>';
echo '</p>';
}
echo '<table border="1" >';
echo '<tr>';
echo '</br>';
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 where TipoStatus = '$status' ");
$result = queryMysql($query);
echo 'resultado' . mysql_num_rows($result);
while ($row = mysql_fetch_assoc($result)) {
echo '<tr>';
echo '<td> '.$row['ServiceID'] .' </td>';
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;`enter code here`
echo '</table>';
echo '<form method = "post" action "rnseetickets.php">';
?>
Your code is a little meandering, and I can't quite tell if you're running this from the command line or as a web page, but it seems like you're wanting to filter a SQL result with a drop-down of options? That can be done with a simple form (if you don't mind a page refresh) or with AJAX (if you want it to filter without a page refresh):
// Run SQL
$sql = "SELECT TipoStatus FROM status";
if (!empty($_GET['status'])) {
$sql .= "WHERE `value`=\"".addslashes($_GET['status'])."\"";
}
$result = queryMysql($sql);
// Filter form
echo "<form action=\"".$_SERVER['PHP_SELF']."\" method="get">";
echo "<select name=\"status\"><option>open</option><option>other option</option></select>";
echo "<input type=\"submit\" value=\"Filter\">";
echo "</form>";
// Table
// As you already have it
Greetings. You can submit a forum on the onchange event of the dropdown box.
Check this link:
javascript onchange submit
You can find more examples by searching 'javascript onchange submit'
Now when the user selects something in the drop down box the form will submit and you can use your php code do filter the results.

Categories