print_r($_REQUEST) is not showing all the datas after redirecting from a page from which form is being submitted. In the redirected page it is showing some datas but not all.In the localhost all the requested datas are showing fine,but in the server the problem is occurring.
I have created a php.ini & put max_execution_time = 160; post_max_size = 250M; into the file & uploaded it in the server. But still couldn't get any solution.
Here is code. Actually some page are included after checking condition and then the form is being submitted after filling fields.
include("configuration.php");
if(isset($_REQUEST["save_update"]) && $_REQUEST["save_update"]!="")
{
include("quotation_save.php");
header("location:http://mpsinfoservices.com/projects/topline/quotation.php?enquiry_id=".$_REQUEST["enquiry_id"]."&displaying_id=".$_REQUEST["displaying_id"]);
}
$enqid = $_REQUEST["enquiry_id"];
$displaying_id = $_REQUEST["displaying_id"];
$len_of_disp = strlen($displaying_id);
/*if(preg_match('/E/',$displaying_id))
{
echo substr($displaying_id,0,6);
echo "<br/>".substr($displaying_id,strlen(substr($displaying_id,0,6)));
if(preg_match('/F/',substr($displaying_id,strlen(substr($displaying_id,0,6)))))
$ch_from_find_str = 'F';
$find_str = substr($displaying_id,0,7);
$ch_from_find_str = substr($find_str,6,1);
}
if(preg_match('/PKG/',$displaying_id))
{
$find_str = substr($displaying_id,0,9);
echo $find_str;
}
*/
$sql_enquiry = mysql_query("SELECT * FROM `enquiry_master` WHERE `id`='".$enqid."' AND `displaying_id`='".$displaying_id."'");
$row_enquiry = mysql_fetch_assoc($sql_enquiry);
$sql_client_info = mysql_query("SELECT * FROM `client_info` WHERE `client_id`='".$row_enquiry['customer_id']."'");
$row_client_info = mysql_fetch_assoc($sql_client_info);
?>
<link type="text/css" href="css/cupertino/jquery-ui-1.8.21.custom.css" rel="stylesheet" />
<link type="text/css" href="css/jquery.dataTables_themeroller.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.21.custom.min.js"></script>
<script type="text/javascript" src="js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="js/function.js"></script>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<link type="text/css" href="css/style.css" rel="stylesheet">
<style>
.client_name
{
border:none;
}
.client_name_mouseover
{
border:1px solid #000;
}
</style>
</head>
<body>
<?php include("includes/header.php"); ?>
<div id="page-container">
<?php
include("includes/left_menu.php");
?>
<div id="page_content" style="float:left;">
<div style="margin-top:25px;">
<div style="padding-top:10px;">
<div style="color:#000;font-weight:bold;font-size:12px;font-family:verdana;">Client Details</div>
<div>Name:- <input type="text" name="client_name" id="client_name" class="client_name" value="<?php echo $row_client_info["client_firstname"].$row_client_info["client_middlename"].$row_client_info["client_lastname"];?>" readonly="readonly"/></div>
<div>Email:- <?php echo $row_client_info["client_email_id"]; ?>
</div>
<div>
<?php
$sql_quotation_insert_status = mysql_query("SELECT `status` FROM `quotation_insert_status` WHERE `enquiry_id`='".$enqid."'");
if( mysql_num_rows($sql_quotation_insert_status)>0)
{
$res_quotation_insert_status = "insert";
}
else
{
$res_quotation_insert_status = "";
}
?>
<form name="quotation" class="quotationfrm" method="post" enctype="multipart/form-data" action="quotation.php">
<input type="hidden" name="displaying_id" value="<?php echo $displaying_id; ?>"/>
<input type="hidden" name="enquiry_id" value="<?php echo $enqid; ?>"/>
<input type="hidden" name="save_update" <?php if($res_quotation_insert_status=="insert"){?>value="update" <?php } if($res_quotation_insert_status==""){?> value="save_quotation" <?php } ?>/>
<?php
if(preg_match('/E/',$displaying_id))
{
if(preg_match('/F/',substr($displaying_id,strlen(substr($displaying_id,0,6)))))
{
include("quotation/flight_quotation.php");
}
if(preg_match('/T/',substr($displaying_id,strlen(substr($displaying_id,0,6)))))
{
include("quotation/train_quotation.php");
}
if(preg_match('/H/',substr($displaying_id,strlen(substr($displaying_id,0,6)))))
{
include("quotation/hotel_quotation2.php");
}
if(preg_match('/CC/',substr($displaying_id,strlen(substr($displaying_id,0,6)))))
{
include("quotation/carrental_quotation.php");
}
if(preg_match('/I/',substr($displaying_id,strlen(substr($displaying_id,0,6)))))
{
include("quotation/insurance_quotation.php");
}
if(preg_match('/V/',substr($displaying_id,strlen(substr($displaying_id,0,6)))))
{
include("quotation/visa_quotation.php");
}
if(preg_match('/CR/',substr($displaying_id,strlen(substr($displaying_id,0,6)))))
{
include("quotation/cruise_quotation.php");
}
}
if(preg_match('/PKG/',$displaying_id))
{
if(preg_match('/H/',substr($displaying_id,strlen(substr($displaying_id,0,7)))))
{
include("quotation/hotel_quotation2.php");
}
include("quotation/package_quotation.php");
if(preg_match('/F/',substr($displaying_id,strlen(substr($displaying_id,0,7)))))
{
include("quotation/flight_quotation.php");
}
if(preg_match('/V/',substr($displaying_id,strlen(substr($displaying_id,0,7)))))
{
include("quotation/visa_quotation.php");
}
if(preg_match('/T/',substr($displaying_id,strlen(substr($displaying_id,0,7)))))
{
include("quotation/train_quotation.php");
}
if(preg_match('/CC/',substr($displaying_id,strlen(substr($displaying_id,0,7)))))
{
include("quotation/carrental_quotation.php");
}
if(preg_match('/I/',substr($displaying_id,strlen(substr($displaying_id,0,7)))))
{
include("quotation/insurance_quotation.php");
}
if(preg_match('/CR/',substr($displaying_id,strlen(substr($displaying_id,0,7)))))
{
include("quotation/cruise_quotation.php");
}
}
?>
<input type="button" class="save_quotation" <?php if($res_quotation_insert_status=="insert"){?> value="Update" <?php } if($res_quotation_insert_status==""){ ?> value="Save The Quotation" <?php } ?> style="margin-top:20px;" <?php if($res_quotation_insert_status=="insert"){ ?> name="save" <?php } if($res_quotation_insert_status==""){ ?> name="update" <?php } ?>/>
<?php if($res_quotation_insert_status=="insert"){?>
<input type="button" class="sendQuotation" value="Send Quotation"/>
<?php
}
?>
</form>
</div>
</div>
<script>
$(function(){
var no=0;
$("form").each(function(){
no++;
});
var suc = 0;
$("#client_name").live("mouseover",function(){
$(this).removeClass("client_name");
$(this).addClass("client_name_mouseover");
});
$("#client_name").live("mouseout",function(){
$(this).removeClass("client_name_mouseover");
$(this).addClass("client_name");
});
$(".mail_to_client").live("click",function(){
$.post("flight_quotation_mail.php?enquiry_id=<?php echo $enqid; ?>",$(".flight_quotation_frm").serialize(),function(data){
if(data=="success")
{
suc++;
}
if(no==suc)
{
$.post("mail_to_client.php?enquiry_id=<?php echo $enqid; ?>");
}
});
$.post("train_quotation_mail.php?enquiry_id=<?php echo $enqid; ?>",$(".train_quotation_frm").serialize(),function(data){
if(data=="success")
{
suc++;
}
if(no==suc)
{
$.post("mail_to_client.php?enquiry_id=<?php echo $enqid; ?>");
}
});
/*$.post("hotel_quotation_mail.php?enquiry_id=<?php echo $enqid; ?>",$(".hotel_quotation_frm").serialize(),function(data){
if(data=="success")
{
suc++;
}
if(no==suc)
{
$.post("mail_to_client.php?enquiry_id=<?php echo $enqid; ?>");
}
});*/
});
$(".save_quotation").live("click",function(){
$(".quotationfrm").submit();
});
$(".sendQuotation").live("click",function(){
for(var instanceName in CKEDITOR.instances)
CKEDITOR.instances[instanceName].updateElement();
var formData = $(".quotationfrm").serialize();
$.post("quotation_pdf.php",function(){
window.open("quotation_pdf.php?"+formData);
});
});
});
</script>
In some cases due to html elements in the data it will render only few, try checking View Source of that page.
The content and order of $_REQUEST is affected by variables_order directive in php.ini (see Description of core php.ini directives)
So, it is possible, that on your production environment value of variables-order directive differs from that in your development environment (localhost).
For example, set variables_order = "GPCS" in order to have G-$_GET, P-$_POST, C-$_COOKIE, S-$_SERVER arrays and all values from that arrays in $_REQUEST.
Related
So I have a chatting site in PHP, but the problem is that anyone can access any "chatroom". Is there a way to add an "Enter passcode" text box to the site before they are able to access the real thing? And if possible I would prefer not using those JavaScript pop-ups. And for the people who really want to help, I don't need any CSS.
My code:
index.php:
<?php
session_start();
if(isset($_GET['logout'])){
//Simple exit message
$logout_message = "<div class='msgln'><span class='left-info'>User <b class='user-name-left'>". $_SESSION['name'] ."</b> has left the chat session.</span><br></div>";
file_put_contents("log.html", $logout_message, FILE_APPEND | LOCK_EX);
session_destroy();
header("Location: ../../index.php"); //Redirect the user
}
if(isset($_POST['enter'])){
if($_POST['name'] != ""){
$_SESSION['name'] = stripslashes(htmlspecialchars($_POST['name']));
}
else{
echo '<span class="error">Please type in a name</span>';
}
}
function loginForm(){
echo
'<div id="loginform">
<p>Please enter your name to continue!</p>
<form action="index.php" method="post">
<label for="name">Name —</label>
<input type="text" name="name" id="name" />
<input type="submit" name="enter" id="enter" value="Enter" />
</form>
</div>';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title> Chat</title>
<meta name="description" content=" Chat Application" />
<link rel="stylesheet" href="../../css/chat.css" />
</head>
<body>
<?php
if(!isset($_SESSION['name'])){
loginForm();
}
else {
?>
<div id="wrapper">
<div id="menu">
<p class="welcome">Welcome, <b><?php echo $_SESSION['name']; ?></b></p>
<p class="logout"><a id="exit" href="#">Exit Chat</a></p>
</div>
<div id="chatbox">
<?php
if(file_exists("log.html") && filesize("log.html") > 0){
$contents = file_get_contents("log.html");
echo $contents;
}
?>
</div>
<form name="message" action="">
<input name="usermsg" type="text" id="usermsg" />
<input name="submitmsg" type="submit" id="submitmsg" value="Send" />
</form>
</div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript">
// jQuery Document
$(document).ready(function () {
$("#submitmsg").click(function () {
var clientmsg = $("#usermsg").val();
$.post("post.php", { text: clientmsg });
$("#usermsg").val("");
return false;
});
function loadLog() {
var oldscrollHeight = $("#chatbox")[0].scrollHeight - 20; //Scroll height before the request
$.ajax({
url: "log.html",
cache: false,
success: function (html) {
$("#chatbox").html(html); //Insert chat log into the #chatbox div
//Auto-scroll
var newscrollHeight = $("#chatbox")[0].scrollHeight - 20; //Scroll height after the request
if(newscrollHeight > oldscrollHeight){
$("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div
}
}
});
}
setInterval (loadLog, 2500);
$("#exit").click(function () {
var exit = confirm("Are you sure you want to end the session?");
if (exit == true) {
window.location = "index.php?logout=true";
}
});
});
</script>
</body>
</html>
<?php
}
?>
post.php:
<?php
session_start();
if(isset($_SESSION['name'])){
$text = $_POST['text'];
$text_message = "<div class='msgln'><span class='chat-time'>".date("g:i A")."</span> <b class='user-name'>".$_SESSION['name']."</b> ".stripslashes(htmlspecialchars($text))."<br></div>";
file_put_contents("log.html", $text_message, FILE_APPEND | LOCK_EX);
}
?>
At the moment I have a form (PHP & jQuery) with validations. I want to add a validation to check if the email address of a new user is already in the MySQL database or not.
At the moment there are 3 (IF) validations already for the name and email in jQuery:
function validate() {
var output = true;
$(".signup-error").html('');
if($("#personal-field").css('display') != 'none') {
if(!($("#name").val())) {
output = false;
$("#name-error").html("Name required!");
}
if(!($("#email").val())) {
output = false;
$("#email-error").html("Email required!");
}
if(!$("#email").val().match(/^([\w-\.]+#([\w-]+\.)+[\w-]{2,4})?$/)) {
$("#email-error").html("Invalid Email!");
output = false;
}
I would like to have a 4th one to check if the email address is already in the MySQL database.
The complete PHP file with jQuery:
<?php
include 'db_connection.php';
if(isset($_POST['finish'])){
$name = '"'.$dbConnection->real_escape_string($_POST['name']).'"';
$email = '"'.$dbConnection->real_escape_string($_POST['email']).'"';
$password = '"'.password_hash($dbConnection->real_escape_string($_POST['password']), PASSWORD_DEFAULT).'"';
$gender = '"'.$dbConnection->real_escape_string($_POST['gender']).'"';
$sqlInsertUser = $dbConnection->query("INSERT INTO users (name, password, email, gender) VALUES($name, $password, $email, $gender)");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" href="css/reset.css" />
<link rel="stylesheet" href="css/text.css" />
<link rel="stylesheet" href="css/960.css" />
<link rel="stylesheet" href="css/demo.css" />
<script src="scripts/jquery-1.10.2.js"></script>
<style>
CSS CODE
</style>
<script>
function validate() {
var output = true;
$(".signup-error").html('');
if($("#personal-field").css('display') != 'none') {
if(!($("#name").val())) {
output = false;
$("#name-error").html("Name required!");
}
if(!($("#email").val())) {
output = false;
$("#email-error").html("Email required!");
}
if(!$("#email").val().match(/^([\w-\.]+#([\w-]+\.)+[\w-]{2,4})?$/)) {
$("#email-error").html("Invalid Email!");
output = false;
}
}
if($("#password-field").css('display') != 'none') {
if(!($("#user-password").val())) {
output = false;
$("#password-error").html("Password required!");
}
if(!($("#confirm-password").val())) {
output = false;
$("#confirm-password-error").html("Confirm password required!");
}
if($("#user-password").val() != $("#confirm-password").val()) {
output = false;
$("#confirm-password-error").html("Password not matched!");
}
}
return output;
}
$(document).ready(function() {
$("#next").click(function(){
var output = validate();
if(output) {
var current = $(".active");
var next = $(".active").next("li");
if(next.length>0) {
$("#"+current.attr("id")+"-field").hide();
$("#"+next.attr("id")+"-field").show();
$("#back").show();
$("#finish").hide();
$(".active").removeClass("active");
next.addClass("active");
if($(".active").attr("id") == $("li").last().attr("id")) {
$("#next").hide();
$("#finish").show();
}
}
}
});
$("#back").click(function(){
var current = $(".active");
var prev = $(".active").prev("li");
if(prev.length>0) {
$("#"+current.attr("id")+"-field").hide();
$("#"+prev.attr("id")+"-field").show();
$("#next").show();
$("#finish").hide();
$(".active").removeClass("active");
prev.addClass("active");
if($(".active").attr("id") == $("li").first().attr("id")) {
$("#back").hide();
}
}
});
});
</script>
</head>
<body>
<div class="container_12">
<div class="grid_8">
<p>
TEXT<br>TEXT<br>TEXT<br>TEXT<br>TEXT
</p>
</div>
<div class="grid_4">
<p>Register new FC Magnate</p>
<div class="message"><?php if(isset($message)) echo $message; ?></div>
<ul id="signup-step">
<li id="personal" class="active">Personal Detail</li>
<li id="password">Password</li>
<li id="general">General</li>
</ul>
<form name="frmRegistration" id="signup-form" method="post">
<div id="personal-field">
<label>Name</label><span id="name-error" class="signup-error"></span>
<div><input type="text" name="name" id="name" class="demoInputBox"/></div>
<label>Email</label><span id="email-error" class="signup-error"></span>
<div><input type="text" name="email" id="email" class="demoInputBox" /></div>
</div>
<div id="password-field" style="display:none;">
<label>Enter Password</label><span id="password-error" class="signup-error"></span>
<div><input type="password" name="password" id="user-password" class="demoInputBox" /></div>
<label>Re-enter Password</label><span id="confirm-password-error" class="signup-error"></span>
<div><input type="password" name="confirm-password" id="confirm-password" class="demoInputBox" /></div>
</div>
<div id="general-field" style="display:none;">
<label>Gender</label>
<div>
<select name="gender" id="gender" class="demoInputBox">
<option value="female">Female</option>
<option value="male">Male</option>
</select></div>
</div>
<div>
<input class="btnAction" type="button" name="back" id="back" value="Back" style="display:none;">
<input class="btnAction" type="button" name="next" id="next" value="Next" >
<input class="btnAction" type="submit" name="finish" id="finish" value="Finish" style="display:none;">
</div>
</form>
</div>
The "db_connection.php" file:
<?php
define('_HOST_NAME', 'localhost');
define('_DATABASE_USER_NAME', 'root');
define('_DATABASE_PASSWORD', '****');
define('_DATABASE_NAME', '****');
$dbConnection = new mysqli(_HOST_NAME, _DATABASE_USER_NAME, _DATABASE_PASSWORD, _DATABASE_NAME);
if ($dbConnection->connect_error) {
trigger_error('Connection Failed: ' . $dbConnection->connect_error, E_USER_ERROR);
}
?>
I tried to create this validation from other examples that were given here on the website. But, no success. Please, it would be great if somebody could help me a little further.
UPDATE: With the help of Suyog I changed the files. But, it doesn't seem to work yet. Here are the files that I use at the moment: fcmagnate.com/files.zip
The form works till the moment the validation of the email address in the database starts, than it stops.
You will have to make use of JQuery AJAX for this.
Write a function in AJAX to send email to php gage where we will check the existance of email.
<script>
function checkEmail(eMail)
{
$.ajax({
url: 'check_email.php',
data: {emailId: eMail},
type: 'post',
success: function (data) {
if(data == '1')
return false;
else
return true;
}
});
}
</script>
Then you can call this function
<script>
function validate()
{
var output = true;
$(".signup-error").html('');
if($("#personal-field").css('display') != 'none')
{
if(!($("#name").val()))
{
output = false;
$("#name-error").html("Name required!");
}
if(!($("#email").val()))
{
output = false;
$("#email-error").html("Email required!");
}
if(!$("#email").val().match(/^([\w-\.]+#([\w-]+\.)+[\w-]{2,4})?$/))
{
$("#email-error").html("Invalid Email!");
output = false;
}
if(!checkEmail($("#email").val()))
{
$("#email-error").html("Email already exist!");
output = false;
}
}
}
</script>
Youe check_email.php file will contain the code as follows
<?php
include 'db_connection.php';
if(isset($_POST['emailId']))
{
$email = '"'.$dbConnection->real_escape_string($_POST['emailId']).'"';
$sqlCheckEmail = $dbConnection->query("SELECT user_id FROM users WHERE LOWER(email) like LOWER('%".$email."%')");
if($sqlCheckEmail->num_rows == 1)
echo '1';
else
echo '0';
}
?>
Use Ajax jQuery.ajax on client side to communicate with server side reusing your php code mentioned.
I need help to convert this code to codeigniter MVC
i have 2 file php
index.php for viewer and cari_barang.php for model
i have problem with file controller, I dont know how to get value post with ajax.
this my PHP code index.php
<html>
<head>
<script type="text/javascript" src="jquery-1.11.2.js"></script>
<script type='text/javascript' src='jquery.autocomplete.js'></script>
<script type="text/javascript">
$(document).ready(function() {
$("#barang").keyup(function() {
var kode = $('#barang').val();
$.ajax({
type : "POST",
data : "kode="+kode,
url : "cari_barang.php",
dataType: "json",
success: function(data){
$("#namabarang").val(data.namabarang);
$("#hargabeli").val(data.hargabeli);
}
});
});
});
</script>
</head>
<body>
<div class="demo" style="width: 450px;">
<div>
<p>Kode Barang : <input type="text" id="barang" value="0001"></p>
<p>Nama Barang : <input type="text" id="namabarang" size="50" disabled></p>
<p>Harga Beli : <input type="text" id="hargabeli" size="15" align="right" disabled></p>
</div>
</div>
</body>
</html>
this code for cari_barang.php
<?php
mysql_connect("localhost","root","");
mysql_select_db("barang");
$kode = $_POST['kode'];
$sql = mysql_query("select * from tbbarang where kodebarang='$kode'");
$row = mysql_num_rows($sql);
if($row>0){
$r = mysql_fetch_array($sql);
$data['namabarang'] = $r['namabarang'];
$data['hargabeli'] = $r['hargabeli'];
echo json_encode($data);
}else{
$data['namabarang'] = '';
$data['hargabeli'] = '';
echo json_encode($data);
}
?>
thanks before
have a look on codeigniter website http://www.codeigniter.com/userguide3/ hope you will find your solution.
if you convert your above code to codeigniter then its only a view file of codeigniter.
thanks all for answer,my problem solved with this code
Model :
public function get($kode)
{
$this->db->where('kodebarang',$kode);
$query = $this->db->get('tbbarang');
if ($query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
$data['namabarang'] = $row->namabarang;
$data['hargabeli'] = $row->hargabeli;
echo json_encode($data);
}
} else {
$data['namabarang'] = '';
$data['hargabeli'] = '';
echo json_encode($data);
}
}
Controller :
public function view()
{
$this->load->model('m_barang');
$kode = $this->input->post('kode');
//#$kode = $_POST['kode'];
$data = $this->m_barang->get($kode);
}
View :
<html>
<head>
<script type='text/javascript' src='<?php echo base_url("jquery-1.11.2.js");?>'></script>
<script type='text/javascript' src='<?php echo base_url("jquery.autocomplete.js");?>'></script>
<!-- <link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />
<link rel="stylesheet" href="main.css" type="text/css" /> -->
<script type="text/javascript">
$(document).ready(function() {
$("#barang").keyup(function() {
var kode = $('#barang').val();
$.ajax({
type : "POST",
data : "kode="+kode,
url : "<?=base_url('barang/view')?>",
dataType: "json",
success: function(data){
$("#namabarang").val(data.namabarang); //$r['namabarang']
$("#hargabeli").val(data.hargabeli); //$r['hargabeli']
}
});
});
});
</script>
</head>
<body>
<div class="demo" style="width: 450px;">
<div>
<p>Kode Barang : <input type="text" id="barang" value=""></p>
<p>Nama Barang : <input type="text" id="namabarang" size="50" disabled></p>
<p>Harga Beli : <input type="text" id="hargabeli" size="15" align="right" disabled></p>
</div>
</div>
<p class="footer" ><?php echo base_url();?></p>
<p class="footer" ><?php echo site_url();?></p>
<p class="footer" ><?php echo base_url('barang/view');?></p>
</body>
</html>
I made an upload page and php script for it that is an AJAX script but i'm getting some errors in Firebug and my upload percentage isn't being returned, so far i am only able to do one upload in firefox and the script won't even work in chrome.
here is my code:
<?php
session_start();
include ('../Connect/Connect.php');
$User = $_SESSION['User'];
if(isset($User))
{
}
else
{
header("location:../");
}
$Connect -> close();
?>
<!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>
<link rel="stylesheet" href="../StyleSheets/StyleSheet.css" />
<link rel="stylesheet" href="../JQueryUI/css/black-tie/jquery-ui-1.10.1.custom.min.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TeraShare</title>
<script type="text/javascript" src="../JQuery/JQuery.js"></script>
<script type="text/javascript" src="../JQueryUI/js/jquery-ui-1.10.1.custom.min.js"></script>
<script type="text/javascript" src="../Scripts/JavaScript.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
var UploadB = $('#Submit');
UploadB.click(function(event)
{
event.preventDefault();
event.stopPropagation();
var Data = new FormData();
var Files = document.getElementById('Files');
for(var I = 0; I < Files.files.length; ++I)
{
var FilesName = Files.files[I].name;
Data.append('File[]', Files.files[I]);
}
var Request = XMLHttpRequest();
Request.upload.addEventListener('progress', function(event)
{
if(event.lengthComputable)
{
var Percent = event.loaded / event.total;
Progress = document.getElementById('#Progress');
while(Progress.hasChildNodes())
{
Progress.removeChild(Progress.firstChild);
}
Progress.appendChild(document.createTextNode(Math.round(Percent * 100) + '%'));
}
});
Request.upload.addEventListener('load', function(event)
{
Progress.style.display = 'none';
});
Request.upload.addEventListener('error', function(event)
{
alert('Upload Failed.');
});
Request.open('POST', 'Upload.php');
Request.setRequestHeader('Cache-Control', 'no-cache');
Progress.style.display = 'block';
Request.send(Data);
});
});
</script>
</head>
<body>
<div id="Wrapper">
<div id="Menu">
<div id="Logo"><img src="../Pictures/Logo.png" /></div>
<div id="Buttons">
<div class="Button" title="LogOut">LogOut</div>
<div class="Button" id="Upload" title="Upload">Upload</div>
<div class="Button" id="CFolder" title="Upload">Create Folder</div>
<div class="Button" id="Store" title="Store">Store</div>
<div class="Button" title="Menu"><?php echo $User; ?> <span class="Triangle"></span></div>
</div>
</div>
<div id="Content">
<div id="Fix">
<div id="UForm">
<form action="" method="post" enctype="multipart/form-data">
<input type="file" id="Files" name="File[]" multiple="multiple" />
<input type="submit" name="Submit" class="AB" id="Submit" value="Upload!" />
<div id="Progress"></div>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
php script:
<?php
session_start();
include('../Connect/Connect.php');
$User = $_SESSION['User'];
$Token = $_POST['Token'];
$Files = $_FILES['File'];
if(isset($User))
{
if(!empty($Files))
{
for($X = 0; $X < count($Files['name']); $X++)
{
$Name = $Files['name'][$X];
$TMP = $Files['tmp_name'][$X];
move_uploaded_file($TMP, '../Users/HARAJLI98/' . $Name);
}
}
}
else
{
header("location:../");
}
$Connect->close();
?>
Document.getElementById needs the physical string of the ID, you don't need to specify that it's an ID.
You are mixing up javascript and jQuery. In jQuery, $.("#Progress") would work because the $ function doesn't know whether you are looking or an ID or a class.
This:
Progress = document.getElementById('#Progress');
should be this:
Progress = document.getElementById('Progress');
or this:
Progress = $("#Progress");
I'm building a tagging system for a site I'm working on. I have a variable for the url of the image that changes as the user selects different pictures. I'm using a MySQL command to display 3 tags for the selected picture, but it isn't working if I give it that changing variable. However, if I manually insert a url of an image, the captions show. However, these will show no matter what picture you're on so that doesn't really help. If I store a url under a variable, that works too, but not with the one that changes all the time.
Here's the site.
I know this isn't very easy to understand, so please let me know if you want me to try re-explaining something or if you want me to include some of the code. Thanks!
EDIT: Ok, I'll retry here. First, here's the code:
<?php
$username = $_GET['username'];
session_start();
$_SESSION['username'] = $username;
//Database Information
$dbhost = "";
$dbname = "";
$dbuser = "";
$dbpass = "";
//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
//Do the query
$query = mysql_query("SELECT * FROM images ORDER BY idnum DESC LIMIT 5");
// Generate an array of all images.
$images = array();
while($image = mysql_fetch_array($query)) {
// Adds each image to the images array.
$images[] = $image;
}
$image['filename'] = $current_image;
$query_captions = mysql_query("SELECT * from captions WHERE image = '$current_image' ORDER BY idnum DESC LIMIT 3");
$captions = array();
while($caption = mysql_fetch_array($query_captions)) {
$captions[] = $caption;
}
?>
<?php
// Beginning attempt at a caption script.
?>
<html>
<head>
<title>Home - Site in Development</title>
<link rel="stylesheet" type="text/css" href="styles.css"/>
<script type="text/javascript">
// Switches the url to view large image.
function switchImageUrl(url, width, height) {
var x = document.getElementById('caption_selection');
var y = document.getElementById('caption_input');
var z = document.getElementById('input_value');
x.style.display = 'none';
y.style.display = 'none';
z.value = '';
document.getElementById('center_frame').style.backgroundImage = 'url' + '(' + url + ')';
document.getElementById('center_frame').style.width = width;
document.getElementById('center_frame').style.height = height;
}
</script>
<!--Toggles view of caption selection tools and resets after.-->
<script type="text/javascript">
function selectionToggle() {
var x = document.getElementById('caption_selection');
var y = document.getElementById('caption_input');
var z = document.getElementById('input_value');
if(x.style.display == 'block')
x.style.display = 'none';
else
x.style.display = 'block';
x.style.width = '75px';
x.style.height = '75px';
x.style.top = '0px';
x.style.left = '0px';
if(y.style.display == 'block')
y.style.display = 'none';
else
y.style.display = 'block';
z.value = '';
}
</script>
<script type="text/javascript">
function collectAttributes() {
var cap = document.getElementById('caption_selection');
var cw = document.getElementById('cap_width');
var ch = document.getElementById('cap_height');
var cl = document.getElementById('cap_left');
var ct = document.getElementById('cap_top');
cw.value = cap.style.width;
ch.value = cap.style.height;
cl.value = cap.style.left;
ct.value = cap.style.top;
}
</script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script>
$(document).ready(function() {
$("#caption_selection").draggable({
containment : "#center_frame"
});
$("#caption_selection").resizable({
containment : "#center_frame"
});
});
</script>
</head>
<body onLoad="CalculateAllImageWidthes()">
<div id='account_links'>
<?php
if ($_SESSION['username']) {
echo "Welcome $username!";
} else { ?>
<a href='login.php'>Login</a> | <a href='register.php'>Register</a>
<?php } ?>
</div>
<h1>Picture Captions</h1>
<br/>
<br/>
<div id="left_bar">
Submit a picture here.
<hr/>
<h2>Top Images</h2>
<br/>
<div id="front_pg_images">
<?php foreach($images as $image) { ?>
<a onClick="switchImageUrl('<?php echo $image['filename']; ?>', '<?php echo $image['width']; ?>', '<?php echo $image['height']; ?>')"><img src="<?php echo $image['filename'];?>" width="72px" height="58px" id="front_pg_thumbnail"/></a>
<?php echo $image['name']." - by ".$image['submitter']; ?> <br/>
<br/>
<?php } ?>
</div>
</div>
<div id="center_frame" style="width: <?php echo $image['width']; echo "px" ?>; height: <?php echo $image['height']; echo "px" ?>; background-image: url('<?php echo $image['filename'];?>')" >
<?php foreach($captions as $caption) { ?>
<div id="set_caption" style="width:<?php echo $caption['width'].'px';?>;height:<?php echo $caption['height'].'px';?>; left:<?php echo $caption['posleft'].'px';?>; top:<?php echo $caption['postop'].'px';?>"><?php echo $caption['text'];?></div>
<?php } ?>
<div id="caption_selection" style="display:none">
</div>
</div>
<div id="toggle_select_container">
<input type="button" id="toggle_select" onClick="selectionToggle()" value="Caption"/>
<div id="caption_input" style="display:none">
<form action="postcaption.php" method="post" onSubmit="collectAttributes()">
<br/>
<textarea name="caption_text" cols="27" rows="4" id="input_value"></textarea><br/>
<input type="hidden" name="filename" value="<?php echo $image['filename'];?>"/>
<input type="hidden" name="width" value="" id="cap_width"/>
<input type="hidden" name="height" value="" id="cap_height"/>
<input type="hidden" name="left" value="" id="cap_left"/>
<input type="hidden" name="top" value="" id="cap_top"/>
<input type="submit" value="Post Caption"/>
</form>
</div>
</div>
</body>
</html>
It uses a JavaScript function to change the image when the user clicks on the thumbnail. Take note of the foreach. For everywhere else on the page, the $image['filename'] has worked perfectly for similar uses, but it just isn't working when I try to use it with this.