i want to use session variable in the code. my requirement is that when i click on "edit/Delete" button,record against the correspondence row is deleted automatically. can any one plz help me how to resolve this problem and also tell me how to use session variable.
`<?php
while($row = $result->fetch_array())
print("
<tr>
<td> $row[0] </td>
<td> $row[1] </td>
<td> $row[2] </td>
<td> $row[3] </td>
<td> $row[4] </td>
<td> <a href='dscm-Emp-Modification.php?ID= $row[0]'>Edit</a></td>
<td> <a href='dscm-Emp-Delete.php?DID= $row[0]'>Delete</a></td>
</tr>
");
?>`
i tried following codes but neither of them worked for me:
//method 1
while($row = $result->fetch_array())
$_SESSION['a']=$row[0];
$_SESSION['b']=$row[1];
$_SESSION['c']=$row[2];
$_SESSION['d']=$row[3];
$_SESSION['e']=$row[4];
print("
<tr>
<td> $_SESSION[a] </td>
<td> $_SESSION[b] </td>
<td> $_SESSION[c] </td>
<td> $_SESSION[d]</td>
<td> $_SESSION[e]</td>
<td> <a href='dscm-Emp-Modification.php?ID= $row[0]'>Edit</a></td>
<td> <a href='dscm-Emp-Delete.php?DID= $row[0]'>Delete</a></td>
</tr>
");
//method 2
{
for ($a=0; $a<=4; $a++){
$_SESSION['data']=$row;
print("
<tr>
<td> $_SESSION[data] </td>
<td> $_SESSION[data] </td>
<td> $_SESSION[data] </td>
<td> $_SESSION[data] </td>
<td> $_SESSION[data] </td>
<td> <a href='dscm-Emp-Modification.php?ID= $row[0]'>Edit</a></td>
<td> <a href='dscm-Emp-Delete.php?DID= $row[0]'>Delete</a></td>
</tr>
");
}
}
You need to call the session_start() function befor use the $_SESSION-Array.
Please read more about sessions in the PHP documentation here.
Related
I am new to Laravel and currently working on a project where the guests enter form data for booking a room in a hotel and after submitting it, they will be redirected to a page showing their booking they have just done. I know this can be done by allowing guests to create login account but my project requires login only for the backend(admin). (Q2.)Also the guests can view booking by entering the booking ID and their last name.
My controller:
public function store(Request $request)
{
$book = new book();
$book->title = $request->input('title');
$book->fname = $request->input('firstname');
$book->lname = $request->input('lastname');
$book->country = $request->input('country');
$book->phone = $request->input('phone');
$book->email = $request->input('email');
$book->no_rooms = $request->input('no_rooms');
$book->room_type_id = $request->input('type_room');
$book->no_adults = $request->input('adults');
$book->no_children = $request->input('children');
$book->meal_id = $request->input('meal');
$book->check_in = $request->input('check_in');
$book->check_out = $request->input('check_out');
$book->save();
}
public function show(book $book)
{
return view('book.show', compact('book'));
}
The way I want it to display after it has been submitted:
<div class="row">
<div class="col-6">
<table class="table table-striped text-dark">
<tbody>
<tr>
<td> Name: </td>
<td> {{$book->title}} {{$book->firstname}} {{$book->lastname}} </td>
</tr>
<tr>
<td> Phone </td>
<td> {{$book->phone}} </td>
</tr>
<tr>
<td> Email </td>
<td> {{$book->email}} </td>
</tr>
<tr>
<td> Phone </td>
<td> {{$book->phone}} </td>
</tr>
<tr>
<td> Passport Issued: </td>
<td> {{$book->country}} </td>
</tr>
<tr>
<td> Number of rooms: </td>
<td> {{$book->no_rooms}} </td>
</tr>
<tr>
<td> Room Type </td>
<td> {{$book->type_room}} </td>
</tr>
<tr>
<td> No of adults: </td>
<td> {{$book->adults}} </td>
</tr><tr>
<td> No of children: </td>
<td> {{$book->children}} </td>
</tr>
<tr>
<td> Meal plan: </td>
<td> {{$book->meals_id}} </td>
</tr>
<tr>
<td> Check-in: </td>
<td> {{$book->check_in}} </td>
</tr>
<tr>
<td> Check-out: </td>
<td> {{$book->check_out}} </td>
</tr>
</tbody>
</table>
</div>
</div>
You can redirect to the show method from the bottom of your store method:
// Replace MyController with the name of your controller
return redirect()->action(
'MyController#show', ['book' => $book]
);
For more information check out the documentation: https://laravel.com/docs/master/redirects#redirecting-controller-actions
If I understand correctly your situation, you wish to show the same data introduced by the user after form submission.
I can think that redirecting to a page that show your div without anything else, is not enough. You'll still need to access to data entered in the form.
Laravel store form data in a session variable called old, according to documentation, that variable should be available during next request after submission, so you could try to get data using
<table class="table table-striped text-dark">
<tbody>
<tr>
<td> Name: </td>
<td> {{ old('title') }} {{ old('firstname') }} {{ old('lastname') }} </td>
</tr>
<tr>
<td> Phone </td>
<td> {{ old('phone') }} </td>
</tr>
<tr>
<td> Email </td>
<td> {{ old('email') }} </td>
</tr>
<tr>
<td> Phone </td>
<td> {{ old('phone') }} </td>
</tr>
<tr>
<td> Passport Issued: </td>
<td> {{ old('country') }} </td>
</tr>
<tr>
<td> Number of rooms: </td>
<td> {{ old('no_rooms') }} </td>
</tr>
<tr>
<td> Room Type </td>
<td> {{ old('type_room') }} </td>
</tr>
<tr>
<td> No of adults: </td>
<td> {{ old('adults') }} </td>
</tr><tr>
<td> No of children: </td>
<td> {{ old('children') }} </td>
</tr>
<tr>
<td> Meal plan: </td>
<td> {{ old('meals_id') }} </td>
</tr>
<tr>
<td> Check-in: </td>
<td> {{ old('check_in') }} </td>
</tr>
<tr>
<td> Check-out: </td>
<td> {{ old('check_out') }} </td>
</tr>
</tbody>
</table>
Just in case that you don't have old data available in your session because a successive redirect, you should inject that data in your session using flash.
You can find more detailed information here, in laravel documentation
You can just use the laravel helper redirect()
return redirect()->route('route name here');
or
return redirect('your-form-path');
read more here: laravel http redirects
Well, let's say I have variable a, b and c:
a = R R R
b = S S S
c = T T T
number = 1 to 3;
In my case I need to display the 27 row of total (var * var * var), but the result need to be like this and generate random number between 1 to 3:
<table>
<tr>
<td> R </td>
<td> R </td>
<td> R </td>
<td> number </td>
</tr>
<tr>
<td> R </td>
<td> R </td>
<td> S </td>
<td> number </td>
</tr>
<tr>
<td> R </td>
<td> S </td>
<td> T </td>
<td> number </td>
</tr>
<tr>
<td> S </td>
<td> S </td>
<td> R </td>
<td> number </td>
</tr>
<tr>
<td> S </td>
<td> T </td>
<td> S </td>
<td> number </td>
</tr>
<tr>
<td> S </td>
<td> T </td>
<td> T </td>
<td> number </td>
</tr>
<tr>
<td> T </td>
<td> R </td>
<td> R </td>
<td> number </td>
</tr>
<tr>
<td> T </td>
<td> R </td>
<td> S </td>
<td> number </td>
</tr>
<tr>
<td> T </td>
<td> S </td>
<td> T </td>
<td> number </td>
</tr>
<tr>
<td> R </td>
<td> S </td>
<td> R </td>
<td> number </td>
</tr>
<tr>
<td> R </td>
<td> T </td>
<td> S </td>
<td> number </td>
</tr>
<tr>
<td> R </td>
<td> T </td>
<td> T </td>
<td> number </td>
</tr>
<tr>
<td> S </td>
<td> R </td>
<td> R </td>
<td> number </td>
</tr>
<tr>
<td> S </td>
<td> R </td>
<td> S </td>
<td> number </td>
</tr>
<tr>
<td> S </td>
<td> S </td>
<td> T </td>
<td> number </td>
</tr>
<tr>
<td> T </td>
<td> S </td>
<td> R </td>
<td> number </td>
</tr>
<tr>
<td> T </td>
<td> T </td>
<td> S </td>
<td> number </td>
</tr>
<tr>
<td> T </td>
<td> T </td>
<td> T </td>
<td> number </td>
</tr>
<tr>
<td> R </td>
<td> R </td>
<td> R </td>
<td> number </td>
</tr>
<tr>
<td> R </td>
<td> R </td>
<td> S </td>
<td> number </td>
</tr>
<tr>
<td> R </td>
<td> S </td>
<td> T </td>
<td> number </td>
</tr>
<tr>
<td> S </td>
<td> S </td>
<td> R </td>
<td> number </td>
</tr>
<tr>
<td> S </td>
<td> T </td>
<td> S </td>
<td> number </td>
</tr>
<tr>
<td> S </td>
<td> T </td>
<td> T </td>
<td> number </td>
</tr>
<tr>
<td> T </td>
<td> R </td>
<td> R </td>
<td> number </td>
</tr>
<tr>
<td> T </td>
<td> R </td>
<td> S </td>
<td> number </td>
</tr>
<tr>
<td> T </td>
<td> S </td>
<td> T </td>
<td> number </td>
</tr>
</table>
How can I achieve this result in php?
Any help will be very much appreciated.
Thanks.
Here you go:
$a = ['R','R','R'];
$b = ['S','S','S'];
$c = ['T','T','T'];
$array = [$a, $b, $c];
<table>
for($i=0 ; i<27; i++) {
<tr>
<td> echo $array[rand(0,2)][rand(0,2)] ; </td>
<td> echo $array[rand(0,2)][rand(0,2)] ; </td>
<td> echo $array[rand(0,2)][rand(0,2)] ; </td>
<td> echo rand(0,2)</td>
</tr>
}
</table>
// !! you need to concat php with HTML !!
So, I was just trying some things, and I wanted to do a table, but when I try to run it, it gives me an error in this part of the code:
echo '
echo '
<table border = 1 width = 300px>
<tr>
<td> Name:
</td>
<td '.$Contacts[$Index]['Name']>
</td>
</tr>
<tr>
<td> Phone:
</td>
<td '.$Contacts[$Index]['Phone number']>
</td>
</tr>
<tr>
<td> Email:
</td>
<td '.$Contacts[$Index]['email']>
</td>
</tr>
';
Can someone please tell me if there is anything wrong I am not seeing?
Concatenation is not done properly.
<?php
echo '
<table border = 1 width = 300px>
<tr>
<td> Name:
</td>
<td>' . $Contacts[$Index]['Name'] .'
</td>
</tr>
<tr>
<td> Phone:
</td>
<td>' . $Contacts[$Index]['Phone number'] . '
</td>
</tr>
<tr>
<td> Email:
</td>
<td>'. $Contacts[$Index]['email'] . '
</td>
</tr>
';
There is an error in your concatenation. I would prefer you close your php tags, output simple html and use php to echo variables when required. It will keep the code clean. Here is an example
?>
<table border = 1 width = 300px>
<tr>
<td> Name:</td>
<td> <?php echo $Contacts[$Index]['Name']; ?> </td>
</tr>
<tr>
<td> Phone:</td>
<td><?php echo $Contacts[$Index]['Phone number']; ?></td>
</tr>
<tr>
<td> Email:</td>
<td> <?php echo $Contacts[$Index]['email'];?></td>
</tr>
<?php
There is another error that you are add values as <td value></td> while the correct way is <td>value<td>
I have resolved that issue.
I need to count how many of these items are open, and there are four types of them: Easy, Medium, Difficult and Not-Wanted. All of these types are values inside the div's. I need to exclude the 'Not-Wanted' types from the count. Notice the 'Open' and 'Close' values have different number of spaces around them. This is the html structure:
<table>
<tbody>
<tr>
<td>
<div>Difficult</div>
</td>
<td>Name</td>
<td> Open </td>
</tr>
<tr>
<td>
<div>Easy</div>
</td>
<td>Name</td>
<td> Closed </td>
</tr>
<tr>
<td>
<div>Easy</div>
</td>
<td>Name</td>
<td> Open </td>
</tr>
<tr>
<td>
<div>Medium</div>
</td>
<td>Name</td>
<td>Open </td>
</tr>
<tr>
<td>
<div>Easy</div>
</td>
<td>Name</td>
<td> Open </td>
</tr>
<tr>
<td>
<div>Medium</div>
</td>
<td>Name</td>
<td> Closed</td>
</tr>
<tr>
<td>
<div>Easy</div>
</td>
<td>Name</td>
<td>Closed </td>
</tr>
<tr>
<td>
<div>Not-wanted</div>
</td>
<td>Name</td>
<td> Open </td>
</tr>
<tr>
<td>
<div>Difficult</div>
</td>
<td>Name</td>
<td>Open</td>
</tr>
............
This is one of my attempts to solve the problem. It is obviously wrong, but I don't know how to get it right.
$doc = new DOMDocument();
$doc->loadHtmlFile('http://www.nameofsite.com');
$doc->preserveWhiteSpace = false;
$xpath = new DOMXPath($doc);
$elements = $xpath->query("/html/body/div[1]/div/section/div/section/article/div/div[1]/div/div/div[2]/div[1]/div[2]/div/section/div/div/table/tbody/tr");
$count = 0;
foreach ($elements as $element) {
if ($element->childNodes->nodeValue != 'Not-wanted') {
if ($element->childNodes->nodeValue === 'open') {
$count++;
}
}
}
echo $count;
I have a very rudimental knowledge of DOMXPath, so it is too complex for me, since I'm only able to create simple queries.
Can anybody help?
Thanks in advance.
Based on the data in your example, I think you can adjust the xpath expression to this to get all the <tr>'s that match your conditions:
//table/tbody/tr[normalize-space(td[3]/text()) = 'Open' and
td[1]/div/text() != 'Not-wanted']
$elements is then of type DOMNodeList and you can then get the length property to get the number of nodes in the list.
For example:
$source = <<<SOURCE
<table>
<tbody>
<tr>
<td>
<div>Difficult</div>
</td>
<td>Name</td>
<td> Open </td>
</tr>
<tr>
<td>
<div>Easy</div>
</td>
<td>Name</td>
<td> Closed </td>
</tr>
<tr>
<td>
<div>Easy</div>
</td>
<td>Name</td>
<td> Open </td>
</tr>
<tr>
<td>
<div>Medium</div>
</td>
<td>Name</td>
<td>Open </td>
</tr>
<tr>
<td>
<div>Easy</div>
</td>
<td>Name</td>
<td> Open </td>
</tr>
<tr>
<td>
<div>Medium</div>
</td>
<td>Name</td>
<td> Closed</td>
</tr>
<tr>
<td>
<div>Easy</div>
</td>
<td>Name</td>
<td>Closed </td>
</tr>
<tr>
<td>
<div>Not-wanted</div>
</td>
<td>Name</td>
<td> Open </td>
</tr>
<tr>
<td>
<div>Difficult</div>
</td>
<td>Name</td>
<td>Open</td>
</tr>
</tbody>
</table>
SOURCE;
$doc = new DOMDocument();
$doc->loadHTML($source);
$doc->preserveWhiteSpace = false;
$xpath = new DOMXPath($doc);
$elements = $xpath->query("//table/tbody/tr[normalize-space(td[3]/text()) = 'Open' and td[1]/div/text() != 'Not-wanted']");
echo $elements->length;
Which will result in:
5
Demo
I get that error in php..And I have no idea why...
Here is how my connection is established:
<?php
$hostname_QASite = "localhost";
$database_QASite = "qasite";
$username_QASite = "root";
$password_QASite = "";
$QASite = mysql_pconnect($hostname_QASite, $username_QASite, $password_QASite) or trigger_error(mysql_error(),E_USER_ERROR);
?>
my query is the following:
mysql_select_db($database_QASite, $QASite) or die(mysql_error());
$query_get_all_topics = "SELECT topic_id, title FROM topic";
$get_all_topics = mysql_query($query_get_all_topics, $QASite) or die(mysql_error());
$row_get_all_topics = mysql_fetch_assoc($get_all_topics);
$totalRows_get_all_topics = mysql_num_rows($get_all_topics);
And then I iterate over the row_get_all_topics ...
What is wrong in the code ?
Edit:
I get that error, when I try to loop 2 times over different results in the database.
UPDATE:
<body>
<br/><br/><br/><br/><br/><br/><br/>
<div align="center">
<ul id="navlist">
<li> צור נושא</li>
<li> ראה קשרים</li>
</ul>
<?php do { ?>
<table border="1">
<tr>
<td>
<table width="100%" border="1" >
<tr>
<td width="90%" align="right">
<?php echo $row_get_all_topics['title']; ?>
</td>
<td width="10%">
:שם נושא
</td>
</tr>
<tr>
<td colspan="2">
<table>
<tr>
<td>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<?php
//$result=$mysql_query("SELECT title, sub_topic_id FROM sub_topic WHERE topic_id=".$row_get_all_topics['topic_id']) or die(mysql_error());
$result="";
if($row=mysql_fetch_array($result))
{
do
{
?>
<table >
<tr>
<td>
<?php echo $row['title']; ?>
</td>
<td>
:תת נושא
</td>
</tr>
<tr>
<td colspan="2">
<table>
<tr>
<td>
</td>
</tr>
<tr>
<td>
עדכן
</td>
<td>
מחק
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td></td>
</tr>
</table>
</td>
</tr>
</table>
<?php
**}while($row=mysql_fetch_assoc($result));** 1 FIRST LOOP
}//end suptopic search
?>
<?php **} while ($row_get_all_topics = mysql_fetch_assoc($get_all_topics)); ?>** 2ND LOOP
AS soon as I add this line, to query teh database inside the loop, the page shows the error..
$result=$mysql_query("SELECT title, sub_topic_id FROM sub_topic WHERE topic_id=".$row_get_all_topics['topic_id']) or die(mysql_error());