I have this code, that picks article content from my word press db then outputs it onto a table, using a loop. once a user select the articles they like they submit the selection to my next page call it displaypage to display the selected articles.
the selection page code looks like this.
<?php /*
Template Name: News Selector Template
*/
//Pull the data
$posts = $wpdb->get_results
("
SELECT
p1.*,
wm2.meta_value
FROM
mp_posts p1
LEFT JOIN
mp_postmeta wm1
ON (
wm1.post_id = p1.id
AND wm1.meta_value IS NOT NULL
AND wm1.meta_key = '_thumbnail_id'
)
LEFT JOIN
mp_postmeta wm2
ON (
wm1.meta_value = wm2.post_id
AND wm2.meta_key = '_wp_attached_file'
AND wm2.meta_value IS NOT NULL
)
WHERE
p1.post_status='publish'
AND p1.post_type='post'
ORDER BY
p1.post_date DESC LIMIT 0,30
");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div class="container">
<div class="header"><img src="/sample/images/logo_main_300x100px.png" alt="logo" name="sample_logo" width="300" height="100" id="logo" style="background-color: #FFF; display:block;" />
<!-- end .header --></div>
<div class="content">
<h1>sample Top 30 Articles</h1>
<p>Select the articles you want to add to the newsletter</p>
<form action="http://sample.net/brands/sample/newsletter/" method="post">
<table width="960" border="2" summary="A collection of all the articles">
<caption>
Article Selection
</caption>
<tr>
<th scope="col">Select</th>
<th scope="col">Title</th>
<th scope="col">Description</th>
<th scope="col">Cover</th>
<th scope="col">link</th>
</tr>
<?php
// if(isset($_POST['submit'])){
if (have_posts($posts)) {
// var_dump($posts); die();
foreach($posts as $post) {
//foreach($_POST['article_list'] as $post){
?>
<tr>
<th scope="row"><input type="checkbox" name="article[]" value="<?php echo $post->ID; ?>" /></th>
<td headers="article[]"><?php echo $post->post_title; ?></td>
<td headers="article[]"><?php echo $post->post_excerpt; ?></td>
<td headers="article[]"><?php echo '<img src="https://sample/wp-content/uploads/'.$post->meta_value.'" width="100px" alt="" />'?></td>
<td headers="article[]"><?php echo $post->guid; ?></td>
</tr>
<?php
}
}
?>
<p><input type="hidden" name="metas" value="<?php echo implode(",", $post); ?>"></p>
</table>
<div>
<p><input type="submit" name="Generate" value="submit"/></p>
</div>
</form>
<!---->
</div>
<!-- end .content --></div>
<div class="footer">
<p>sample Management System</p>
<!-- end .footer --></div>
<!-- end .container --></div>
</body>
</html>
Iv used implode to collect the array variables of all selected articles via a check box option.
on my display page i wrote this simple code to see the output of the array.
<?php /*
Template Name: Newsletter Template
*/
$posts = explode(",", $_POST['metas']);
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<?php echo $posts[0]->guid ?>
<?php echo $posts[0]->meta_value ?>
<?php echo $posts[0]->post_title ?>
<?php echo $posts[0]->post_excerpt ?>
</body>
</html>
Now when i submit the selected articles from the first page i'm supposed to be able to access the various array elements in my display page, but that's not the case. i get the
ERROR
Warning: implode(): Invalid arguments passed in
/home/sampled/public_html/brands/sample/wp-content/themes/newsample/page-newsselector.php
on line 164
i don't know where i went wrong with my implementation.
HELP PLEASE
Related
On the list.php page, I am passing a variable using hidden input method in form.
This form redirects to listd.php where the variable is used to run an SQL query to delete a particular row from the database where the variable==name.
If I print the variable on listd.php before processing SQL query then it is visible but during when query is processed it gives unidentified index error.
The code in listd.php works if I take input from the user on the same page.
list.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title> Sports </title>
<link rel="stylesheet" href="main.css" type="text/css" />
<link href="https://fonts.googleapis.com/css?family=Tangerine">
<link href="https://fonts.googleapis.com/css?family=Dancing+Script|Great+Vibes|Roboto|Barrio" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
</head>
<body>
<?php
require ("config.php");
?>
<div class="row">
<div class="container-fluid">
<div class="jumbotron text-center">
<h3> List Events</h3>
<?php
session_start();
if($_SESSION['username'])
echo "<h2>Welcome ".$_SESSION['username']."!</h2>";
else
header('location:index.php');
//session_start();
if(isset($_SESSION['username']))
echo "<h3><a href='logout.php'>Logout</a></h3>";
?>
</div>
</div>
</div>
<div class="container">
<h2>Hover Rows</h2>
<p>The .table-hover class enables a hover state on table rows:</p>
<table class="table table-hover">
<thead>
<tr>
<th>Event </th>
<th>Add</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<!--
<tr>
<td>John</td>
<td>Doe</td>
<td>john#example.com</td>
</tr>
-->
<?php
{$result="SELECT name FROM events";
$q = mysqli_query($conn,$result) or die(mysql_error());
while ($row=mysqli_fetch_array($q))
{
echo "<tr> <td>";
echo $row['name'];
echo "</td>";
echo "<td>";
echo '<button> Add </button> <br><br>';
echo "</td>";
echo "<td>";
echo '<form action="liste.php" method="post" >';
echo '<input type="hidden" name="edit" value="';?>
<?php echo $row['name'];
echo'"> <input type="submit" value="Edit">';
echo "</form>";
echo "</td>";
echo "<td>";
echo '<form action="listd.php" method="post" >';
echo '<input type="hidden" name="del2" value="';?>
<?php echo $row['name'];
echo'"> <input type="submit" value="Delete">';
echo "</td>";
echo "</form>";
}
}
?>
<!--
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary#example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july#example.com</td>
</tr>
-->
</tbody>
</table>
</div>
</body>
</html>
listd.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title> Sports </title>
<link rel="stylesheet" href="main.css" type="text/css" />
<link href="https://fonts.googleapis.com/css?family=Tangerine">
<link href="https://fonts.googleapis.com/css?family=Dancing+Script|Great+Vibes|Roboto|Barrio" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
</head>
<body>
<?php
require ("config.php");
?>
<div class="row">
<div class="container-fluid">
<div class="jumbotron text-center">
<h3> Events </h3>
<div class="row">
<div class="container-fluid text-primary text-center">
<br>
<button class="btn"> Add </button> <br><br>
<button class="btn"> Edit </button> <br><br>
<button class="btn"> Delete </button> <br><br>
<button class="btn"> View </button> <br><br>
</div>
</div>
<?php
session_start();
?>
<form action="listd.php" method="post" class="a">
<table>
<tr>
<td> Category Name </td>
<td>
<strong>
<?php echo $_POST["del2"];
$k=$_POST['del2'];
?>
</strong>
</td>
</tr>
<tr>
<td></td>
<td> <input type="submit" value="Delete" name="delete"> </td>
</tr>
</table>
</form>
<?php
$event=$k;
if(isset($_REQUEST['delete'] )&& $event )
{
$sql="DELETE FROM events WHERE name='$event'";
if(mysqli_query($conn,$sql))
{
echo "deleted Succesfully";
//header('location:listd.php');
}
else
echo "error";
}
?>
</div>
</div>
</div>
</body>
</html>
It's really not necessary to use two forms to do this, unless this is a very dangerous action. this is also the source of your problem. $k is not preserved on the second postback. Requests are stateless. When you submit the second form, the listd.php script runs again from the start, and the values assigned to variables the last time it ran. This is the normal behaviour of HTTP requests in general.
A single-form version might look like this:
list.php
<?php
//this needs to be before anything else otherwise the redirect might fail due to headers already sent.
session_start();
if(isset($_SESSION['username'])) //corrected to use isset(). Only one test for this is needed.
{
echo "<h2>Welcome ".$_SESSION['username']."!</h2>";
echo "<h3><a href='logout.php'>Logout</a></h3>";
}
else
{
header('location:index.php');
die(); //script needs to die because webcrawlers/bots will ignore the redirect header, and view the rest of the page anyway, without permission. Using die() means the rest of the page never gets output.
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title> Sports </title>
<link rel="stylesheet" href="main.css" type="text/css" />
<link href="https://fonts.googleapis.com/css?family=Tangerine">
<link href="https://fonts.googleapis.com/css?family=Dancing+Script|Great+Vibes|Roboto|Barrio" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
</head>
<body>
<?php
require ("config.php");
?>
<div class="row">
<div class="container-fluid">
<div class="jumbotron text-center">
<h3> List Events</h3>
</div>
</div>
</div>
<?php
$message = null; //will hold any extra message to the user resulting from data processing actions (such as delete)
//only run the next section if del2 has been submitted from a postback.
if(isset($_POST['del2']))
{
$event = $_POST['del2'];
$sql= "DELETE FROM events WHERE name='$event'"; //here you should use parameterised queries, I will leave it to you to look this up online, using the link I gave in the comments.
if(mysqli_query($conn,$sql))
{
$message = "Deleted succesfully";
}
else
{
$message = "error";
//here you should check mysqli_error() and log the output somewhere (not visible to the user)
}
}
?>
<div class="container">
<h2>Hover Rows</h2>
<!-- here is an example of how you can inject the confirmation message into somewhere suitable in the page. You can modify this to suit your needs. -->
<?php if ($message != null) { echo "<p><b>".$message."</b></p>"; } ?>
<p>The .table-hover class enables a hover state on table rows:</p>
<table class="table table-hover">
<thead>
<tr>
<th>Event </th>
<th>Add</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
$result="SELECT name FROM events";
$q = mysqli_query($conn,$result) or die(mysqli_error()); //corrected to use mysqli_error not mysql_error
while ($row=mysqli_fetch_array($q))
{
echo "<tr> <td>";
echo $row['name'];
echo "</td>";
echo "<td>";
echo '<button> Add </button> <br><br>';
echo "</td>";
echo "<td>";
echo '<form action="liste.php" method="post" >';
echo '<input type="hidden" name="edit" value="';
echo $row['name'];
echo'"> <input type="submit" value="Edit">';
echo "</form>";
echo "</td>";
echo "<td>";
echo '<form action="list.php" method="post" >';
echo '<input type="hidden" name="del2" value="';
echo $row['name'];
echo'"> <input type="submit" value="Delete" onclick="return confirm("Are you sure?");>'; //adds a confirmation dialog box to the delete button
echo "</td>";
echo "</form>";
}
?>
</tbody>
</table>
</div>
</body>
</html>
You do not need listd.php at all.
P.S. A separate hint: I see you are copying the same HTML <head> etc material into every page script. This is not necessary. You can create two files e.g. header.php and footer.php. In header.php you can put the opening <html> and <head> tags right down to <body> and any other enclosing tags necessary for the consistent layout of all your pages. Then in footer.php you can put the equivalent closing tags. And then in all the other pages of your site you can simply write <?php require_once("header.php"); ?> as the first line and <?php require_once("footer.php"); ?> as the last line. Then any changes you need to make to the headers (e.g. new CSS files or something) are automatically applied to all the pages without tedious copy/paste actions. Although I suggested that you remove your second script here, you can do this for any other pages in your site. It's also a good general principle of code re-use which you can apply to all kinds of situations in your future code.
P.P.S. I'd also consider using an up-to-date doctype. The HTML5 doctype declaration is simply <!DOCTYPE html>. This will likely result in more consistent behaviour of the HTML and CSS in your page, and future-proofs your application against deprecation of older doctypes which are no longer in current use.
I have a form that I need to act in specific ways. Example: User brings equipment back: I don't want that to show up in my form. User takes equipment out: I want it to generate to my form, they enters some information, form sends information to database. User takes equipment out: it too generates said form, he doesn't enter any information, form submits information after 20 sec, information is in database.
I was doing a simple page refresh to get the information into my form but that was pulling all the equipment that had been brought into the warehouse that day. So I commented that out and then I would get stuck on my ajax page.
I then tried creating a new php page that had a 301 page refresh and that worked to get the page back to my index page, however, my form wasn't working properly and so I commented out the auto submit and now my form works great... except I can't fulfill this last requirement where the page will submit the data if the user forgets to put his equipment information in.
I'm looking to do an if/then/else type of page submission. However, I can't figure out how to do one purely in either php or html. This is what I have figured out so far but it doesn't work and I know I'm way off somewhere.
<!DOCTYPE html>
<html>
<body>
<!--This is the one that is currently commented out in my code
<script type="text/javascript">
window.setTimeout(function() {
window.location = 'index.php'},1000*2);
</script>
</body>
</html> -->
//This is my pipe dream
<?php
if (isset($_POST['action'])) {
switch ($_POST['action']) {
case ‘DONE’:
document.getElement('formSubmit').submit();
break;
}
} else {
<script type="text/javascript">
window.setTimeout(function(){
document.getElement('formSubmit').submit();
},1000*30);
</script>
}
?>
I don't know that much about jQuery other than going through a codecademy, and I know even less javascript. I'm a database person that got "conned" into building an advanced form/webpage. So I'm learning PHP, CSS, jQuery and HTML as I code.
Index.php:
<!DOCTYPE html>
<html>
<head>
<meta name=“Warehouse 3962” content="width=device-width, initial-scale=1.0">
<link href="style.css" type="text/css" rel="stylesheet">
<script type="text/javascript">
<!—window.setTimeout(function(){
document.getElement(‘formSubmit').submit();
},1000*30); —>
</script>
</head>
<body>
<section class="w">
<div class="row">
<div class="small columns">
<img src="logo.png" />
<h3 class="green">Users</h3>
</div>
<h6>Warehouse 3962</h6>
</div>
<div class="row">
<div class="small columns">
<form action="ajax.php" method="post" id="formSubmit">
<table id="equipment-table">
<thead>
<tr>
<th>Equipment</th>
<th>Amount</th>
<th>Val1</th>
<th>Val2</th>
</tr>
</thead>
<tbody>
<?php foreach
($results['tags'] as $equipment) {
if ($equipment['category'] == "Part") { ?>
<tr>
<td><?= $equipment['Amount']; ?></td>
<td class="text-center"><?= $equipment[‘quantity']; ?></td>
<td><input type="text" name="val1" /></td>
<td><input type="text" name="val2" /></td>
</tr>
<?php } // end if
} // end foreach ?>
<tr>
<td colspan="4" style="text-align: right;"><input type="submit" class="button" name="DONE" value="DONE" /></td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
</section>
</body>
</html>
Please try this new solution. This will send a post every 30 seconds containing only the input boxes containing text on them.
<!DOCTYPE html>
<html>
<head>
<meta name="Warehouse 3962" content="width=device-width, initial-scale=1.0">
<link href="style.css" type="text/css" rel="stylesheet">
</head>
<body>
<section class="w">
<div class="row">
<div class="small columns">
<img src="logo.png" />
<h3 class="green">Users</h3>
</div>
<h6>Warehouse 3962</h6>
</div>
<div class="row">
<div class="small columns">
<form action="ajax.php" method="post" id="formSubmit">
<table id="equipment-table">
<thead>
<tr>
<th>Equipment</th>
<th>Amount</th>
<th>Val1</th>
<th>Val2</th>
</tr>
</thead>
<tbody>
<?php
foreach ($results['tags'] as $equipment) :
if ($equipment['category'] === "Part") :
?>
<tr>
<td>
<?php echo $equipment['Amount']; ?>
</td>
<td class="text-center">
<?php echo $equipment['quantity']; ?>
</td>
<td>
<input id="<?php echo $equipment['number'];?>-val1" type="text" name="<?php echo $equipment['number'];?>-val1"/>
</td>
<td>
<input id="<?php echo $equipment['number'];?>-val2" type="text" name="<?php echo $equipment['number'];?>-val2"/>
</td>
</tr>
<?php
endif;
endforeach;
?>
<tr>
<td colspan="4" style="text-align: right;">
<input type="submit" class="button" name="DONE" value="DONE" />
</td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
</section>
<script type="text/javascript">
function sendData() {
var inputs = document.getElementById('equipment-table').getElementsByTagName('input'),
data = [],
name, val1, val2;
for (var i = 0; i < inputs.length; i++) {
if ( inputs[i].type === 'submit') {
continue;
}
if ( inputs[i].value ) {
name = inputs[i].name.split('-val');
val1 = inputs[i].name.split('val1');
if (val1.length > 1) {
data.push({name: name[0], val1: inputs[i].value});
}
else {
data.push({name: name[0], val2: inputs[i].value});
}
}
}
window.setTimeout(function() {
sendData();
},30000);
}
sendData();
</script>
</body>
</html>
You cannot mix PHP with JavaScript and why you set a timeout to 1000*30, that is equal to set a timeout to 30000 which means 30 seconds.
Then, you can use the 'require' attribute in the input filed to force the user to fill the required information.
<!DOCTYPE html>
<html>
<head>
<meta name="Warehouse 3962” content="width=device-width, initial-scale=1.0">
<link href="style.css" type="text/css" rel="stylesheet">
</head>
<body>
<section class="w">
<div class="row">
<div class="small columns">
<img src="logo.png" />
<h3 class="green">Users</h3>
</div>
<h6>Warehouse 3962</h6>
</div>
<div class="row">
<div class="small columns">
<form action="ajax.php" method="post" id="formSubmit">
<table id="equipment-table">
<thead>
<tr>
<th>Equipment</th>
<th>Amount</th>
<th>Val1</th>
<th>Val2</th>
</tr>
</thead>
<tbody>
<?php
foreach ($results['tags'] as $equipment) :
if ($equipment['category'] == "Part") : ?>
<tr>
<td><?= $equipment['Amount']; ?></td>
<td class="text-center">
<?php echo $equipment[‘quantity']; ?>
</td>
<td>
<input id="val1" type="text" name="val1”/>
</td>
<td>
<input id="val2" type="text" name="val2"/>
</td>
</tr>
<?php
endif;
endforeach;
?>
<tr>
<td colspan="4" style="text-align: right;">
<input type="submit" class="button" name="DONE" value="DONE" />
</td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
</section>
<script type="text/javascript">
window.setTimeout(function(){
var val1 = document.getElementById("val1").value,
val2 = document.getElementById("val1").value;
if ( ! val1 && ! val2 ) document.getElement('formSubmit').submit();
},30000);
</script>
</body>
</html>
i actually want to use ajax in CodeIgniter to update value in the database.
below is the code given:
views/list_user.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Admin Panel</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/screen.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('.round_button_circle').click(function() {
//Now just reference this button and change CSS
//$(this).css('background','green');
var id=this.value;//Getting the id of the user to update the status from unpublish to publish
var url='<?php echo base_url(); ?>index.php/ajax_controller/user_status';
alert(id+url);
$.ajax({
type: 'POST',
url: 'url', //We are going to make the request to the method "list_dropdown" in the match controller
data: 'id='+id, //POST parameter to be sent with the tournament id
success: function(data)
{
}
});
});
});
</script>
</head>
<body>
<div id="page-heading">
<div class="button">Create User</div><!--create category-->
<h1>USERS</h1><!--users's list-->
</div>
<!-- end page-heading -->
<table border="0" style="width:97%;margin:0px auto" cellpadding="0" cellspacing="0" id="content-table">
<tr>
<td>
<!-- start content-table-inner START -->
<div id="content-table-inner">
<div class="stdiv"><div class="msg1">
<?php
if(isset($_GET['msg']))
{
$msg=$_GET['msg'];
if($msg=="usertype")
{
echo "User has been Created";
}
if($msg=="create")
{
echo "User has been Created";
}
if($msg=="delete")
{
echo "User has been Deleted";
}
if($msg=="update")
{
echo "User has been Updated";
}
}
?>
</div>
</div>
<!-- start category-table -->
<table border="0" cellpadding="0" style="width:100%;margin:0px auto" cellspacing="0" id="product-table">
<tr>
<tr>
<th class="tbl_hdr">USER ID</th> <!--ID-->
<th class="tbl_hdr">NAME</th> <!--Name-->
<th class="tbl_hdr">EMAIL</th> <!--Email-->
<th class="tbl_hdr">PHONE NUMBER</th> <!--ph number-->
<th class="tbl_hdr">STATUS</th> <!--publish/unpublish-->
<th class="tbl_hdr" colspan="2">ACTION</th> <!--edit/delte-->
</tr>
<?php foreach($users as $user){?>
<tr>
<td><?php echo $user->id;?></td>
<td><?php echo $user->username;?></td>
<td><?php echo $user->email;?></td>
<td><?php echo $user->contact;?></td>
<td ><button id="status" class="round_button_circle" value="<?php echo $user->id;?>"></button></td>
</tr>
<?php }?>
</table>
<!-- end product-table................................... -->
</div>
<!-- end content-table -->
<!-- start paging..................................................... -->
<!-- end paging................ -->
<div class="clear"></div>
<!-- end content-table-inner ............................................END -->
</td>
</tr>
</table>
<div class="clear"> </div>
</div>
<!-- end content -->
<div class="clear"> </div>
</div>
<!-- end content-outer........................................................END -->
<div class="clear"> </div>
<!-- start footer -->
</body>
</html>
controller/ajax_controller.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Ajax_Controller extends CI_Controller {
// Show view Page
// This function call from AJAX
public function user_status()
{
$id=$this->input->post('id');
$data = array(
'status' => 1
);
$this->db->where('id', $id);
$this->db->update('tbl_users', $data);
echo "1";
}
}
Its giving me the url and the id which i want to update in the database in the alert box...but its not updating the value in the database once the button is clicked..
Can anyone help???
There is one mistakes in your code.
Change
url: 'url', // in ajax call
To
url: url, // do not use quotes with url variable
I am trying to make page in php/html that will display a "product's details." I have it displaying the icon and the link to the "details page," but it will not display ONLY one item on the "details page." Currently, the product's page (where the icon and the link are) will link to the "details page" just fine. However, when the page loads it loads every item in the sql database that has an 'ID.' I expected it to only take the item's id and display the page related to that item, however I received a cluster of them all... The code I have is what follows. I am currently trying to learn PHP so please if I make an error, a really bad one like something that isn't efficient. Please post the more efficient way of doing it. I am learning it the way I was taught at school.
<?php
//This page display a topic
include('admin/variable.php');
if(isset($_GET['id']))
{
$id = intval($_GET['id']);
$dn1 = mysql_fetch_array(mysql_query('select c.id, c.name, c.description, c.price, c.quantity, c.itemID, c.imgName, c.position, (select count(t.id) from topics as t where t.parent=c.id and t.id2=1) as topics, (select count(t2.id) from topics as t2 where t2.parent=c.id and t2.id2!=1) as replies from categories as c group by c.id order by c.position asc'));
if($dn1['id']>0)
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="<?php echo $design; ?>/style.css" rel="stylesheet" title="Style" />
<title><?php echo htmlentities($dn1['name'], ENT_QUOTES, 'UTF-8'); ?> - <?php echo htmlentities($dn1['itemID'], ENT_QUOTES, 'UTF-8'); ?> - KB Computers</title>
</head>
<body>
<div class="header">
<img src="<?php echo $design; ?>/images/logo.png" alt="Forum" />
</div>
<div class="Content">
<?php
?>
<h1><?php echo $dn1['name']; ?></h1>
<?php
$dn2 = mysql_query('select c.id, c.name, c.description, c.price, c.quantity, c.itemID, c.imgName, c.position, c.position, (select count(t.id) from topics as t where c.parent=c.id and t.id2=1) as topics, (select count(t2.id) from topics as t2 where t2.parent=c.id and t2.id2!=1) as replies from categories as c group by c.id WHERE c.id = ' . $id .' order by c.position asc');
//////////////////////////////////////////////////////////
while($dnn2 = mysql_fetch_array($dn2)) //This is line 30!
//////////////////////////////////////////////////////////
{
$parent = $dnn2['parent'];
if(isset($_GET['id']))
{
if($_GET['id'] == $parent){
?>
<div id="thing">
<table>
<tr>
<th><?php echo $dnn2['imgName']; ?></th>
</tr>
<br />
<tr>
<th><?php echo $dnn2['price']; ?></th>
</tr>
<br />
<tr>
<th> <?php echo $dnn2['description']; ?></th>
</tr>
<br />
<tr>
<th><?php echo $dnn2['itemID']; ?></th>
</tr>
<?php
if(isset($_SEESION['username']) and $_SESSION['username'] == $admin){?><div class="edit"><img src="<?php echo $design; ?>/images/edic.png" alt="Edit" /></div>
<?php } ?>
</table></div>
<?php
}else{echo 'The parent and id values are not the same.';}
}}
?>
</div>
</body>
</html>
<?php
}
else
{
echo '<h2>This topic doesn\'t exisc.</h2>';
}
}
else
{
echo '<h2>The ID of this topic is not defined.</h2>';
}
?>
<?php
//This page display a topic
include('admin/variable.php');
include('home.php');
if(isset($_GET['id']))
{
$dn1 = mysql_query('select
c.id,
c.name,
c.description,
c.price,
c.quantity,
c.itemID,
c.imgName,
c.parent,
c.position,
(select count(c.id) from categories as c where c.parent=c.id) as categories, (select count(c.id) from categories as c where c.parent=c.id and c.id!=0) as replies from categories as c group by c.id order by c.position asc');
if($dn1 === false){
die(mysql_error());
}
while($dnn1 = mysql_fetch_array($dn1))
{
$parent = $dnn1['parent'];
if($_GET['id'] == $parent){
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="require/style.css" rel="stylesheet" title="Style" />
<title><?php echo htmlentities($dnn1['name'], ENT_QUOTES, 'UTF-8'); ?> - <?php echo htmlentities($dnn1['itemID'], ENT_QUOTES, 'UTF-8'); ?> - KB Computers</title>
</head>
<body>
<div class="Content">
<div style="background:white; height:800px;">
<div id="shopNav">
<ul>
<li class="end">Shop</li>
<li>Catagories</li>
<li>New Products</li>
<li>My Account</li>
<li class="end2">Checkout</li>
</ul>
</div>
<div id="thing">
<table><h1><?php echo $dnn1['name']; ?></h1>
<tr>
<th><?php echo '<img src="image/' . $dnn1['imgName'].'" alt="' . $dnn1['imgName']. '" width="128" height="128"'; ?></th>
</tr>
<tr>
<th><?php echo $dnn1['price']; ?></th>
</tr>
<tr>
<th class="tableDesc"> <?php echo $dnn1['description']; ?></th>
</tr>
<tr>
<th><?php echo $dnn1['itemID']; ?></th>
</tr>
<?php
if(isset($_SEESION['username']) and $_SESSION['username'] == $admin){?>
<tr>
<img src="<?php echo $design; ?>/images/edic.png" alt="Edit" />>
</tr>
<?php } ?>
<tr>
<th> </th>
</tr>
</table>
</div>
<?php include("require/rightBar.html"); ?></div><?php include("require/footer.html");
}
}
}else{echo 'That product doesnt exist!';}
?>
</div>
</body>
I have a lot going on in my header so I am hoping it is makes some sense. My Header does not render at all. The only part that shows up is the loginfrom2.inc.php I was wondering if anyone can let me know what is wrong
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel=stylesheet type="text/css" href="style.css">
<style type="text/css">
.headerfont {
color: #FFF;
}
</style>
<?php
/*Login Logout*/
if(isset($_SESSION['currentMember'])) {
$currentMember=unserialize($_SESSION['currentMember']);
?>
</head>
<body>
<table width="764" height="97" cellpadding="0" cellspacing="0" border="0">
<tr valign="top">
<td width="248"></td>
<td width="100%" background="img/faddedbanner3.png"> <img src="../img/star3.png" width="94" height="104" alt="Star"> <span class="headerfont" align="center"><strong>The Unofficial Bank of Mike</strong></span></td><td background="../assign4/img/faddedbanner3.png"></td>
<td>
</td>
</tr>
<div id="logout">
<span id="user_session">VALUED CUSTOMER: <strong>
<?=$currentMember->firstname?>
<?=$currentMember->lastname?>
</strong></span>
<a id="logout" href="<?=URL_ROOT?>logout.php" title="logout">LOGOUT</a>
<?php
}else{
require_once('loginform2.inc.php');
}
?>
</table>
</body>
</html>
//////////////////////////////////////////
This is my Loginform2.inc.php You can see the include statement above
<div id="login_form">
<form id="login" method="post" action="processlogin.php">
<p>
<label for="emailaddress">E-Mail Address:</label>
<input type="text" name="emailaddress" id="emailaddress" size="15">
</p>
<p>
<label for="password">Password: </label>
<input type="password" name="password" id="email" size="15">
</p>
<p>
<input type="submit" name="submit" id="login_submit" value="Login"></p>
</form>
</div>
///////////////////////processlogin.php
/*start session*/
session_start();
$_SESSION['currentMember'] = serialize($currentMember);
note the screen shots of my my web page
<?php
/*Login Logout*/
if(isset($_SESSION['currentMember'])) {
$currentMember=unserialize($_SESSION['currentMember']);
?>
Move that block to at least be inside the <body> tag.
When $_SESSION['currentMember'] is not set, the <head> element is never closed.
You also shouldn't be putting anything between the last <tr> and closing </table> tag. Your HTML is a bit of a mess.
Here's how you should probably structure it
<?php session_start() ?>
<!DOCTYPE html>
<html>
<head>
<!-- link / style elements, etc -->
</head>
<body>
<table>
<!-- table contents -->
</table>
<?php if (isset($_SESSION['currentMember'])) :
$currentMember=unserialize($_SESSION['currentMember']); ?>
<div id="logout">
<!-- etc -->
</div>
<?php else : require_once 'loginform2.inc.php'; endif ?>
</body>
</html>
First move that if block inside your body tag, as others have suggested. That means replace this:
<?php
if(isset($_SESSION['currentMember'])) {
$currentMember=unserialize($_SESSION['currentMember']);
?>
</head>
<body>
With this:
</head>
<body>
<?php
if(isset($_SESSION['currentMember'])) {
$currentMember=unserialize($_SESSION['currentMember']);
?>
If that doesn't fix it, take a look at this line:
if(isset($_SESSION['currentMember'])) {
It checks if $_SESSION['currentMember'] has a value other than NULL. If not, loginform2 is displayed instead of your header. I can't see anywhere in the code you've pasted where $_SESSION['currentMember'] is being given a value.
I'm guessing that it should be set in processlogin.php once a user successfully logs in. Perhaps some part of the login process is broken.