PHP - Understanding How $_session Works And My Auth_session.php File
Back with more noob questions so I was following a page in setting up a login system and so far it works how I want except for one minor thing So I want when a user is logged into the system to see Profile div instead of Login and Register and I do that in my index.php with the following <?php if(isset($_SESSION['username'])){ echo "<div class='profile'> <a href='logout.php'>Logout</a> </div> "; } else{ echo "<div class='loginregister'> <a href='login.php'>Login</a> <a href='register.php'>Register</a> </div> "; } ?> So when a user logs in it hits the login.php which looks like this <?php require('dbconnect.php'); session_start(); // When form submitted, check and create user session. if (isset($_POST['username'])) { $username = stripslashes($_REQUEST['username']); // removes backslashes $username = mysqli_real_escape_string($conn, $username); $password = stripslashes($_REQUEST['password']); $password = mysqli_real_escape_string($conn, $password); // Check user is exist in the database $query = "SELECT * FROM `Users` WHERE User='$username' AND password='" . md5($password) . "'"; $result = mysqli_query($conn, $query) or die(mysql_error()); $rows = mysqli_num_rows($result); if ($rows == 1) { $_SESSION['username'] = $username; // Redirect to user dashboard page header("Location: index.php"); } else { echo "<div class='form'> <h3>Incorrect Username/password.</h3><br/> <p class='link'>Click here to <a href='login.php'>Login</a> again.</p> </div>"; } } else { and it starts the session_start() function whilst also allocating $_SESSION['username'] = $username so in theory when index.php loads if SHOULD (?) hit the correct if statement in the index.php file now outputting the Profile div instead of the Login and Register div. Except it doesn't. However when I include the auth_session.php at the top of my index.php file like (currently uncommented to test) //<?php //include auth_session.php file on all user panel pages //include("auth_session.php"); //?> with the Auth_session file looking like <?php session_start(); if(!isset($_SESSION["username"])) { header("Location: login.php"); exit(); } else { } ?> It does show the correct Profile div instead of the Login and Register div. So I'm trying to understand what is happening here as from the look of it the $_SESSION['username'] is allocated within login.php and the session_start() function is also started in login.php So why would I need auth_session.php to be ran in order for the correct divs to show (I've not included auth_session.php as I want people to be able to see the site that aren't logged in) Warm regards Similar TutorialsHi i'm new to the forum and i'm wondering if anyone here could help me out with the problem i'm having. the script i have uses $_SESSION['userid'] = $users['id']; and i'm not exactly sure how to read that .. any information would be helpful. thanks in advance I've taken and redesigned a whole bunch of example and tutorial code pieces for my small project. I have a MySQL database working now (I realized it's easier than using flat files) and I need to get user accounts working. I'm having a lot of trouble understanding how PHP sessions work. Assuming a user has logged in and is now clicking on links and browsing around, on each page load, don't I need to check the session variable to load his username, and also check that his session is current? How do I check that the session is current? None of the examples / tutorials that I'm finding online even mention how my code is to know which user the page is being served to. Does session_start() have a magic feature that makes this check unnecessary? I know I can use cookies, but I figured I would code it without since some articles seem to indicate that cookies don't have to be required to support typical user session functionality. Hi All, Happy New Year to you all. I purchased a script for a cms and within this it has a feature for memberships by subscription. The person who wrote the script has not been very helpful at all. The script manages users and subscriptions with stripe. He told us that the recurring payments are all handled by a cron file. We run the cron file each night just before midnight. It should take a recurring payment for all those people who have a monthly recurring subscription. However, what is happening is the script is removing all the expired members from the database, and it should renew any person who has a recurring payment. BUT IT IS NOT. The script is removing all the members whos account have expired but it fails to take any payment. The script uses stripe for payments. I wonder if anyone can see from the code below what is going on. I think the way the file runs (but I am not totally sure) is it removes the expired memberships and then as it has done this it thinks there are no renewals. When you run a file for a job in php does the script follow the order of the code within it? Also, I noticed that on the stripe code it has the currency set to USD when it should be GBP as we are in the UK. If you look a the code that the script runs when they first sign up and then compare it to the code for the renewals you can see it is different. Can anyone help me, as the developer is no help at all and keeps telling me he has fixed it, when he has not as no renewal has taken place at all. The code for the first part when the user signs up is as follows:
//Create a client $client = \Stripe\Customer::create(array( "description" => App::Auth()->name, "source" => $token['id'], )); //Charge client $row = Db::run()->first(Membership::mTable, null, array("id" => $cart->mid)); $charge = \Stripe\Charge::create(array( "amount" => round($cart->total * 100, 0), // amount in cents, again "currency" => $key->extra2, "customer" => $client['id'], "description" => $row->{'description' . Lang::$lang}, ));
Then we was told by the developer that this file should be run on a cron job using wget, which we have set up and it runs fine but does not do anything with the stripe recurring payments. Cron File:
define("_WOJO", true); require_once("../init.php"); Cron::Run(1);
Then there is a cron.class.php file which seems to contain the information for stripe
class Cron { /** * Cron::Run() * * @return */ public static function Run($days) { $data = self::expireMemberships($days); self::runStripe($days); self::sendEmails($data); } /** * Cron::expireMemberships() * * @param integer $days * @return */ public static function expireMemberships($days) { $sql = " SELECT u.id, CONCAT(u.fname,' ',u.lname) as fullname, u.email, u.mem_expire, m.id AS mid, m.title FROM `" . Users::mTable . "` AS u LEFT JOIN `" . Membership::mTable . "` AS m ON m.id = u.membership_id WHERE u.active = ? AND u.membership_id <> 0 AND u.mem_expire <= DATE_ADD(DATE(NOW()), INTERVAL $days DAY);"; $result = Db::run()->pdoQuery($sql, array("y"))->results(); if ($result) { $query = "UPDATE `" . Users::mTable . "` SET mem_expire = NULL, membership_id = CASE "; $idlist = ''; foreach ($result as $usr) { $query .= " WHEN id = " . $usr->id . " THEN membership_id = 0"; $idlist .= $usr->id . ','; } $idlist = substr($idlist, 0, -1); $query .= " END WHERE id IN (" . $idlist . ")"; Db::run()->pdoQuery($query); } } /** * Cron::sendEmails() * * @param array $data * @return */ public static function sendEmails($data) { if ($data) { $numSent = 0; $mailer = Mailer::sendMail(); $mailer->registerPlugin(new Swift_Plugins_AntiFloodPlugin(100, 30)); $core = App::Core(); $tpl = Db::run()->first(Content::eTable, array("body", "subject"), array('typeid' => 'memExpired')); $replacements = array(); foreach ($data as $cols) { $replacements[$cols->email] = array( '[COMPANY]' => $core->company, '[LOGO]' => Utility::getLogo(), '[NAME]' => $cols->fullname, '[ITEMNAME]' => $cols->title, '[EXPIRE]' => Date::doDate("short_date", $cols->mem_expire), '[SITEURL]' => SITEURL, '[DATE]' => date('Y'), '[FB]' => $core->social->facebook, '[TW]' => $core->social->twitter, ); } $decorator = new Swift_Plugins_DecoratorPlugin($replacements); $mailer->registerPlugin($decorator); $message = Swift_Message::newInstance() ->setSubject($tpl->subject) ->setFrom(array($core->site_email => $core->company)) ->setBody($tpl->body, 'text/html'); foreach ($data as $row) { $message->setTo(array($row->email => $row->fullname)); $numSent++; $mailer->send($message, $failedRecipients); } unset($row); } } /** * Cron::runStripe() * * @param bool $days * @return */ public static function runStripe($days) { $sql = " SELECT um.*, m.title, u.id as uid, m.price, u.email, u.stripe_cus, CONCAT(u.fname,' ',u.lname) as name FROM `" . Membership::umTable . "` AS um LEFT JOIN `" . Membership::mTable . "` AS m ON m.id = um.mid LEFT JOIN `" . Users::mTable . "` AS u ON u.id = um.uid WHERE um.active = ? AND um.recurring = ? AND TRIM(IFNULL(u.stripe_cus,'')) <> '' AND u.mem_expire <= DATE_ADD(DATE(NOW()), INTERVAL $days DAY) ORDER BY expire DESC;"; $data = Db::run()->pdoQuery($sql, array(1, 1))->results(); require_once (BASEPATH . 'gateways/stripe/stripe.php'); $key = Db::run()->first(AdminController::gTable, array("extra"), array("name" => "stripe")); \Stripe\Stripe::setApiKey($key->extra); if ($data) { try { foreach ($data as $row) { $tax = Membership::calculateTax($row->uid); $charge = \Stripe\Charge::create(array( "amount" => round(($row->price + $tax) * 100, 0), // amount in cents, again "currency" => "usd", "customer" => $row->stripe_cus, )); // insert transaction $data = array( 'txn_id' => $charge['balance_transaction'], 'membership_id' => $row->mid, 'user_id' => $row->uid, 'rate_amount' => $row->price, 'total' => Validator::sanitize($row->price * $tax, "float"), 'tax' => Validator::sanitize($tax, "float"), 'currency' => $charge['currency'], 'pp' => "Stripe", 'status' => 1, ); $last_id = Db::run()->insert(Membership::pTable, $data)->getLastInsertId(); //update user membership $udata = array( 'tid' => $last_id, 'uid' => $row->uid, 'mid' => $row->mid, 'expire' => Membership::calculateDays($row->mid), 'recurring' => 1, 'active' => 1, ); //update user record $xdata = array( 'membership_id' => $row->id, 'mem_expire' => $udata['expire'], ); Db::run()->insert(Membership::umTable, $udata); Db::run()->update(Users::mTable, $xdata, array("id" => $row->uid)); } } catch (\Stripe\CardError $e) { } } } }
I noticed on this file that the currency section is not the same as the first file, so that led me to believe that was why nothing was happening as we deal in gbp only. So, i changed this to gbp and ran the script manually, and all it did was remove the memberships from the users who were supposed to have a recurring payment. So, my question can you see what is wrong with that code? I have been trying to get this developer to fix this for over a week now as we have a live website running and not taking a single recurring payment. Please help in anyway you can?
Hello again: I would like to see if someone can either show me some code, or point me in the direction of a good article about uploading a file (meaning a photo, .JPG, .GIF, etc) via PHP. I have only done this with ASP. My searches on GOOGLE are only showing me ways to upload a file INTO the database, and I don't believe that is the proper way to do it. I have always stored the file (.JPG) in a folder called "uploads" and stored the file name (myPhoto.JPG) in the database. So, if I want to make a Team bio list with a photo, a title, and a description what is the proper way to do that? Meaning, I click "Add Player" and a form with title, description, and a photo upload field appear. The data is filled out, "Submit" is clicked, and the photo is uploaded to "uploads" and all other data is inserted into the database. I had wanted to be able to modify, delete, or make inactive each player, and use a dropdown SELECT menu to choose what player to edit. Any ideas how to accomplish this? I would appreciate the help!
First let me explain my code. This is later included in project_status.php] . In project_status.php] , I have included another file project_status_app.php which contains a HTML form.
<?php include 'inc_fn_header_and_menu.php'; function includeFile($file,$variable) { $var = $variable; include($file); } if (isset($_GET['id']) && $_GET['id']!="") { $pid = $_GET['id']; $_SESSION['pidForApproval'] = $_GET['id']; $query = 'SELECT * FROM `profile` WHERE pid ='.'\''.$pid.'\''; $result=mysqli_query($db,$queryToRetrievePP) or die("There are no records to display ... \n" . mysqli_error()); foreach ($result as $row) { $status = $row['status']; } } ...........some PHP and HTML code....... <div id="customerPurchaseApprovalForm"> <?php echo '<p>APPROVAL FOR CUSTOMER PURCHASE</p>'; $discountApprovalStatus = "Granted"; if ($discountApprovalStatus == "Granted") { includeFile("project_status_app.php",$highestannualvalue); } else { //......... } In project_status_app.php I am attempting to retrieve pidForApproval from the $_SESSION array. <?php // put your code here UPDATE `pp` SET `customer_purchase_remarks` = 'hahaha' WHERE `pp`.`id` = 207; if ($_SERVER['REQUEST_METHOD'] == 'POST') { include '../../inc/fastlogin.php'; $sql = "UPDATE pp SET customer_purchase_remarks ='{$_POST['remarkstxt']}' WHERE pp.pid='{$_SESSION['pidForApproval']}'"; $result = mysqli_query ( $fastdb, $sql ) ; if (mysqli_affected_rows($fastdb) != 1) { $_SESSION['err_cpa_rmks'] = "<p>Error while updating WHERE id='{$_SESSION['pidForApproval']}'</p>"; //echo "<p>Error while updating WHERE id='{$_POST['pidForApproval']}'</p>".mysqli_error($fastdb); } else { $_SESSION['suc_cpa_rmks'] = "<p>Records was updated successfully.</p>"; //echo "Records was updated successfully."; } header ("location: project_status.php?id="$_SESSION['pidForApproval']); exit(); } ?> When I load project_status.php, project_status_app.php is supposed to display the form. Once the user fills in the form the and the submit button has been pressed, the UPDATE statement is supposed to run and then it is supposed to navigate back to project_status.php?id=FA142. But the update is failing and the when the project_status.php is loaded back, the url looks like this http://localhost/fast/project_status.php?id= . The id is empty. It is supposed to be something like this http://localhost/fast/project_status.php?id=FA142. With the id being populated at the header ("location: project_status.php?id=".$_SESSION['pidForApproval']);
Missing some information. Hello everyone, I am working on a form that is similar to a shopping cart system and I am thinking of creating a button that submits the checked value and saves them to a $_SESSION variable. And also a link that links to a cart.html that takes the values of a $_SESSION variable. I am have trouble figuring what tag/attribute should I use in order to achieve that.
Right now my code attached below submits the checked values to cart.html directly. However I want my submit button to save the checked box to a $_SESSION variable and STAY on the same page. And then I will implement a <a> to link to the cart.php.
I researched a little bit about this subject and I know it's somewhat related to ajax/jquery. I just wanted to know more about it from you guys. I appreciate your attention for reading the post and Thanks!
Below is the form that I currently have:
<form name= "finalForm" method="POST" action="cart.php"> <input type="Submit" name="finalSelected"/> <?php foreach($FinalName as $key => $item) {?> <tr> <td><input type="checkbox" name="fSelected[]" value="<?php echo htmlspecialchars($FinalID[$key])?>" /> <?php echo "$FinalID[$key] & $item";?> </td> </tr> <?php } ;?>Below is the code for cart.php <?php require ('connect_db.php'); if(isset($_POST['finalSelected'])) { if(!empty($_POST['fSelected'])) { $chosen = $_POST['fSelected']; foreach ($chosen as $item) echo "aID selected: $item </br>"; $delimit = implode(", ", $chosen); print_r($delimit); } } if(isset($delimit)) { $cartSQL = "SELECT * from article where aID in ($delimit)"; $cartQuery = mysqli_query($dbc, $cartSQL) or die (mysqli_error($dbc)); while($row = mysqli_fetch_array($cartQuery, MYSQLI_BOTH)) { $aTitle[] = $row[ 'name' ]; } } ?> <table> <?php if(isset($delimit)) { $c=0; foreach($aTitle as $item) {?> <tr> <td> <?php echo $aTitle[$c]; $c++;?> </td> </tr> <?php }}?> </table> My external css file works on everything except for body, however, it works when I include the css on the page itself:
body{ margin-top: 0px; padding-top: 0px; margin-bottom: 0px; padding-bottom: 0px; background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYxIDY0LjE0MDk0OSwgMjAxMC8xMi8wNy0xMDo1NzowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNS4xIFdpbmRvd3MiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6OERFQkEzRUJDNUM5MTFFMUE3NzBCMTZBMEExNEQ5NUQiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6OERFQkEzRUNDNUM5MTFFMUE3NzBCMTZBMEExNEQ5NUQiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo4REVCQTNFOUM1QzkxMUUxQTc3MEIxNkEwQTE0RDk1RCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo4REVCQTNFQUM1QzkxMUUxQTc3MEIxNkEwQTE0RDk1RCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PiSp0pIAAAAySURBVHjaYmBgYOAHYmYGCADR/CDiDxDzQAW5gPgLlM3ACsQKUBqhBYjZkY3CMBMgwACvHQKnyUp+6gAAAABJRU5ErkJggg=="); background-color:#b20a22; -webkit-transition: all 300ms ease-in-out; -moz-transition: all 300ms ease-in-out; -ms-transition: all 300ms ease-in-out; -o-transition: all 300ms ease-in-out; transition: all 300ms ease-in-out; }What could be wrong? Code works when...
<script type="text/javascript"> var currenttime = '<?php print gmdate('F d, Y H:i:s', time() + (1 * 60 * 60))?>' var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December") var serverdate=new Date(currenttime) function padlength(what){ return (what.toString().length==1)? "0"+what : what } function displaytime(){ serverdate.setSeconds(serverdate.getSeconds()+1) var datestring=montharray[serverdate.getMonth()]+" "+padlength(serverdate.getDate())+", "+serverdate.getFullYear() var timestring=padlength(serverdate.getHours())+":"+padlength(serverdate.getMinutes())+":"+padlength(serverdate.getSeconds()) document.getElementById("servertime").innerHTML=datestring+" "+timestring } window.onload=function(){ setInterval("displaytime()", 1000) } </script>Code not works when... <script type="text/javascript" src="clock.js">I want to use second option. Any help? Im trying to use a file upload script i found he http://www.phptoys.com/e107_plugins/content/content.php?content.39 and everything says it works but the file deosnt upload and i get the following in the error log: Quote [20-Jan-2011 20:02:42] PHP Fatal error: Call to a member function Get() on a non-object in /home/mikeh/public_html/test/uploader.php on line 33 [20-Jan-2011 20:03:48] PHP Fatal error: Call to a member function Get() on a non-object in /home/mikeh/public_html/test/uploader.php on line 33 here is some info copied from my hostgator cpanel: Home Directory: /home/mikeh Operating System: Linux CentOS below is the entire source code: <?php /************************************************* * Micro Upload * * Version: 0.1 * Date: 2006-10-27 * * Usage: * Set the uploadLocation variable to the directory * where you want to store the uploaded files. * Use the version which is relevenat to your server OS. * ****************************************************/ //Windows way //$uploadLocation = "/home/mikeh/public_html/test"; //Unix, Linux way $uploadLocation = "/home/mikeh/public_html/test/"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html> <head> <title>MicroPing domain status checker</title> <link href="style/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="main"> <div id="caption">UPLOAD FILE</div> <div id="icon"> </div> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="fileForm" id="fileForm" enctype="multipart/form-data"> File to upload:<center> <table> <tr><td><input name="upfile" type="file" size="36"></td></tr> <tr><td align="center"><br/><input class="text" type="submit" name="submitBtn" value="Upload"></td></tr> </table></center> </form> <?php if (isset($_POST['submitBtn'])){ ?> <div id="caption">RESULT</div> <div id="icon2"> </div> <div id="result"> <table width="100%"> <?php $target_path = $uploadLocation . basename( $_FILES['upfile']['name']); //die($target_path); if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) { echo "The file: ". basename( $_FILES['upfile']['name']). " has been uploaded!"; } else{ echo "There was an error uploading the file, please try again!"; } ?> </table> </div> <?php } ?> <div> </body> Edit: can be seen/tested at: http://cnotes.ca/test/microUpload.php Dear php freaks, In my test file the following code works perfectly: Code: [Select] <!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" /> <script language="javascript" type="text/javascript"> function dropdownlist(listindex) { document.formname.subcategory.options.length = 0; switch (listindex) { case "1" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); break; case "2" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); break; case "3" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); break; case "4" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); document.formname.subcategory.options[5]=new Option("4","4"); break; case "5" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); document.formname.subcategory.options[5]=new Option("4","4"); document.formname.subcategory.options[6]=new Option("5","5"); break; case "6" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); document.formname.subcategory.options[5]=new Option("4","4"); document.formname.subcategory.options[6]=new Option("5","5"); document.formname.subcategory.options[7]=new Option("6","6"); break; case "7" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); document.formname.subcategory.options[5]=new Option("4","4"); document.formname.subcategory.options[6]=new Option("5","5"); document.formname.subcategory.options[7]=new Option("6","6"); document.formname.subcategory.options[8]=new Option("7","7"); break; case "8" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); document.formname.subcategory.options[5]=new Option("4","4"); document.formname.subcategory.options[6]=new Option("5","5"); document.formname.subcategory.options[7]=new Option("6","6"); document.formname.subcategory.options[8]=new Option("7","7"); document.formname.subcategory.options[9]=new Option("8","8"); break; case "9" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); document.formname.subcategory.options[5]=new Option("4","4"); document.formname.subcategory.options[6]=new Option("5","5"); document.formname.subcategory.options[7]=new Option("6","6"); document.formname.subcategory.options[8]=new Option("7","7"); document.formname.subcategory.options[9]=new Option("8","8"); document.formname.subcategory.options[10]=new Option("9","9"); break; case "10" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); document.formname.subcategory.options[5]=new Option("4","4"); document.formname.subcategory.options[6]=new Option("5","5"); document.formname.subcategory.options[7]=new Option("6","6"); document.formname.subcategory.options[8]=new Option("7","7"); document.formname.subcategory.options[9]=new Option("8","8"); document.formname.subcategory.options[10]=new Option("9","9"); document.formname.subcategory.options[11]=new Option("10","10"); break; } return true; } </script> </head> <title>Dynamic Drop Down List</title> <body> <form id="formname" name="formname" method="post" action="submitform.asp" > <table width="50%" border="0" cellspacing="0" cellpadding="5"> <tr> <td width="41%" align="right" valign="middle">Aantal kinderen :</td> <td width="59%" align="left" valign="middle"><select name="category" id="category" onchange="javascript: dropdownlist(this.options[this.selectedIndex].value);"> <option value="">------</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select></td> </tr> <tr> <td align="right" valign="middle">Waarvan thuiswonend : </td> <td align="left" valign="middle"><script type="text/javascript" language="JavaScript"> document.write('<select name="subcategory"><option value="">-----</option></select>') </script> <noscript><select name="subcategory" id="subcategory" > <option value="">Select Sub-Category</option> </select> </noscript></td> </tr> </table> </form> </body> </html> When i want to implement it in my signup page, it doesnt do anything. I've checked it a thousand times, i double checked that also the -formname of my signup page is 'formname' -the element name stays 'subcategory' I really need this to be implemented. Where can be the problem? What should i look for? PHP = 5.5.14
MySQL = 5.2.17
This simple .php script works as a standalone OK:
<?php require '<snip partial URL>mysqli.php'; // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $result = mysqli_query($con,"SELECT `callsign`, `qth`, `submitted` FROM `lqplogs` ORDER BY `callsign`"); echo "<table> <tr> <th><u>CALLSIGN</u></th><th><u>QTH</u></th><th><u>LOG SUBMITTED</u></th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['callsign'] . "</td>"; echo "<td>" . $row['qth'] . "</td>"; echo "<td>" . $row['submitted'] . "</td>"; echo "</tr>"; } echo "</table>"; mysqli_close($con); ?>A separate .html page with other info works by itself OK too, but when I try to embed the PHP script (with PHP start & end tags, of course) *between* these HTML tags: <table> <tr> <td> ... Full PHP Script Embedded here... </td> </tr> </table> I get this mess: "; while($row = mysqli_fetch_array($result)) { echo ""; echo ""; echo ""; echo ""; echo ""; } echo " CALLSIGN QTH LOG SUBMITTED " . $row['callsign'] . " " . $row['qth'] . " " . $row['submitted'] . " "; mysqli_close($con); ?>Any thoughts as to why are appreciated. Thanks! - FreakingOUT Hi there, If anyone has a spare minute, id really appreciate someone casting their eye over this and seeing if there's anything obviously wrong. Writing to the txt file works fine, but the redirect to the thankyou.html page doesn't. Cheers Guys. <?PHP $filename = "output.txt"; #CHMOD to 666 $forward = 1; # redirect? 1 : yes || 0 : no $location = "thankyou.html"; #set page to redirect to, if 1 is above ## set time up ## $date = date ("l, F jS, Y"); $time = date ("h:i A"); ## mail message ## $msg = ""; foreach ($_POST as $key => $value) { $msg .= ucfirst ($key) .", ". $value . ", "; } $msg .= "\n"; $fp = fopen ($filename, "a"); # w = write to the file only, create file if it does not exist, discard existing contents if ($fp) { fwrite ($fp, $msg); fclose ($fp); } else { $forward = 2; } if ($forward == 1) { header ("Location:$location"); } else if ($forward == 0) { echo ("Thank you for submitting our form. We will get back to you as soon as possible."); } else { "Error processing form. Please contact the webmaster"; } ?> Many thanks, Mike Hello, New to file upload boxes, working in PHP. My code seems to work great in IE, but not in Firefox or Chrome. This form shows the input box for the filename in IE and Firefox (with a Browse button), but Chrome only shows the Browse button, no filename box. <form enctype="multipart/form-data" method="post" action="profile.php"> <input type="file" size="32" name="image_field_photo" value=""> <br><input type="submit" name="Submit" value="Upload"> IE will upload the file to the specified directory, then update the DB based on the filename. Firefox will not upload the file, nor will Chrome. Using SSL for all pages. Using an upload class I got off PHPClasses.org - what's weird is I have used this same class on another project, and can upload files via Chrome. Any ideas? Thanks! Hi all I was trying to connect to a database which is running on an external host. So i thought i try the stuff below. That didn't work. Is it possible that the host has disabled external connection or something? I tried to add http:// before the domain, but no succes either Code: [Select] <?php $dbc = mysqli_connect('db87654321.somedomain.com','user','pass','database')// this is line 5 or die(mysqli_error($dbc)); echo 'connected'; ?> it gave the following error: Quote Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2005): Unknown MySQL server host 'db87654321.somedomain.com' (11004) in H:\xampp\htdocs\databasetestfile.php on line 5 P.s. the script worked when upload to the server. P.p.s is there something i should be carefull with when connection to an external database?
Hi, this query runs fine when I run it from PHPMyAdmin: UPDATE `tran_term_taxonomy` SET `description` = (SELECT keyword from `good_keywords` ORDER BY RAND() LIMIT 1,1) WHERE `tran_term_taxonomy`.`taxonomy` = 'post_tag' AND `tran_term_taxonomy`.`description` = "" LIMIT 1 However, when I run the same query in a PHP file on my server, the page doesn't load at all. The message I get is: www.somesite.com is currently unable to handle this request. HTTP ERROR 500. This is my PHP code: <?php include("/database/connection/path/db_connect.php"); $result4 = mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE `tran_term_taxonomy` SET `description` = (SELECT keyword from `good_keywords` ORDER BY RAND() LIMIT 1,1) WHERE `tran_term_taxonomy`.`taxonomy` = 'post_tag' AND `tran_term_taxonomy`.`description` = "" LIMIT 1"); echo $result4; ?> So how do I make this query work please? Thanks for your guidance. Hi Guys.... I need to export data into excel file. So far its works on IE and Firefox. But if i using Google Chrome it download only php file. Eg(suppose file test.xls but it goes to test.php). Why it happen?? Hi i have made a login in system for a website iam trying to make. after you log in im trying to display the members username via the $_session created in the check_login.php. but when i Echo or print_r the $_session all is get is "welcome array" its like its not passing any information via the $_session from page to page. here is my code thanks in advance. Check_login.php session_start(); // username and password sent from form $myusername=$_POST['myusername']; $mypassword=md5($_POST["mypassword"]); // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" $_SESSION["myusername"]==$myusername; $_SESSION["mypassword"]; header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> login_success.php <? session_start(); if($_SESSION['myusername']="$myusername"){ header("location:main_login.php"); } Echo "welcome" . $_SESSION['$myusername']; ?> thanks The $_Session has a url variable. Using a Dom how do I properly do: Code: [Select] html->load($_SESSION['variable']) I was thinking about breaking down the session to retrieve the value inside but I don't know how. For the last few hours I have been pulling my hair out on a session not storing when I moved from local host to my vps. I have been setting sessions like: $_SESSION['mydata'] = $variable; This works no problem on my wamp installation. However to get it to work on my vps, I have to store them like this $_SESSION[mydata] = $variable; Can someone please explain to me why this is the case? PHP 5.3.3 I am trying to redirect a user (currently logged in) to a page where they are able to edit a posted comment. To keep things secure I am using a forms hidden input value to pass the {postID} to a redirect page Code: [Select] <form name="post_edit" method="post" action="post-edit-redirect.php" > <input type="hidden" name="local" id="local" value="<?php echo $row_rsPosts['postID']; ?>" /> <input type="image" src="../imgs/managepost.png" name="submit" /> </form> On the redirect page (simplified below) I am setting the {postID} in a SESSION before redirecting to the user to the page to edit their post with the new $_SESSION val for {postID} set. Code: [Select] session_start(); $id = $_REQUEST['local']; $_SESSION['postID']=$id; header("Location: edit-post.php"); This is working fine in every browser except IE (some one please just put an end to it), where when the edit-post.php page is reached the $_SESSION['postID'] is empty. If I regenerate the session ID from the redirect page as below IE then sets the SESSION ok. Code: [Select] session_start(); session_regenerate_id(); $id = $_REQUEST['local']; $_SESSION['postID']=$id; header("Location: edit-post.php"); However there should be no need to do this and would rather not if there is no need. Any help on why IE is not setting the SESSION is appreciated, and I hope I am not covering old ground here however I am unable to find a solution anywhere. - Cheers |