PHP - Need $_session Help For Final
I, for some unknown reason, decided to attempt to build my first social networking website for my senior project. I am sort of a dumb dumb when it comes to PHP. For what I am currently working on now I need to display "members" that go to the same "school" and start in the same "semester" according to whomever is currently logged in. I understand $_SESSION['userid'] = mysql_insert_id(); is tracking the current user, but how would I track other information attached to that current user. The "school" and "semester" are tracked within tables outside of the "user" table.
Any help at all would be awesome. If you need anymore information let me know. Thanks a trizillion. Similar Tutorials
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> I apologize for starting a couple of threads. But I have finally typed out my entire dilemma and could really use support in solving this issue. I am having an extremely hard time with I am sure a simple solution. I am slightly new at programming, but I know a fair amount to get my by. Anyways... Here's my problem. I am a photographer and I working on a website to teach and train students. I have currently made a very detailed website, but photo uploading management is kicking my butt. I first begin with an iFrame. The code follows, <?PHP include('../functions.php'); if($loggedinid="") { header( 'Location: http://lightgraspers.com/login.php' ) ; } //session_start(); //$_SESSION['pid']=$_SERVER['QUERY_STRING']; //$loggedinid=$_SESSION['uid']; //$_SESSION['pid']=$pid; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Queued Photo Uploader - Standalone Showcase from digitarald.de</title> <meta name="author" content="Harald Kirschner, digitarald.de" /> <meta name="copyright" content="Copyright 2009 Harald Kirschner" /> <!-- Framework CSS --> <link rel="stylesheet" href="http://github.com/joshuaclayton/blueprint-css/raw/master/blueprint/screen.css" type="text/css" media="screen, projection"> <link rel="stylesheet" href="http://github.com/joshuaclayton/blueprint-css/raw/master/blueprint/print.css" type="text/css" media="print"> <!--[if IE]><link rel="stylesheet" href="http://github.com/joshuaclayton/blueprint-css/raw/master/blueprint/ie.css" type="text/css" media="screen, projection"><![endif]--> <!--[if lte IE 7]> <script type="text/javascript" src="http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js"></script> <![endif]--> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.2/mootools.js"></script> <script type="text/javascript" src="source/Swiff.Uploader.js"></script> <script type="text/javascript" src="source/Fx.ProgressBar.js"></script> <script type="text/javascript" src="http://github.com/mootools/mootools-more/raw/master/Source/Core/Lang.js"></script> <script type="text/javascript" src="source/FancyUpload2.js"></script> <!-- See script.js --> <script type="text/javascript"> //<![CDATA[ /** * FancyUpload Showcase * * @license MIT License * @author Harald Kirschner <mail [at] digitarald [dot] de> * @copyright Authors */ window.addEvent('domready', function() { // wait for the content // our uploader instance var up = new FancyUpload2($('demo-status'), $('demo-list'), { // options object // we console.log infos, remove that in production!! verbose: true, // url is read from the form, so you just have to change one place url: $('form-demo').action, // path to the SWF file path: 'source/Swiff.Uploader.swf', // remove that line to select all files, or edit it, add more items typeFilter: { 'Images (*.jpg, *.jpeg, *.gif, *.png)': '*.jpg; *.jpeg; *.gif; *.png' }, // this is our browse button, *target* is overlayed with the Flash movie target: 'demo-browse', // graceful degradation, onLoad is only called if all went well with Flash onLoad: function() { $('demo-status').removeClass('hide'); // we show the actual UI $('demo-fallback').destroy(); // ... and hide the plain form // We relay the interactions with the overlayed flash to the link this.target.addEvents({ click: function() { return false; }, mouseenter: function() { this.addClass('hover'); }, mouseleave: function() { this.removeClass('hover'); this.blur(); }, mousedown: function() { this.focus(); } }); // Interactions for the 2 other buttons $('demo-clear').addEvent('click', function() { up.remove(); // remove all files return false; }); $('demo-upload').addEvent('click', function() { up.start(); // start upload return false; }); }, // Edit the following lines, it is your custom event handling /** * Is called when files were not added, "files" is an array of invalid File classes. * * This example creates a list of error elements directly in the file list, which * hide on click. */ onSelectFail: function(files) { files.each(function(file) { new Element('li', { 'class': 'validation-error', html: file.validationErrorMessage || file.validationError, title: MooTools.lang.get('FancyUpload', 'removeTitle'), events: { click: function() { this.destroy(); } } }).inject(this.list, 'top'); }, this); }, /** * This one was directly in FancyUpload2 before, the event makes it * easier for you, to add your own response handling (you probably want * to send something else than JSON or different items). */ onFileSuccess: function(file, response) { var json = new Hash(JSON.decode(response, true) || {}); if (json.get('status') == '1') { file.element.addClass('file-success'); file.info.set('html', '<strong>Image was uploaded:</strong> ' + json.get('width') + ' x ' + json.get('height') + 'px, <em>' + json.get('mime') + '</em>)'); } else { file.element.addClass('file-failed'); file.info.set('html', '<strong>An error occured:</strong> ' + (json.get('error') ? (json.get('error') + ' #' + json.get('code')) : response)); } }, /** * onFail is called when the Flash movie got bashed by some browser plugin * like Adblock or Flashblock. */ onFail: function(error) { switch (error) { case 'hidden': // works after enabling the movie and clicking refresh alert('To enable the embedded uploader, unblock it in your browser and refresh (see Adblock).'); break; case 'blocked': // This no *full* fail, it works after the user clicks the button alert('To enable the embedded uploader, enable the blocked Flash movie (see Flashblock).'); break; case 'empty': // Oh oh, wrong path alert('A required file was not found, please be patient and we fix this.'); break; case 'flash': // no flash 9+ :( alert('To enable the embedded uploader, install the latest Adobe Flash plugin.') } } }); }); //]]> </script> <!-- See style.css --> <style type="text/css"> /** * FancyUpload Showcase * * @license MIT License * @author Harald Kirschner <mail [at] digitarald [dot] de> * @copyright Authors */ /* CSS vs. Adblock tabs */ .swiff-uploader-box a { display: none !important; } /* .hover simulates the flash interactions */ a:hover, a.hover { color: red; } #demo-status { padding: 10px 15px; width: 420px; border: 1px solid #eee; } #demo-status .progress { background: url(assets/progress-bar/progress.gif) no-repeat; background-position: +50% 0; margin-right: 0.5em; vertical-align: middle; } #demo-status .progress-text { font-size: 0.9em; font-weight: bold; } #demo-list { list-style: none; width: 450px; margin: 0; } #demo-list li.validation-error { padding-left: 44px; display: block; clear: left; line-height: 40px; color: #8a1f11; cursor: pointer; border-bottom: 1px solid #fbc2c4; background: #fbe3e4 url(assets/failed.png) no-repeat 4px 4px; } #demo-list li.file { border-bottom: 1px solid #eee; background: url(assets/file.png) no-repeat 4px 4px; overflow: auto; } #demo-list li.file.file-uploading { background-image: url(assets/uploading.png); background-color: #D9DDE9; } #demo-list li.file.file-success { background-image: url(assets/success.png); } #demo-list li.file.file-failed { background-image: url(assets/failed.png); } #demo-list li.file .file-name { font-size: 1.2em; margin-left: 44px; display: block; clear: left; line-height: 40px; height: 40px; font-weight: bold; } #demo-list li.file .file-size { font-size: 0.9em; line-height: 18px; float: right; margin-top: 2px; margin-right: 6px; } #demo-list li.file .file-info { display: block; margin-left: 44px; font-size: 0.9em; line-height: 20px; clear } #demo-list li.file .file-remove { clear: right; float: right; line-height: 18px; margin-right: 6px; } </style> </head> <body> <div class="container"> <!-- See index.html --> <div> <form action="server/script.php" method="post" enctype="multipart/form-data" id="form-demo"> <fieldset id="demo-fallback"> <label for="demo-photoupload"> Upload a Photo: <input type="file" name="Filedata" /> </label> </fieldset> <div id="demo-status" class="hide"> <p><?php echo "$conid", "$loggedin", "$loggedinid", "$pid", $_GET['pid'] ?> <a href="#" id="demo-browse">Browse Files</a> | <a href="#" id="demo-clear">Clear List</a> | <a href="#" id="demo-upload">Start Upload</a> </p> <div> <strong class="overall-title"></strong><br /> <img src="assets/progress-bar/bar.gif" class="progress overall-progress" /> </div> <div> <strong class="current-title"></strong><br /> <img src="assets/progress-bar/bar.gif" class="progress current-progress" /> </div> <div class="current-text"></div> </div> <ul id="demo-list"></ul> </form> </div> </div> </body> </html> I can carry the value of $loggedid over to the iFrame, but then it doesn't go with the server/script.php path. No variables pass through... Here is the script.php information: <?php include('../../functions.php'); // Request log /** * You don't need to log, this is just for the showcase. Better remove * those lines for production since the log contains detailed file * information. */ $result = array(); $result['time'] = date('r'); $result['addr'] = substr_replace(gethostbyaddr($_SERVER['REMOTE_ADDR']), '******', 0, 6); $result['agent'] = $_SERVER['HTTP_USER_AGENT']; if (count($_GET)) { $result['get'] = $_GET; } if (count($_POST)) { $result['post'] = $_POST; } if (count($_FILES)) { $result['files'] = $_FILES; } // we kill an old file to keep the size small //if (file_exists('script.log') && filesize('script.log') > 102400) { // unlink('script.log'); //} //$log = @fopen('script.log', 'a'); //if ($log) { // fputs($log, print_r($result, true) . "\n---\n"); // fclose($log); //} // Validation $error = false; if (!isset($_FILES['Filedata']) || !is_uploaded_file($_FILES['Filedata']['tmp_name'])) { $error = 'Invalid Upload'; } /** * You would add more validation, checking image type or user rights. * if (!$error && $_FILES['Filedata']['size'] > 2 * 1024 * 1024) { $error = 'Please upload only files smaller than 2Mb!'; } if (!$error && !($size = @getimagesize($_FILES['Filedata']['tmp_name']) ) ) { $error = 'Please upload only images, no other files are supported.'; } if (!$error && !in_array($size[2], array(1, 2, 3, 7, 8) ) ) { $error = 'Please upload only images of type JPEG, GIF or PNG.'; } if (!$error && ($size[0] < 25) || ($size[1] < 25)) { $error = 'Please upload an image bigger than 25px.'; } */ // Processing /** * Its a demo, you would move or process the file like: * * move_uploaded_file($_FILES['Filedata']['tmp_name'], '../uploads/$loggedinid/' . $_FILES['Filedata']['name']); * $return['src'] = '/uploads/$loggedinid' . $_FILES['Filedata']['name']; * * or * * $return['link'] = YourImageLibrary::createThumbnail($_FILES['Filedata']['tmp_name']); * */ if ($error) { $return = array( 'status' => '0', 'error' => $error ); } else { $return = array( 'status' => '1', 'name' => $_FILES['Filedata']['name'] ); // Our processing, we get a hash value from the file $return['hash'] = md5_file($_FILES['Filedata']['tmp_name']); // ... and if available, we get image data $info = @getimagesize($_FILES['Filedata']['tmp_name']); // Specify directory path for your images directory $upload_directory = $_SERVER[DOCUMENT_ROOT] ."/file_upload/uploads/$loggedinid/$pid/"; $fileLoc="file_upload/uploads/$loggedinid/$pid/"; // Check that the images directory exists if(file_exists($upload_directory)) { // Upload file or return error message information $fileUrl = $fileLoc .$_FILES[Filedata][name]; mysql_query("INSERT INTO `homework` SET `uid`='$loggedin', `pid`='$pid', `url`='$fileUrl', `approved`='0'"); if(!move_uploaded_file($_FILES[Filedata][tmp_name], $upload_directory .$_FILES[Filedata][name])) { $error = "Could not upload file " .$_FILES["Filedata"]["name"] ."<br />" .$_FILES; } } else { mkdir("../uploads/$loggedinid/$pid", 0777); // Upload file or return error message information $fileUrl = $fileLoc .$_FILES[Filedata][name]; mysql_query("INSERT INTO `homework` SET `uid`='$loggedinid', `pid`='$pid', `url`='$fileUrl', `approved`='0'"); if(!move_uploaded_file($_FILES[Filedata][tmp_name], $upload_directory .$_FILES[Filedata][name])) { $error = "Could not upload file " .$_FILES["Filedata"]["name"] ."<br />" .$_FILES; } } if ($info) { $return['width'] = $info[0]; $return['height'] = $info[1]; $return['mime'] = $info['mime']; } } // Output /** * Again, a demo case. We can switch here, for different showcases * between different formats. You can also return plain data, like an URL * or whatever you want. * * The Content-type headers are uncommented, since Flash doesn't care for them * anyway. This way also the IFrame-based uploader sees the content. */ if (isset($_REQUEST['response']) && $_REQUEST['response'] == 'xml') { // header('Content-type: text/xml'); // Really dirty, use DOM and CDATA section! echo '<response>'; foreach ($return as $key => $value) { echo "<$key><![CDATA[$value]]></$key>"; } echo '</response>'; } else { // header('Content-type: application/json'); echo json_encode($return); } ?> The files upload correctly, but I need "uid" and the "pid" variables to carry through. This will then allow me to access the students information from the back-end. The files are uploading fine, I need those variables in there for the rest of the script to work. I have a database that contains results of fantasy football games. I have a query that returns the results of the games team X played against the other teams in the league. The query works perfect in the database. Results are Quote Opponent Name: America Enforcers Wins Losses Draws 1 1 0 Last Game: Week 2 of 2011: 416.6 - 369.8 the query and the php code cycle thru each team that team X has played and brings up team X's record and the results of the last game played. My problem is that the code stops one team short. So Team X played teams A, B, C, D, E but the code only returns teams A, B, C, D E is left off. I can't for the life of me figure out what silly mistake I made. Code: [Select] <?php include_once('../other/functions.php'); $con = mysql_connect($hostname, $username, $password) OR DIE ('Unable to connect to database! Please try again later.'); $db = mysql_select_db($dbname, $con); $thing = $_GET['thing']; $query = "select selected.teamname AS selected_team, selected_score.score AS selected_score, week.week, year, home_id, ". "target_score.score as target_score, target.teamname as targetname, week.ID ". "from owners as selected ". "JOIN game_scores AS selected_score ON selected.owner_id = selected_score.team_id ". "JOIN game_setup ON game_setup.game_id = selected_score.game_id ". "JOIN game_scores AS target_score ON target_score.game_id = game_setup.game_id AND target_score.team_id != selected_score.team_id ". "JOIN owners AS target ON target.owner_id = target_score.team_id ". "JOIN week ON week.week = game_setup.week ". "WHERE selected.owner_id = $thing ". "and target.active = 1 ". "GROUP BY target.teamname, year, week.ID "; $result = mysql_query($query); $row = mysql_fetch_array($result); $result1 = mysql_query($query); $row1 = mysql_fetch_array($result1); if (!$result) { die('Invalid query: ' . mysql_error()); } $wins=0; $losses=0; $draws=0; $last_target = false; echo '<h2>' . $row1['selected_team'] . ' vs. Active Teams</h2>'; while ($row = mysql_fetch_assoc($result)) { if ($last_target['targetname'] != $row['targetname']) { if ($last_target) { printf(' <table border="1" width="600"> <tr> <th>Opponent Name:</th> <th colspan="2">%s</th> </tr> <tr> <th>Wins</th> <th>Losses</th> <th>Draws</th> </tr> <tr> <td align="center">%d</td> <td align="center">%d</td> <td align="center">%d</td> </tr> <tr> <th>Last Game:</th> <td colspan="2">%s of %s: %.1f - %.1f</td> </tr> </table><br/>', $last_target['targetname'], $wins, $losses, $draws, $last_target['week'], $last_target['year'], $last_target['selected_score'], $last_target['target_score'] ); } $wins = $losses = $draws = 0; } if ($row['selected_score'] < $row['target_score']) ++$losses; elseif ($row['selected_score'] == $row['target_score']) ++$draws; else ++$wins; $last_target = $row; } ?> Any ideas on how to make the magic elvish be good??? Thank you for your time. I am running a contact form, which successfully works and sends the info, what I need help with, is when the form is submitted and the email is received this is the message: Code: [Select] Name: Name Appears Here Email: Email of client IP: 123456789 Message: Message content What I would like is to have another variable added to the email so the user whom reads it knows where the message came from, to below message for example From: Blah Here is the contact.php Code: [Select] <?php session_name("fancyform"); session_start(); $_SESSION['n1'] = rand(1,20); $_SESSION['n2'] = rand(1,20); $_SESSION['expect'] = $_SESSION['n1']+$_SESSION['n2']; $str=''; if($_SESSION['errStr']) { $str='<div class="error">'.$_SESSION['errStr'].'</div>'; unset($_SESSION['errStr']); } $success=''; if($_SESSION['sent']) { $success='<h1>Thank you!</h1>'; $css='<style type="text/css">#contact-form{display:none;}</style>'; unset($_SESSION['sent']); } ?> <!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>Contact</title> <script type="text/javascript" src="jquery.js"></script> <style>body{background: #ededed;margin:0;padding:0;}#menu_wrap{position:relative;margin-top:20px;margin-left:auto;margin-right:auto;padding:0; padding-right:0px;width:313px;height:37px;list-style-type:none;-webkit-border-radius:20px;-moz-border-radius:20px;border-radius:20px;-webkit-box-shadow:0 1px 3px rgba(0,0,0,.2);-moz-box-shadow:0 1px 3px rgba(0,0,0,.2);box-shadow:0 1px 3px rgba(0,0,0,.2)}.button a{cursor:pointer;text-align:center;font:16px/100% Arial, Helvetica, sans-serif;font-weight:bold;position:relative;min-width:50px;height:20px;float:left;padding:10px;padding-top:8.5px;padding-bottom:8.5px;text-decoration:none;text-shadow:0 1px 1px rgba(0,0,0,.3)}.button:first-child a{-webkit-border-top-left-radius:20px;-webkit-border-bottom-left-radius:20px;-moz-border-topleft-radius:20px;-moz-border-bottomleft-radius:20px;border-top-left-radius:20;border-bottom-left-radius:20px}.Vista_Green, .Vista_Green .button a{color:#FFF;background: #9dd53a;background: -moz-linear-gradient(top, #9dd53a 0%, #a1d54f 50%, #80c217 51%, #7cbc0a 100%);background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#9dd53a), color-stop(50%,#a1d54f), color-stop(51%,#80c217), color-stop(100%,#7cbc0a));background: -webkit-linear-gradient(top, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%);background: -o-linear-gradient(top, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%);background: -ms-linear-gradient(top, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%);filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#9dd53a', endColorstr='#7cbc0a',GradientType=0 );background: linear-gradient(top, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%);}.Vista_Green .button a:hover,.Vista_Green .button a:focus,.Vista_Green .button a:active{background: #7cbc0a;background: -moz-linear-gradient(top, #7cbc0a 0%, #80c217 13%, #a1d54f 50%, #9dd53a 100%);background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#7cbc0a), color-stop(13%,#80c217), color-stop(50%,#a1d54f), color-stop(100%,#9dd53a));background: -webkit-linear-gradient(top, #7cbc0a 0%,#80c217 13%,#a1d54f 50%,#9dd53a 100%);background: -o-linear-gradient(top, #7cbc0a 0%,#80c217 13%,#a1d54f 50%,#9dd53a 100%);background: -ms-linear-gradient(top, #7cbc0a 0%,#80c217 13%,#a1d54f 50%,#9dd53a 100%);filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#7cbc0a', endColorstr='#9dd53a',GradientType=0 );background: linear-gradient(top, #7cbc0a 0%,#80c217 13%,#a1d54f 50%,#9dd53a 100%);}.button:last-child a{float:left;border:none; -webkit-border-top-right-radius:20px;-webkit-border-bottom-right-radius:20px;-moz-border-radius:20px;border-top-right-radius:20px;border-bottom-right-radius:20px}</style> <br> <link rel="stylesheet" type="text/css" href="jqtransformplugin/jqtransform.css" /> <link rel="stylesheet" type="text/css" href="formValidator/validationEngine.jquery.css" /> <link rel="stylesheet" type="text/css" href="index.css" /> <?=$css?> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript" src="jqtransformplugin/jquery.jqtransform.js"></script> <script type="text/javascript" src="formValidator/jquery.validationEngine.js"></script> <script type="text/javascript" src="script.js"></script> </head> <p align="center"> <img border="0" src="images/image6611.png"></p> </p> <ul id="menu_wrap" class="Vista_Green"><li class="button"><a href="index.php">Home</a></li><li class="button"><a href="services.php">Services</a></li><li class="button"><a href="extra.php">Extra</a></li><li class="button"><a href="#">Contact</a></li> </ul><!-- Javascript code--> <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script> <script type="text/javascript">var search_input= $('.search input[type=text]');var search_input_size =120; var search_large_size = 180; var padding = 5; var shrinked = "";$(document).ready(function(){search_input.click(function(){shrink();}).focus(function(){shrink();});search_input.blur(function(){ if(shrinked=="YES")normal();});$('.button a').hover(function(){if(shrinked=="YES")normal();}); });function shrink(){if(search_input_size < search_large_size ){$('.button a').each(function(){$(this).animate({'padding-left': padding+'px','padding-right': padding+'px'},'fast');});search_input.animate({'width': search_large_size+'px'},'fast'); shrinked="YES";}return false;}function normal(){search_input.animate({'width':search_input_size+'px'},'fast'); $('.button a').animate({'padding-left':'10px','padding-right':'10px'},'fast');shrinked="";search_input.blur();return false;}</script> <body> <div id="main-container"> <div id="form-container"> <h1>Your Friendly Tree Specialist</h1> <h2>We will contact you soon.</h2> <form id="contact-form" name="contact-form" method="post" action="submit.php"> <table width="100%" border="0" cellspacing="0" cellpadding="5"> <tr> <td width="15%"><label for="name">Name</label></td> <td width="70%"><input type="text" class="validate[required,custom[onlyLetter]]" name="name" id="name" value="<?=$_SESSION['post']['name']?>" /></td> <td width="15%" id="errOffset"> </td> </tr> <tr> <td><label for="email">Email</label></td> <td><input type="text" class="validate[required,custom[email]]" name="email" id="email" value="<?=$_SESSION['post']['email']?>" /></td> <td> </td> </tr> <tr> <td><label for="subject">Subject</label></td> <td><select name="subject" id="subject"> <option value="" selected="selected"> - Choose -</option> <option value="Question">Question</option> <option value="Business proposal">Business proposal</option> <option value="Advertisement">Advertising</option> <option value="Other">Other</option> </select> </td> <td> </td> </tr> <tr> <td valign="top"><label for="message">Message</label></td> <td><textarea name="message" id="message" class="validate[required]" cols="35" rows="5"><?=$_SESSION['post']['message']?></textarea></td> <td valign="top"> </td> </tr> <tr> <td><label for="captcha"><?=$_SESSION['n1']?> + <?=$_SESSION['n2']?> =</label></td> <td><input type="text" class="validate[required,custom[onlyNumber]]" name="captcha" id="captcha" /></td> <td valign="top"> </td> </tr> <tr> <td valign="top"> </td> <td colspan="2"><input type="submit" name="button" id="button" value="Submit" /> <input type="reset" name="button2" id="button2" value="Reset" /> <?=$str?> <images id="loading" src="images/ajax-load.gif" width="16" height="16" alt="loading" /></td> </tr> </table> </form> <?=$success?> </div> <div class="tree-info"> </div> </div> </body> </html> Here is the submit.php Code: [Select] <?php /* config start */ $emailAddress = 'emailhere'; /* config end */ require "phpmailer/class.phpmailer.php"; session_name("fancyform"); session_start(); foreach($_POST as $k=>$v) { if(ini_get('magic_quotes_gpc')) $_POST[$k]=stripslashes($_POST[$k]); $_POST[$k]=htmlspecialchars(strip_tags($_POST[$k])); } $err = array(); if(!checkLen('name')) $err[]='The name field is too short or empty!'; if(!checkLen('email')) $err[]='The email field is too short or empty!'; else if(!checkEmail($_POST['email'])) $err[]='Your email is not valid!'; if(!checkLen('subject')) $err[]='You have not selected a subject!'; if(!checkLen('message')) $err[]='The message field is too short or empty!'; if((int)$_POST['captcha'] != $_SESSION['expect']) $err[]='The captcha code is wrong!'; if(count($err)) { if($_POST['ajax']) { echo '-1'; } else if($_SERVER['HTTP_REFERER']) { $_SESSION['errStr'] = implode('<br />',$err); $_SESSION['post']=$_POST; header('Location: '.$_SERVER['HTTP_REFERER']); } exit; } $msg= 'Name: '.$_POST['name'].'<br /> Email: '.$_POST['email'].'<br /> IP: '.$_SERVER['REMOTE_ADDR'].'<br /><br /> From: Aussie Submission<br /> Message:<br /><br /> '.nl2br($_POST['message']).' '; $mail = new PHPMailer(); $mail->IsMail(); $mail->AddReplyTo($_POST['email'], $_POST['name']); $mail->AddAddress($emailAddress); $mail->SetFrom($_POST['email'], $_POST['name']); $mail->Subject = "A new ".mb_strtolower($_POST['subject'])." from ".$_POST['name']." | contact form feedback"; $mail->MsgHTML($msg); $mail->Send(); unset($_SESSION['post']); if($_POST['ajax']) { echo '1'; } else { $_SESSION['sent']=1; if($_SERVER['HTTP_REFERER']) header('Location: '.$_SERVER['HTTP_REFERER']); exit; } function checkLen($str,$len=2) { return isset($_POST[$str]) && mb_strlen(strip_tags($_POST[$str]),"utf-8") > $len; } function checkEmail($str) { return preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str); } ?> The form works fine, no errors just need to know how to add the extra message. I have tried adding it to the submit, but when I submit the form, I get a blank page, if I push back, it goes to the thank you message and is sent. Hopefully someone can help, thank you. Hi everyone, this is my first time in this forum and I really need to seek some help from much more experienced PHP coders. My Final Year Project requires me to create a questionnaire to collect Profiling Data from the students. However with only half a year's experience with PHP coding, we find our knowledge rather insufficient at this point. Currently we have created a simple questionnaire with a simple search engine [attached] However now we have been requested to create a questionnaire where it is able to edit, add, remove questions from the questionnaire online itself without the need to go backend. Looking at some tutorials and other posts on this forum, I realised that the "hardcoding" we did, by putting all the questions/answers in to the HTML code itself instead of pulling it out from the database in SQL will cause difficulties. Thus I have decided to build the whole survey from scratch where the questions and answers are all stored in the SQL database itself. Help needed : > How should I actually create my database? What is in my mind now is to create a database with tables as such: Questionslist (Storing questions) id, questionid, question Answerslist (Storing options for questions male,female etc.) id, questionid, option > I currently have no clue how to start creating a page where I can add/edit/remove the questions in the questionnaire. Any example on how to start? > I roughly have an idea on how to edit or remove the questions the questions, but how do I add a question with the choice of making it a TEXT option, or a RADIO BUTTON option or a LIST option and have it add that question into my table of questionlist and answerlist as well? Currently using Adobe Dreamweaver CS5 and HeidiSQL for this project. We have requested a webspace from the school itself to host this questionnaire as well. If anyone needs more infomation to be able to assist me, I would gladly provide. With Thanks, Shawn [attachment deleted by admin] I just installed this new script here http://webhost.pro/domain-check.php it's a basic domain availability tool. I am trying to make a form that can be used on any page forward to this page with the content. The page loads with this in the url webhost.pro/domain-check.php?domain=dwhs.net and will run the page. So I can make a form that just submits to that page and sends the details. I made this page for testing http://webhost.pro/test.html But no go, here is the code: <form id="search" action="/domain-check.php" method="GET"> <input type="text" name="s"> <a onClick="document.getElementById('search').submit()" class="button1">Search</a> <div class="clear"></div> </form> Thanks! Hey, i was reading some code and i find this: if(stristr($_SESSION["s"]["user"]["asdasd"]),$someString) How the double/triple [] in $_SESSION works ? PS: I tryied to google it but it was kinda hard to search :X 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. edited 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? 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 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 I just got through a server problem with a variable named $_SESSION['id'] What would happen was when I loaded a mysql request with id in it (usually what i name the main key in a table) it would overwrite the value in the $_SESSION without specifically asking it to ie $_SESSION['id']=$id; This was on an acenet server I have the same thing on a bluehost server and wampserver and never had a problem What I did on acenet was rename $_SESSION['id'] when declaring it to $_SESSION['usernumber'] and all my issues stopped Anyone know why? Is it a acenet problem? My problem is fixed im just wondering if anyone has had a similar issue????? Is there an equivalent to * (any) in a $_SESSION? Something like this: foreach ($_SESSION['cart']['content'][*]['Large'] as $content) { Hello, I am currently making a small website that requires two languages. This is the class I made: Code: [Select] <?php class languages { public function __construct() { if(!isset($_SESSION['language'])) { $_SESSION['language'] = 'nl'; } $lang = isset($_GET['lang']) ? $_GET['lang'] : ""; $languages = array('en', 'nl'); if(in_array($lang, $languages)) { $_SESSION['language'] = $lang; } } } $languages = new languages; $language = $_SESSION['language']; ?> Now as soon I use index.php?lang=en, the website will display it self in English but, as soon I remove the &lang=en from the URI, the language gets not stored in the session and it displays nl agian. Can somebody help me? Thank you! Hello all, I have this at the top of my page to ensure that only logged in users can see the content Code: [Select] if(!isset($_SESSION['myusername'])){ header("Location:login.php"); exit; } else { $username = $_SESSION['myusername']; } This, of course is checked in the login form against a database and only stored in $_SESSION once it's verified... Now, my question is -- how secure is this? For example, could someone have $_SESSION['myusername'] set from another webpage, then navigate to mine and be able to see the protected content? Hiya, I'm quite new to php. My script was working fine till I transferred to a new host. The login system doesn't seem to register the $_SESSION 'userid' variable, so the proper page won't load because it thinks I'm not logged in. login.php - processes the login information Code: [Select] <?php session_start(); include('functions.php'); connect(); // note: session_start needs to be on every document apart // from index.php, login.php and register.php $username = protect($_POST['username']); $password = protect($_POST['password']); // the password and username from the inputs are stored in variables if ($username&&$password) { // if both the username and password variables are true $query = mysql_query("SELECT * FROM users WHERE username='$username'"); $numrow = mysql_num_rows($query); if ($numrow!=0) { // if $numrow does not equal nothing while ($row = mysql_fetch_assoc($query)) { $userid = $row['userid']; $dbusername = $row['username']; $dbpassword = $row['password']; } if ($username==$dbusername&&md5($password)==$dbpassword) { // $password gets encrypted so it can be checked on the database password $_SESSION['username'] = $username; $_SESSION['userid'] = $userid; // used for sessions knowing who is logged in header("Location:main.php"); // redirects to main.php page after successful login } else { echo "Incorrect password"; } } else { ?> <html> <head> <title>University Crusade</title> <link rel="stylesheet" href="css/style.css" type="text/css" media="screen"> <meta name="viewport" content="width=device-width, minimum-scale=1,maximum-scale=1, user-scalable=no"> </head> <body> <div id="wrapper"> <?php die (" That account doesn't exist...<br /><a href=\"index.php\">try again,</a> <a href=\"register.php\">or register an account.</a> "); } } else { die("Please enter a username and password"); } ?> </div> <div id="footer"> </div> </body> </html> and the main.php - after login.php it takes the user here Code: [Select] <?php session_start(); include('functions.php'); connect(); ?> <html> <head> <title>University Crusade</title> <link rel="stylesheet" href="css/new.css" type="text/css" media="screen"> <meta name="viewport" content="width=device-width, minimum-scale=1,maximum-scale=1, user-scalable=no"> </head> <body> <?php if (isset($_SESSION['userid'])) { include('safe.php'); ?> <ul id="tab-nav"> <li><a href="stats.php" id="tab-character">CHARACTER</a></li> <li><a href="games.php" id="tab-games">GAMES</a></li> <li><a href="account.php" id="tab-account">ACCOUNT</a></li> </ul> <div id="wrapper"> <h2 id="name">Hello, <?php echo $_SESSION['username'] ?>!</h2> <p> Welcome to UNIVERSITY CRUSADE the fantasy-themed pervasive web game! </p> <p> To start playing, begin with clicking the "games" button at the top of the screen, from there choose a challenge and follow the instructions </p> <p> What are the other buttons for? Well, the "account" button (top-right) is where you can change settings for your account - things like changing your password, deleting your account etc. The "character" button (top-left) when clicked takes you to your character, you can change your display picture, view your statistics and battle other players. </p> <p> More help with the game is available in the "account" section, this includes a detailed game manual describing in-detail game concepts and information. </p> </div> <div id="footer"> <a href="logout.php" class="button">log me out</a> </div> <?php } else { die (" <div id=\"wrapper\"> <p>Opps! You don't seem to be logged in...</p> <a class=\"button\" href=\"index.php\">login now</a><br /> <p>Don't have an account? No worries, just <a href=\"register.php\">register for one.</a></p> </div> "); } ?> </body> </html> I appreciate any help, as I'm left scratching my head. HI all i have the following code: <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); if (session_status() == PHP_SESSION_NONE) { session_start(); } if (!isset($_SESSION['user_name'])){ header("location: index.php"); } mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); include '../_includes/dbconn.php'; if($_SERVER['REQUEST_METHOD']=='POST'){ if(isset($_POST['delete-equipment-button'])){ $eid = $_POST['EM-id']; $stmt = $conn->prepare(" SELECT a.equipment_id, b.equipment_name from ssm_equipment_order a inner join ssm_equipment b on a.equipment_id = b.equipment_id where a.equipment_id = ? "); $stmt->bind_param('i', $eid); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($eid, $eqname); $stmt->fetch(); $instances = $stmt->num_rows; $_SESSION['eqname']="$eqname"; if($instances>0){ $_SESSION['updateEquipment']="is being used in an active order and cannot be deleted"; header("location: ../equipment-list.php"); }else{ $_SESSION['updateEquipment']="has been successfully deleted"; $stmt = $conn->prepare(" DELETE FROM ssm_equipment WHERE equipment_id = ? "); $stmt->bind_param('i', $eid); $stmt->execute(); var_dump($_SESSION); // header("location: ../equipment-list.php"); } } } ?> The session variable eqname gets set properly when the delete fails (the first half of my if). When i get to the else, the session does not set a value. I assumed that it was because the item whose name i am trying to get is being deleted but i thought this would happen after i have set the session variable and therefore be preserved for when i get back to the equipment list? As always, i appreciate your help. |