Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am struggling with the syntax if someone can help me.
Condition1 = if the value of $ncha['p_no_contacts']-$ncha['r_cnt'] is 1 then add an extra echo in the h1 section saying that, "You are viewing last contact details and have exhausted your membership. Please renew your membership" If the above value is more than 1 then let that one echo statement be as it is.
next thing is to update the payments table or delete the row from payments table if $inc1 is equal to $ncha['p_no_contacts']
I need a correct syntax if someone can help.
EDIT:
This is what I tried but I get error Parse error: syntax error, unexpected '>' on line 51 which is the h1 line of else statement.
Thanks
<div class="modal-dialog yoyo-large">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×
</button>
if $ncha['p_no_contacts']-$ncha['r_cnt'] = 1
{
<h1 class="modal-title" id="myModalLabel" style="color:red;">Remaining Contacts (
<?php echo ($ncha['p_no_contacts']-$ncha['r_cnt']);?>)
</h1>
}
else
{
<h1 class="modal-title" id="myModalLabel" style="color:red;">Remaining Contacts (
<?php echo ($ncha['p_no_contacts']-$ncha['r_cnt']) <br> You are viewing last contact details and have exhausted your membership. Please renew your membership;?>)
</h1>
</div>
<div class="modal-body">
<div class="col-sm-12 form-group">
<div class="col-sm-6" style="font-size:13px;">
<table class="table table-hover table-striped">
<tr height="30">
<td width="80">
<strong>Matri ID :
</strong>
</td>
<td>
<?php echo $fet['matri_id']; ?>
</td>
</tr>
<tr height="30">
<td>
<strong>Name :
</strong>
</td>
<td>
<?php echo $fet['username']; ?>
</td>
</tr>
<tr height="30">
<td>
<strong>Address :
</strong>
</td>
<td>
<?php echo $fet['address']; ?>
</td>
</tr>
<tr height="30">
<td>
<strong>Phone :
</strong>
</td>
<td>
<?php echo $fet['phone']; ?>
</td>
</tr>
<tr height="30">
<td>
<strong>Mobile :
</strong>
</td>
<td>
<?php echo $fet['mobile']; ?>
</td>
</tr>
<tr height="30">
<td>
<strong>Email :
</strong>
</td>
<td>
<?php echo $fet['email']; ?>
</td>
</tr>
</table>
</div>
</div>
<?php
$chk1=$ncha['r_cnt'];
$inc1=$chk1+1;
If $inc1 = $ncha['p_no_contacts']
(
$dele="delete from payments where (pemail='$mid' or pmatri_id='$mid')";
$de=mysql_query($dele) or die(mysql_error());
}
else
{
$upda="update payments SET r_cnt='$inc1' where (pemail='$mid' or pmatri_id='$mid')";
$up=mysql_query($upda) or die(mysql_error());
}
$ex=mysql_query("select id from today_contact where who='$mid' and whose='$from_id'");
if(mysql_num_rows($ex)==0)
{
mysql_query("insert into today_contact (who,whose,on_date) values ('$mid','$from_id',now())");
}
else
{
mysql_query("update today_contact set on_date=now() where who='$mid' and whose='$from_id'");
}
?>
</div>
</div>
</div>
You are mixing HTML and PHP code together.
You also forgot parentheses around the condition on the first line of this code fragment.
Change:
if $ncha['p_no_contacts']-$ncha['r_cnt'] = 1
{
<h1 class="modal-title" id="myModalLabel" style="color:red;">Remaining Contacts (
<?php echo ($ncha['p_no_contacts']-$ncha['r_cnt']);?>)
</h1>
}
else
{
<h1 class="modal-title" id="myModalLabel" style="color:red;">Remaining Contacts (
to:
<?php
if ($ncha['p_no_contacts']-$ncha['r_cnt'] = 1)
{
?>
<h1 class="modal-title" id="myModalLabel" style="color:red;">Remaining Contacts (
<?php echo ($ncha['p_no_contacts']-$ncha['r_cnt']);?>)
</h1>
<?php
}
else
{
?>
<h1 class="modal-title" id="myModalLabel" style="color:red;">Remaining Contacts (
Other important things:
- mysql_* functions in PHP are all deprecated, and removed from the last version of PHP (PHP 7). You should use mysqli_* or PDO functions instead
- it seems you are using unescaped variables in your queries. This is very insecure and may cause your code to fail, or be the target of SQL injections. Read How can I prevent SQL-injection in PHP? for more information.
I got the answer. By mistake I added a parenthesis instead of brace bracket in the second line of the below code. Phew! It took me almost two days to figure this out. Thanks #Jocelyn for your kind assistance.
If $inc1 = $ncha['p_no_contacts']
(
$dele="delete from payments where (pemail='$mid' or pmatri_id='$mid')";
$de=mysql_query($dele) or die(mysql_error());
}
else
{
$upda="update payments SET r_cnt='$inc1' where (pemail='$mid' or pmatri_id='$mid')";
$up=mysql_query($upda) or die(mysql_error());
}
Related
I'm wondering if some more experienced PHP coders can help me resolve this issue:
I have a edit.php page which displays current client data to update in form fields.
the update button that when clicked at the moment is just going to a page clients.php (Showing all clients data including the updated client data)
My goal is when the update button is clicked instead of going to clients.php as a redirect and showing a table full of clients, i wish it to redirect to just the individual client info on the report.php page and have it echo the current updated client data in a table.
All i get is a syntax error below.
syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
Below is the redirect code on the edit.php page, then below that the reports.php page i want to redirect to but only echo current Client ID's data.
if($run_update){
header("Location: reports.php?cus_id=<?php echo $result['id'] ?>");
keepmsg('<div class="alert alert-success text-center">
×
<strong>Success!</strong> Client updated successfully.
</div>');
} else {
keepmsg('<div class="alert alert-danger text-center">
×
<strong>Sorry!</strong> Client could not be updated.
</div>');
}
Below is the simple reports.php page. This is were I'm trying to redirect to and display only the current clients data by ID
<div class="container">
<div class="jumbotron">
<div class="container">
<div class="row">
<div class="col-md-12">
<small class="pull-right"><a href="edit.php?cus_id=<?php echo $row['id'] ?>" class='btn btn-danger'>Edit Client</a> </small>
<h2 class="text-center invert"> Client Info: <span class="font-weight-light"><?php echo $row['deceased'] ?></span></h2>
<hr>
</div>
</div>
</div>
<br>
<div class="table-responsive table-wrapper">
<table class="table table-bordered table-hover text-center">
<thead>
<tr>
<th class="text-center">Job Type</th>
<th class="text-center">Name of Deceased</th>
<th class="text-center">Plot Number</th>
<th class="text-center">Cemetery</th>
</tr>
</thead>
<tbody class="invert_td">
<tr>
<td><?php echo $row['jobtype'] ?></td>
<td><?php echo $row['deceased'] ?></td>
<td><?php echo $row['plot'] ?></td>
<td><?php echo $row['cemetery'] ?></td>
</tr>
</tbody>
</table>
</div>
</div>
Below if the 1st line of code from my form on the edit.php page if that helps
<form class="form-horizontal" role="form" method="post" action="edit.php?cus_id=<?php echo $client_id ?>">
try header("Location: reports.php?cus_id=".$result['id']);
Hi Mohammed i have a function in my functions.php
Though I'm not sure if this is what you meant by passing in in the header?
function redirect($page){
header("Location: {$page}{$result} ['id']");
}
I created this function yet it still does not take me to the correct client info page
e.g http://localhost:9090/wmdb/admin/reports.php?cus_id=132
only to
http://localhost:9090/wmdb/admin/reports.php?cus_id=
im trying to a update a record by getting the id of the post via $_GET then update the records through $_POST.
i already have performed the delete action through $_GET it works fine also the mysqli_fetch_assoc works fine for displaying the record for editing but the actual editing does not happens it gives a Empty error from the validation in the code in the empty check function.
i have gone through lots research but cant seem to get my head around the error , i would thank full if any one could suggest any changes in the code.
Thank you in advance!
This is the error
Notice: Undefined index: id in /then the long url etc/
Below is the code
<?php
//DB Connection
include'include/db-conn.php';
if (isset($_POST['edit'])) {
//Raw GET Inputs
$raw_c_id = $_GET['id'];
//Cleaned Inputs
$c_c_id = filter_var($raw_c_id, FILTER_SANITIZE_STRING);
//Error Mwssages
$empty = '<div class="alert alert-danger alert-dismissible">
×
<strong>Error!</strong>Field is empty please provide content!
</div>
';
$success = '<div class="alert alert-success alert-dismissible fixed-top">
×
<strong>Success!</strong> Content Added Successfully
</div>
';
$not_success = '<div class="alert alert-danger alert-dismissible">
×
<strong>Not Success!</strong> Content Not Added Successfully
</div>
';
if (empty($c_c_id)) {
echo $empty;
exit();
header("Location:index.php");
}
$update = "UPDATE `continents`
SET `continent_name`='$c_c_name', `last_edited`='date(d/m/Y)'
WHERE `id`='$c_c_id'";
$run_update = mysqli_query($conn, $update);
if (!$run_update) {
header("Location: index.php");
echo $not_success;
}
else{
header("Location: index.php");
echo $success;
}
}
?>
This is the html part
<div class="panel-body">
<form action="edit.php" method="POST">
<div class="form-group">
<label for="continent_name">Continent Name</label>
<input required type="text" placeholder="10" class="form-control" value="<?php echo $c_name ; ?>" name="continent_name">
</div>
<small>Date Added: <?php echo $c_dated_added ; ?></small> / <small>Last Edited: <?php echo $c_last_edited ; ?></small>
<div class="form-group">
<input class="form-control btn-success" type="submit" name="edit" value="Submit">
</div>
</form>
</div>
Thid the while loop
<div class="table-responsive">
<table id="example" class="table table-hover ">
<thead>
<tr class="">
<th>ID</th>
<th>Continent Name</th>
<th>Date Added</th>
<th>Status</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
$all_continents = "SELECT * FROM `continents` ORDER BY `status`";
$run = mysqli_query($conn,$all_continents);
while ($row_result = mysqli_fetch_assoc($run)) {
$id = $row_result['id'];
$c_continent_name = $row_result['continent_name'];
$c_date_added = $row_result['date_added'];
$c_status = $row_result['status'];
echo "
<tr>
<td>$id</td>
<td>$c_continent_name</td>
<td>$c_date_added</td>
<td>$c_status</td>
<td>
<a class='btn btn-info' href='edit.php?id=$id'>Edit</a>
</td>
<td>
<a class='btn btn-danger' href='delete.php?id=$id'>Delete</a>
</td>
</tr>
";
}
?>
</tbody>
</table>
It looks like you're trying to use GET and POST parameters at the same time. The reason it's not working is because the GET parameter is lost when you submit your form. You need to pass it on in the form's action attribute:
<form action="edit.php?id=<?php echo $_GET['id'] ?>" method="POST">
Please also take a look at the advice in this post:
Is there a way to use GET and POST together?
I need to apply WHERE status!='disable' in my php code at $result after I click on the checkbox and then on uncheck of the checkbox it should be removed again and both enable and disable datas from MySql should be shown in the php, is that possible without using AJAX codes, if it is then how can I do that. Can anyone find where am I going wrong
Checkbox, code given below:
<h4 id="CATEGORIESfilters">Availability</h4>
<table border="0" cellspacing="0" id="Availabilitytable">
<tr>
<td>
<input type="checkbox" name="Availability" id="Availabilitycheckboxexcludeoutofstock" >
</td>
<td>
<label for="Availabilitycheckboxexcludeoutofstock">Exclude Out Of Stock</label>
<td>
</tr>
</table>
Php Code is given below:
<?php
include "db_connection.php";
if(isset($_REQUEST['Availability']))
{
$availability="WHERE status!='disable'";
}
else
{
$availability="";
}
$result = mysql_query("SELECT * FROM burger $availability ORDER BY product_no_id DESC");
while($data=mysql_fetch_array($result)):
if($data['status']=="enable")
{
?>
<div class="productwrap">
<div id="Instockwrap">
In Stock
</div>
</div>
<?php
}
else
{
?>
<div class="productwrap">
<div id="Outofstockwrap">
Out Of Stock
</div>
</div>
<?php
}
endwhile;
?>
you can add a class to the out of stock items and hide them via jquery if checkbox is checked, so you dont have to reload the page on checkbox changes
hotels_data table
hotel_rooms table
MYSQL QUERY
$pdo = $dbo->prepare('SELECT distinct hotels_data.*, hotel_rooms.hid, hotel_rooms.room_name, hotel_rooms.price
FROM hotels_data
LEFT OUTER JOIN hotel_rooms
ON hotels_data.hotel_id = hotel_rooms.hid
');
OUTPUTING THE DATA
i loop the Hotel rooms
$row = $pdo->fetchAll(PDO::FETCH_OBJ);
foreach($row as $rows){
print '
<!-- Listing -->
<div class="list_hotels_box">
<ul class="list_hotels_ul">
<li style="display:block;">
<img src="../img/hotel_img.png" alt="" style="width: 180px; height:180px;"/>
</li>
<li style="width: 100%;">
<h3 class="clear-top">'.$rows->hotel_name.'<span><?php print $star; ?></span></h3>
<p>'.$rows->hotel_address.', '.$rows->hotel_state.''.$rows->hotel_country.' </p>
<div id="rooms">
<p>
<table class="table table-condensed table-striped table-hover table-bordered">
';
foreach($row as $td){
if($td->hotel_id == $rows->hid){
print
'
<tr>
<td>'.$td->room_name.'</td>
<td align="right" style="color: darkorange;"><strong><sup>RM</sup>'.$td->price.'</strong></td>
</tr>
';
};
} ;
print '
<tr>
<td colspan="2">See All Rooms</td>
</tr>
</table>
</p>
</div>
</li>
<div align="right">
<li>
<h4><small>Rating</small> <strong>8.5</strong></h4>
<span class="help-block clear">"0" Reviews</span>
<button onclick="alert(\'Not operational yet\')" class="btn btn-sm btn-info">Book Now</button>
</li>
</div>
</ul>
</div>
<!-- Listing -->
';
Here is the output
i have Hotel Sample & Hotel Sample 2 but Hotel Sample has outputted 2
i think its bcoz of the 2 rooms
so my problem is how do i remove the duplicate data
Please assist me. TQ
sorry if i didn't make myself very clear
One way would be to simply split to 2 queries, like:
SELECT * FROM hotels_data;
And then rooms query inside your hotels loop:
SELECT hid, room_name, price FROM hotel_rooms WHERE hid = :hotel_id
This assumes you are using binded parameters and bind the $rows->hotel_id to :hotel_id parameter.
You could also use GROUP BY hotel_id, but then you won't get all the rooms for your hotels, unless you use GROUP_CONCAT() and parse the concatenated rooms values.
I'm running into a strange scenario involving a widget and the lay-out. I've created a layout that overrides the original column 2 lay-out. It calls a widget in the file and in that widget display a table on the side-bar of some information that I would like to show the user. The layout sidetable.php looks like this
<?php $this->beginContent('//layouts/main'); ?>
<div class="row-fluid">
<div class="span3">
<?php
$this->widget('ListSummaryWidget', array('totaldue'=>$totaldue));
?>
<table class="table">
</table>
</div><!-- sidebar span3 -->
<div class="span9">
<div class="main">
<?php echo $content; ?>
</div><!-- content -->
</div>
</div>
<?php $this->endContent(); ?>
Now all this works - displaying a datatable on the left hand column of the screen. However, something strange happens. Whenever I git rid of
<table class="table">
</table>
The whole view breaks - showing a ridiculous structure/layout that doesn't look much at all like the original. This is confusing/intriguing. In my widget I declare the exact same table and yet it does not seem to matter that I declare this table. Here is the code for my widget's view
<table class="table list_summary table-bordered">
<form action="<?php echo Yii::app()->createUrl('recipient/processpayment', array('id'=>$id)) ?>" method="post" >
<tr class="primary"><td> <h4>List Summary </h4> </td></tr>
<tr ><td>
<?php echo $numpeople; ?> Recipient(s)
</td></tr>
<tr ><td>
Total Due: <?php echo $totaldue ?> Rwf
</td></tr>
<tr> <td>
<h4> Mobile Money Accounts: </h4>
<?php
/*
foreach($accounts as $account)
{
echo $account->name; ?>: <?php echo $account->balance; ?> Rwf<br> <?php
}
*/
?>
</td> </tr>
<tr> <td>
<button class="btn btn-block btn-primary " type="submit">Pay Now</button> </td> </tr>
</td></tr>
</form>
Could anyone explain why this is happening? Though it's not the worst thing in the world - I'm really intrigued as to why I'm required to have some html when I have the same html in the widget's view.
Resolved:
I didn't end the table in my widget. I should have added at the end
</table>