im developing a project my own and i use codeigniter as my framework, i'm pretty begginer to php and codeignier. i created a confirm box in jquery ,but it's and html alert. so how to do that? don't laugh at me guys. thanks.
view
<?php
$_instance = get_instance();
$attributes = array('id' => 'main_form');
?>
<?php echo form_open('registration/reset',$attributes);?>
<style>
span{
color: red;
}
#main_tb{
margin-top:100px;
}
</style>
<table cellspacing='10' id>
</table>
<div id='main_form'>
<form id="main_form" name="form">
<table CELLSPACING=2 CELLSPACING=10 id='main_tb' >
<tr>
<td></td>
<td id="error"></td>
</tr>
<tr>
<td>User Name</td>
<td> <select class="cmb" style="width: 200px;" id="cmb_user" name="cmb_user"> </select></td>
</tr>
<tr>
<td></td>
<td><?php echo $this->session->flashdata('reset_error'); ?></td>
</tr>
<tr>
<td></td>
<td> <input type="submit" id="save" value="reset password"/></td>
</tr>
</table>
</form>
</div>
<?php echo form_close();?>
script
$j('#main_form').submit(function() {
// event.preventDefault();
var status = confirm("Are you sure? This cannot be undone");
if(status == false){
return false;
}
else{
return true;
}
});
controller
function reset(){
$password =$_POST['cmb_user'];
echo $username = $this->input->post('cmb_user');
$data_array = array(
'id_user' => $this->input->post('cmb_user'),
);
// // echo 'sdsd';
// echo $_POST['cmb_user'];
//
$this->load->model('registration/registration_model');
$this->registration_model->reset_pass($data_array);
$this->session->set_flashdata('reset_error', ' <br><span style="font-size: 10px;background-color: #FFFFFF;color:#ff0000;border:solid 1px #ff99cc;padding:2px;border-radius: 5px 5px 5px 5px">Reset Successfull</span>');
redirect('/registration/admin_reset');
}
this function works great. but i want to add jquery fancy popup like sweet alert. thank's again..
Add the following code into your view
<script src="https://cdn.rawgit.com/t4t5/sweetalert/master/dist/sweetalert.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/t4t5/sweetalert/master/dist/sweetalert.css">
<script language="javascript">
sweetAlert("Oops...", "Something went wrong!", "error");
</script>
Related
So im kinda trying to delete row from my mysql database using checkboxes. Here is my code. Would be glad if someone could write me down simple delete code. Tryed many but failed, stuck for hours with this :(
<html>
<head>
<title>Admin, User</title>
</head>
<body>
<?php include 'connect.php';?>
<?php include 'functions.php';?>
<?php include 'title_bar.php';?>
<h3>Sukurti Nauja uzduoti: </h3>
<form method='post'>
<?php
if(isset($_POST['submit2']))
{
$pav = $_POST['pav'];
$uzduotis = $_POST['uzduotis'];
if(empty($pav) or empty($uzduotis)){
echo "<p>Privalomi visi langai!</p>";
}
else {
$sql = ("INSERT INTO uzduotys VALUES ('','$pav','$uzduotis')");
}
if($database->query($sql) == TRUE)
{
header('location:kurtisalinti.php');
}
else {
echo "<p>Klaida!</p>";
}
}
?>
<p>Uzduoties pavadinimas:
<p><input type='text' name='pav' />
<p>Uzduotis:
<p><textarea name='uzduotis'></textarea>
<p><input type='submit' name='submit2' value='Sukurti Uzduoti' />
</form>
</p></p></p></p>
</form>
<h3>Pasalinti pasirinkta uzduoti is uzduociu saraso: </h3>
<?php
$query = mysqli_query($database,"SELECT uzid,pav,uzduotis FROM uzduotys");
$count=mysqli_num_rows($query);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Pavadinimas</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Aprasymas</strong></td>
</tr>
<?php
while($rows = mysqli_fetch_array($query)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" value="<?php echo $row['uzid']; ?>"></td>
<td bgcolor="#FFFFFF"><?php echo $rows['uzid']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['pav']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['uzduotis']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Istrinti Uzduotis"></td>
</tr>
<?php
?>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
Welcome to StackOverflow! Generally as a rule of thumb asking to write you some code doesn't get you very far, however I know that some people learn better from seeing it implemented and being able to modify off of that.
There is a number of ways you can do this. Using something like jquery and ajax you can post your requests without having to reload the page. Keep in mind what I have below may not fully work for you since taking the time to do this much already without a database or connection should give you an idea of what you're looking to do. Good luck!
CAUTION: PSUEDO CODE (This may not fully work and is not intended for production) The idea is to show you an approach to achieving what you are looking for.
<?php
include('connect.php');
include('functions.php');
include('title_bar.php');
if(isset($_POST['submit-uzduotis']))
{
$pav = $_POST['pav'];
$uzduotis = $_POST['uzduotis'];
if(empty($pav) or empty($uzduotis))
{
$result = "<span>Privalomi visi langai!</span>";
}
else
{
$sql = ("INSERT INTO uzduotys VALUES ('','$pav','$uzduotis')");
}
if($database->query($sql) == true)
{
header('location:kurtisalinti.php');
}
else
{
$result = "<span>Įvyko klaida!</span>";
}
}
if(isset($_POST['remove']))
{
$id = mysql_real_escape_string($_POST['remove']);
mysqli_query($database, "DELETE FROM uzduotys WHERE uzid = $id");
}
function showTableData()
{
$query = mysqli_query($database, "SELECT uzid, pav, uzduotis FROM uzduotys");
$count = mysqli_num_rows($query);
while($row = mysqli_fetch_array($query))
{
echo '<tr id="'. $row['uzid'] .'">
<td>
<input type="checkbox" name="checkbox[]" value="'. $row['uzid'] .'">
</td>
<td>'. $row['uzid'] .'</td>
<td>'. $row['pav'] .'</td>
<td>'. $row['uzduotis'] .'</td>
<td>
<button id="remove-single" data-id="'. $row['uzid'] .'">REMOVE</button>
</td>
</tr>';
}
}
?>
<html>
<head>
<title>Admin, User</title>
<style>
.uzduotis-table {
background-color: #ccc;
border-collapse: collapse;
}
.uzduotis-table thead > td {
background-color: #333;
font-weight: bold;
}
.uzduotis-table td {
padding: 3px;
text-align: center;
background-color: #fff;
}
label {
display:block;
position:relative;
font-weight: bold;
}
</style>
</head>
<body>
<h3>Sukurti Nauja uzduoti: </h3>
<form method='post'>
<?php echo $result; ?>
<div>
<label>Uzduoties pavadinimas:</label>
<input type='text' name='pav' />
</div>
<div>
<label>Uzduoties:</label>
<textarea name='uzduotis'></textarea>
</div>
<div>
<input type='submit' name='submit-uzduoties' value='Sukurti Uzduoti' />
</div>
</form>
<h3>Pasalinti pasirinkta uzduoti is uzduociu saraso: </h3>
<table class="uzduotis-table">
<thead>
<tr>
<td>#</td>
<td>Id</td>
<td>Pavadinimas</td>
<td>Aprasymas</td>
</tr>
</thead>
<tbody>
<?php showTableData(); ?>
<tr>
<td colspan="5">
<button id="remove-selected" data-id="'. $row['uzid'] .'">REMOVE SELECTED</button>
</td>
</tr>
</tbody>
</table>
<script src="https://code.jquery.com/jquery-2.2.3.min.js" integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo=" crossorigin="anonymous"></script>
<script>
$(document).ready(function(){
// Remove Single (Button)
$('body').on('click', '#remove-single', function() {
remove($(this).data('id'));
});
// Remove All Checked
$('body').on('click', '#remove-selected', function() {
$('.uzduotis-table tr').filter(':has(:checkbox:checked)').each(function() {
remove(this.id);
});
});
function remove(id)
{
console.log("Remove: " + id);
alert('Removing: ' + id);
$.ajax({
type: "POST",
url: '<?php echo $url; ?>',
data: { remove: id },
success: function (data) {
$('#' + id).remove();
}
});
}
})
</script>
</body>
</html>
I cleaned up a bit of the html and styles, just made it easier for me to read. Also I would recommend looking into a library such as PDO to handle your database queries as there currently isn't much in place to protect or safe guard against sql injection.
I have some problem with position off my tables.
here you can see what is looking now:
http://postimg.org/image/auv0lum57/
My controller:
?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Manage_products extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('Products_model');
$this->load->library('form_validation');
}
public function index()
{
session_start();
$this->data['products'] = $this->Products_model->get_all();
$this->data['title'] = 'Product Management';
$this->data['message'] = $this->session->flashdata('message');
$this->load->view('main_view', $this->data);
$this->load->view('manage_products', $this->data);
}
view off manage_products
Products
table, td, th
{
border:1px solid green;
}
th
{
background-color:green;
color:white;
}
#infoMessage p{
padding: .8em;
margin-bottom: 1em;
border: 2px solid #ddd;
background: #FFF6BF;
color: #817134;
border-color: #FFD324;
text-align: center;
}
</style>
</head>
<body>
<table width="700" border="0" align="center">
<tr>
<td><h2>Parduotuvės </h2></td>
</tr>
<tr>
<td><div id="infoMessage"><?php echo $message;?></div></td>
</tr>
<tr>
<td><input name="New" type="button" value="Pridėti naują" onclick="window.location='product/add'" /></td>
</tr>
</table>
<form name="frmproduct" method="post">
<input type="hidden" name="rid" />
<input type="hidden" name="command" />
<table width="700" align="center">
<tr>
<th width="150"><strong>Parduotuvės pavadinimas</strong></th>
<th><strong>Prekės identifikatorius</strong></th>
<th><strong>Nuoroda</strong></th>
<th><strong>Redaguoti</strong></th>
<th><strong>Ištrinti</strong></th>
</tr>
<?php
foreach ($products as $product){
$product_id = $product['id'];
?>
<tr>
<td><?php echo $product['pavadinimas'] ?></td>
<td><?php echo $product['prekesid'] ?></td>
<td><?php echo $product['linkas'] ?></td>
<td><a href='product/edit/<?php echo $product_id ?>'>Redaguoti</a></td>
<td>
<?php
echo anchor('product/delete/'.$product_id, 'Delete', array('onClick' => "return confirm('Ar tikrai norite ištrinti?')"));
?>
</td>
</tr>
<?php
}
?>
</table>
</form>
</body>
</html>
I think problem is with line 22. I must load main_view, but my table must be in main_view, not in bottom. How to fix this problem?
I think I under stood correct try something like
return $this->load->view('name', null, true) or $this->load->view('name', $data, true)
could try and use null or true, return for tables.
This is my code; I will tell you the issue then.
<?php
//checking for perfect loging
session_start();
$user_name = $_SESSION['username'];
$user_pass = $_SESSION['password'];
require ("connection.php");
if ( $user_name == '' ) {
header('location:home.php');
exit();
}
/////////////////////////////////////
?>
<?php
//collecting posted variables by pressing addanother button
if(isset($_POST['adnother'])) {
$date = $_POST['date'];
$billnmbr = $_POST['billnmbr'];
$itemcode = $_POST['itemcode'];
$itemname = $_POST['itemname'];
$exdate = $_POST['exdate'];
$eachprice = $_POST['eachprice'];
$itmtotal = $_POST['itmtotal'];
$wasFound=false;
$i=0;
// check for >>>>>>>>>>> if the session bill_array array is not set or cart array is empty <<<<<<<<<<<<<<<
if(!isset($_SESSION["bill_array"]) || count($_SESSION["bill_array"]) < 1 ) {
// Run if the bill_array is empty or not set
$_SESSION["bill_array"]= array(1 => array("date"=> $date, "billnmbr"=> $billnmbr, "itemcode"=> $itemcode, "itemname"=> $itemname, "exdate"=> $exdate, "eachprice"=> $eachprice, "itmtotal"=> $itmtotal));
} else {
// Run if the bill has at least one item in it
foreach($_SESSION["bill_array"] as $each_item) {
$i++;
while(list($key,$value)=each($each_item)){
if($key=="itemcode" && $value == $itemcode){
// That item is in cart already so push a error message in to screen
$wasFound = true;
?>
<script type="text/javascript">
var error = "<?= $wasFound ?>";
if(error == "true") {
alert("You trying to add same item twice")
}
</script>
<?php
}//close if condition
}//close while loop
}//close foreach loop
//if the next item is not in the bill and then add it to the bill_array
if($wasFound==false){
array_push($_SESSION["bill_array"],array("date"=> $date, "billnmbr"=> $billnmbr, "itemcode"=> $itemcode, "itemname"=> $itemname, "exdate"=> $exdate, "eachprice"=> $eachprice, "itmtotal"=> $itmtotal));
}//clos if condition
}//close else statment
}//close ifisset
?>
<!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>Front-end Billing</title>
<link href="main.css" rel="stylesheet" type="text/css" media="all" />
<style type="text/css">
.mainheder {
font-size: 36px;
font-weight: bolder;
color: #00C;
text-align: center;
}
#headertopic {
position:absolute;
left:304px;
top:1px;
width:395px;
height:44px;
z-index:1;
background-color: #999900;
}
#mainmenue {
position:absolute;
left:208px;
top:78px;
width:614px;
height:48px;
z-index:10000;
}
#dateandtime {
position:absolute;
left:790px;
top:251px;
width:208px;
height:82px;
z-index:1;
}
#redcross {
position:absolute;
left:377px;
top:321px;
width:247px;
height:239px;
z-index:0;
}
#usrlogin {
position:absolute;
left:4px;
top:216px;
width:265px;
height:184px;
z-index:1;
}
#address {
position:absolute;
left:2px;
top:462px;
width:204px;
height:155px;
z-index:2;
}
#logdas {
position:absolute;
left:10px;
top:92px;
width:197px;
height:58px;
z-index:1;
}
.logdas {
font-weight: bold;
color: #00F;
}
#pagetheam {
position:absolute;
left:332px;
top:49px;
width:341px;
height:24px;
z-index:1;
text-align: center;
font-size: 18px;
font-weight: bolder;
color: #0CF;
text-decoration: underline;
}
#billingitems {
position:absolute;
left:11px;
top:186px;
width:489px;
height:293px;
z-index:1;
}
#printlayout {
position:absolute;
left:531px;
top:186px;
width:211px;
height:322px;
z-index:1;
text-align: center;
}
.printlayoutshopname {
font-size: 14px;
font-weight: bold;
color: #000;
}
.billaddrs {
font-size: 10px;
}
.bilnmbr {
font-size: 10px;
font-weight: bold;
text-align: left;
}
</style></head>
<body>
<div id="wrap">
<div id="headertopic" class="mainheder">Accoutnig for Phamacy</div>
<p> </p>
<p> </p>
<div id="mainmenue"> <?php // include 'index.html' ;?> </div>
<div id="logdas"><p class="logdas">Logged in as : <?php echo $user_name; ?></p>
<p class="logdas">Date : <?php echo date("Y-m-d") ?></p>
</div>
<div id="pagetheam">Front-end Billing </div>
<div id="billingitems">
<form id="form1" name="form1" method="post" action="biling.php">
<?php $data = mysql_query("SELECT * FROM billnumber ") ;
$info = mysql_fetch_array( $data );
$oldnumber = $info['bill_number'];
$oldnumber= $oldnumber + 1;
$Transaction_number = "PM". $oldnumber ;
?>
<table width="490" height="282" border="0">
<tr>
<td width="160"><input type="hidden" name="date" id="date" value=" <?php echo date("Y-m-d") ?> " /><?php echo date("Y-m-d") ?></td>
<td width="47"> </td>
<td width="69"> </td>
</tr>
<tr>
<td width="206">Bill Number</td>
<td width="160"><input type="hidden" name="billnmbr" id="billnmbr" value="<?php echo $Transaction_number; ?>" /><?php echo $Transaction_number; ?></td>
<td width="47"> </td>
<td width="69"> </td>
</tr>
<tr>
<td>Item Code</td>
<td><input type="text" name="itemcode" id="itemcode" tabindex="1" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Item Name</td>
<td><input type="text" name="itemname" id="itemname" tabindex="2" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Expier Date</td>
<td><input type="text" name="exdate" id="exdate" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Item Price</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>Each :
<input type="text" name="eachprice" id="eachprice" /></td>
<td>Total :
<input type="text" name="itmtotal" id="itmtotal" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="adnother" id="adnother" value="add another item" tabindex="5" /></td>
<td><input type="submit" name="submit" id="submit" value="Submit" /></td>
<td> </td>
</tr>
</table>
</form>
</div>
<div id="printlayout">
<p><span class="printlayoutshopname">Yasitha Pharacy<br />
</span><span class="billaddrs">22,Colombathanthiri Mawatha, Ethulkotte, Kotte.</span></p>
<table width="211" border="0">
<tr>
<td width="103"><span class="bilnmbr">Bill No: <?php echo $Transaction_number; ?></span></td>
<td colspan="2" class="bilnmbr">Date: <?php echo date("Y-m-d") ?></td>
</tr>
<?php
if(isset($_POST['adnother'])) {
//taking items in the bill to variables if the bill_array is not empty.
$cartOutput="";
if(!isset($_SESSION["bill_array"]) || count($_SESSION["bill_array"]) < 1 ) {
$cartOutput = "<h2 align='center'> Bill is still empty </hd>";
}
else {
$i = 0;
foreach ($_SESSION["bill_array"]as $each_item ): ?>
<tr>
<td class="bilnmbr">Item code: </td>
<td colspan="2" class="bilnmbr"><?php echo $each_item['itemcode']; ?></td>
</tr>
<tr>
<td colspan="3" class="bilnmbr">Item Name:</td>
</tr>
<tr>
<td colspan="3" class="bilnmbr"><?php echo $each_item['itemname']; ?></td>
</tr>
<tr class="bilnmbr">
<td>Each</td>
<td width="98">Qty</td>
<td width="98">Total</td>
</tr>
<tr class="bilnmbr">
<td><?php echo $each_item['eachprice']; ?></td>
<td>20</td>
<td><?php echo $each_item['itmtotal']; ?></td>
</tr>
</table>
<?php endforeach; ?>
<?php
}
}
////////////////////////////////////////
?>
<p>
</p>
</div>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<?php //closing div for wrapper?>
</div>
</body>
</html>
I used two dimensional array for insert item details to a session array, after inserting a item I want its details to be displayed in a separate table (right hand side) there is no problem with one item, when I add a item it is viewing in the perfect place, but when I add the second item it is going under that table without creating new row. What is the wrong with what I had done?
I found my error
i ended my foreach loop like this
</tr>
</table>
<?php endforeach;
}
}
////////////////////////////////////////
?>
but now i corrected to this way
</tr>
<?php endforeach;
}
}
////////////////////////////////////////
?>
</table>
now it's all ok.... thank you guys for wasting your time for my silly mistake... sorry.... :(
I just can't get my variables to carry over to the next page. The variable assignment works fine on the initial page (tested), but the value goes null when going to the next. Plz Help!
Page 1:
<?PHP session_start(); ?>
<HTML>
<HEAD>
<META NAME='robots' CONTENT='noindex,nofollow'>
<TITLE>Master Chief's Gamestore</TITLE>
<STYLE type="text/css">
BODY {
color: #ffffff;
background: url('~/halo-reach.jpg');
background-repeat: no-repeat;
background-position: top;
background-color: black;
}
</STYLE>
</HEAD>
<body vLink='#3366CC' link='#3366CC' alink='#3366CC'>
<br/><br/><br/><br/><br/>
<table width='100%' height='80%'>
<tr>
<td align='center' valign='middle'>
<table width="50%" cellspacing="0" cellpadding="25" border="0">
<form method="post">
<tr bgcolor="#666633">
<th id="header" align="left" colspan="3">
<DIV align="center">
<font face="Verdana, Arial, Helvetica" color="white" size="3">
Master Chief's Gamestore </font>
</DIV>
</th>
</tr>
<tr bgcolor="#A3A385">
<td width="100%" valign="middle" colspan="2">
<font face="Verdana, Arial, Helvetica" size="2">
<div align="center"><br/><br/>
Username: 
<input type="text" name="username"> 
Password: 
<input type="password" name="password"><br/>
<br/><input type="submit" name="act" value="Login"><br/>
<input type="submit" name="act" value="Register"><br/>
<input type="submit" name="act" value="Main"><br/> <br/><br/>
</div>
</font>
</td>
</tr>
<?PHP
if ($_POST['act'] == "Login") {
mysql_connect("~", "~", "~") or die("unable to connect to server");
mysql_select_db("~") or die("unable to select database");
$user = $_POST['username'];
$pass = $_POST['password'];
$query = "select * from users where user like '%" . $user . "%' and pass like '%" . $pass . "%';";
$result = mysql_query($query);
$rows = mysql_numrows($result);
if ($rows == 0 || strlen($user) == 0) {
echo "<br />Login Failure";
} else {
$_SESSION['user'] = mysql_result($result, 0, "user");
$_SESSION['id'] = mysql_result($result, 0, "P_Id");
header('Location: ~/success.php');
}
}
if ($_POST['act'] == "Register") {
header('Location: ~/register.php');
}
if ($_POST['act'] == "Main") {
header('Location: ~/index.php');
}
?>
<div align="center">
<tr bgcolor="#666633">
<td align="left">
Logged in as:
<?PHP
$user = $_SESSION['user'];
if (!$user) {
$user = 'Guest';
}
echo $user;
?>
</td>
<td align="right">
Password: 
<input type="password" name="srcpw">
<input type="submit" name="dspphp" value="Display PHP">
</td>
</tr>
</div>
</form>
</table>
</td>
</tr>
</table>
</body>
</html>
Page 2:
<?PHP session_start(); ?>
<HTML>
<HEAD>
<META NAME='robots' CONTENT='noindex,nofollow'>
<TITLE>Master Chief's Gamestore</TITLE>
<STYLE type="text/css">
BODY {
color: #ffffff;
background: url('~/halo-reach.jpg');
background-repeat: no-repeat;
background-position: top;
background-color: black;
}
</STYLE>
</HEAD>
<body vLink='#3366CC' link='#3366CC' alink='#3366CC'>
<br/><br/><br/><br/><br/>
<table width='100%' height='80%'>
<tr>
<td align='center' valign='middle'>
<table width="30%" cellspacing="0" cellpadding="25" border="0">
<form method="post">
<tr bgcolor="#666633">
<th id="header" align="left" colspan="3">
<DIV align="center">
<font face="Verdana, Arial, Helvetica" color="white" size="3">
Master Chief's Gamestore </font>
</DIV>
</th>
</tr>
<tr bgcolor="#A3A385">
<td width="100%" valign="middle" colspan="2">
<font face="Verdana, Arial, Helvetica" size="2">
<div align="center">
<br/><br/>Success<br/><br/>
<input type='submit' name='main' value='Main'>
<?PHP
if ($_POST['main'] == "Main") {
header('Location: http://~/index.php');
}
if ($_POST['act'] == "Display Code") {
if ($_POST['pw'] == "pass") {
highlight_file("success.php");
}
}
?>
</div>
</font>
</td>
</tr>
<div align="center">
<tr bgcolor="#666633">
<td align="left">
Logged in as:
<?PHP
$user = $_SESSION['user'];
if (!$user)
$user = 'Guest';
echo $user;
?>
</td>
<td align="right">
Password: 
<input type="password" name="pw">
<input type="submit" name="dspphp" value="Display PHP">
</td>
</tr>
</div>
</form>
</table>
</td>
</tr>
</table>
</body>
</html>
EDIT: I've tried this sample code and it does NOT work.
Page 1:
<?php
session_start();
if (isset($_GET['link'])) {
$_session['myvariable'] = 'Hello World';
header('Location: http://' . $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']) . '/page2.php');
exit;
}
?>
Click Here
Page 2:
<?php
session_start();
print 'Here is page two, and my session variable: ';
print $_session['myvariable'];
exit;
?>
But as I posted below, I have used sessions in other pages successfully on the same server. Soo frustrating....
Thanks for all the posts btw!
Make sure cookies are enabled so the second page actually re-creates the session of the first page instead of creating a new, empty one. Check out http://www.php.net/manual/en/session.idpassing.php for details.
EDIT
Another possible cause for sessions not working as expected, especially if it only affects certain pages, is that you have accidental whitespace or other output before your first 'session_start() error
It looks like you are just redirecting the user to the second page without posting anything. You would want to set hidden variables and actually submit your form to the second page. Re-directing will lose all the post variables.
If you want to send variables to the second page with a redirect, you can use session variables or a GET variable passed in with the URL to the second page.
Try using
$_SESSION['myvariable'] = 'Hello World';
in upper case
<?php
session_start();
require_once('recaptcha/recaptchalib.php');
$publickey = "API_KEY"; // you got this from the signup page
?>
<script type="text/javascript" src="javascripts/jquery.form.js"></
script>
<script type="text/javascript">
$(document).ready(function() {
$('#inquiry').ajaxForm({
target: '#error',
success: function() {
$('#error').fadeIn('slow');
}
});
});
var RecaptchaOptions = {
theme : 'clean'
};
</script>
<div class="top_area">Inquiry Form</div>
<div id="search_area">
</div>
<div style="overflow-y: hidden;">
<form name="inquiry" id="inquiry" action="asadadasd.php"
method="post">
<div id="error"></div>
<table align="center">
<tr>
<td valign="top" align="right"></td>
<td>
<?php
echo recaptcha_get_html($publickey);
?>
</td>
</tr>
<tr>
<td valign="top"></td>
<td>
<input type="submit" id="submit" name="submit" value="Submit"
style="height: 30px; background: #ab2220; border: 2px #fff solid;
color: #fff;" />
</td>
</tr>
</table>
</form>
</table>
</form>
</div>
That's the code I have as of now but recaptcha plugin doesn't show up
am I missing something?
Thanks guys,
You are so awesome
You have to use the recaptcha AJAX API on facebox. Include the AJAX script in your page (Not the page facebox will display. Put it in the containing page) Then use the recaptcha api as specified in the docs.
http://code.google.com/apis/recaptcha/docs/display.html#AJAX