Search the Community
Showing results for tags 'help'.
-
Hey I'm new to php and I have a bit of a problem. I haven't edited anything on this page, but keep getting a Parse error: syntax error, unexpected T_LNUMBER on line 64. Does anyone see the mistake or could help me in any way? Thank you. <?php // Set Content Width if ( ! isset( $content_width ) ) $content_width = 480; /*==================================== THEME SETUP ====================================*/ // Load default style.css and Javascripts add_action('wp_enqueue_scripts', 'themezee_enqueue_scripts'); if ( ! function_exists( 'themezee_enqueue_scripts' ) ): function themezee_enqueue_scripts() { // Register and Enqueue Stylesheet wp_register_style('zeeBusiness_stylesheet', get_stylesheet_uri()); wp_enqueue_style('zeeBusiness_stylesheet'); // Enqueue jQuery Framework wp_enqueue_script('jquery'); // Register and enqueue the Malsup Cycle Plugin wp_register_script('zee_jquery-cycle', get_template_directory_uri() .'/includes/js/jquery.cycle.all.min.js', array('jquery')); wp_enqueue_script('zee_jquery-cycle'); } endif; // Load comment-reply.js if comment form is loaded and threaded comments activated add_action( 'comment_form_before', 'themezee_enqueue_comment_reply' ); function themezee_enqueue_comment_reply() { if( get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); } } // Setup Function: Registers support for various WordPress features add_action( 'after_setup_theme', 'themezee_setup' ); if ( ! function_exists( 'themezee_setup' ) ): function themezee_setup() { // init Localization load_theme_textdomain('themezee_lang', get_template_directory() . '/includes/lang' ); // Add Theme Support add_theme_support('post-thumbnails'); add_theme_support('automatic-feed-links'); add_editor_style(); // Add Custom Background add_theme_support('custom-background', array('default-color' => 'eee')); // Add Custom Header add_theme_support('custom-header', array( 'default-image' => get_template_directory_uri() . '/images/default_header.jpg', 'header-text' => false, 'width' => 1100, 'height' => 140, 'flex-height' => true)); // Register Navigation Menus register_nav_menu( 'top_navi', __('Top Navigation', 'themezee_lang') ); register_nav_menu( 'main_navi', __('Main Navigation', 'themezee_lang') ); register_nav_menu( 'foot_navi', __('Footer Navigation', 'themezee_lang') );
-
<?php //connect to the database require_once('connectvars.php'); $firstname = ( $_POST['firstname']); $lastname = ( $_POST['lastname']); $username = ( $_POST['username']); $password = ( $_POST['password1']); $email = ( $_POST['email']); //insert data into table $query = "INSERT INTO summerfun_users (username, password, email, first_name, last_name) VALUES ($username, '$password', '$email', '$firstname', '$lastname')"; mysqli_query($dbc, $query); //confirm success with the user echo "congrats friend, you are now a member of summer fun"; ?> i am getting undefined index errors on all my variables, please help
-
I'm designing a website for a wine wholesaler that needs to be able to update and display their product catalog in a certain specific way. The site in development is at www.metrocellars.com/new/ Let me first begin by outlining the database tables in use: location​ - a table of 6 records, the broader breakdown of geographic location (Brazil, California, etc.) These rows are used in the navigation menu, and each location has many "regions" referencing them. region​ - the more specific area of origin of each product (wine). Each "Region" references one of the 6 broader "Locations". product​ - The meat of the db, each Product record references a Producer/Winery (PID), a specific Region (RID - which also references a broader Location), and a specific Varietal (VID - Wine type/color). The left part of the image below shows part of the Product table. winery​ - This table holds records of each Winery/Producer referenced by PID in Product table. varietals - This table lists each type of wine, (Pinot, Merlot, etc) referenced by VID in the Product table. ​ On the right side of the above image, I included a visual of the relevant tables with FK relation lines. I haven't figured out which ON DELETE/UPDATE to use, as I got errors a couple times from child rows as I was assigning indexes/keys. I'm a little rusty with the SQL at the moment. Using this model, I need to be able to output the data to a wine list page, but I am having problems putting together the right queries and loops to list the data in the requested format. Here is an example of what the page content should look like when the 'region' California (LID = 2) is clicked on the nav menu. California Slo Down Wines http://www.slodownwines.com/ Broken Dreams Sexual Chocolate Central Coast Jackhammer http://jackhammerwine.com Pinot Noir Happy Canyon of Santa Barbara Cimarone Winery http://www.cimarone.com/ 3CV Bank 3CV Cilla’s Blend Le Clos Secret Gran Premio 3CV Estate Sauvignon Blanc Dragonette Cellars http://dragonettecellars.com/ GMS Rose Sauvignon Blanc Happy Canyon Vineyards http://happycanyonvineyard.com/ Ten Goal Merlot http://happycanyonvineyard.com/ Piocho Margerum Wine Company Sybarite Sauvignon Blanc Paso Robles Spaceman Vineyards Reserve Airspace Santa Barbara County Ampelos Cellars Syrache - Syrah & Grenache Margerum Wine Company http://www.margerumwinecompany.com/ Chenin Blanc M5 Riesling Uber Reserve Tercero http://tercerowines.com/ Grenache Grenache Blanc The Climb Santa Lucia Highlands Jackhammer http://jackhammerwine.com Chardonnay Santa Maria Tyler Winery Bien Nacido Pinot Noir Sta Rita Hills Ampelos Cellars http://ampeloscellars.com/ Pinot Noir Lambda Reserve Rho Reserve Viognier Dragonette Cellars http://dragonettecellars.com/ In the above list, each heading is a record of each "Region" with the same LID as California in the Location table. LID = 2, so I need to list each Region within California, and within each of those listings, list each Wine that has the same RID as that Region, but grouped by their respective Wineries. Basically, there are a few Wineries that have products (child rows I believe) with differing Regions of origin. So, there are products that can have the same PID, but different RID. You can get an idea of the format from the above example. My problem is, is how would I nest the loops and queries, and what joins would be necessary? Any and all help is a godsend. This has been quite a headache.
-
Hey, I'm new to forums and also quite new to php. I was wondering is there a way to add a comment boxs but without mysql? I've got one http://mhgames.tk/commentbox.html. But all the comments go back to one page, And if I post the comment box on multiple pages I don't want them all going into the same comments. If that make sense and if I need to create a mysql database for every page.. That will take ages. More about me? - I'm making a game website with my friend. I would like to add a comment box on every page with a game. (separate comments) I've added one with mysql at the moment but all the comments go into one section. This wouldn't be helpful if I need to separate the comments for each page. Thank you, I will really appreciated.
- 3 replies
-
- php
- comment box
-
(and 2 more)
Tagged with:
-
Hello, I now have a working blog, but only want some blog posts to show. I have a table called 'post_type' and have got the numbers 1 and 2 entered. Here is the code of my blog. Should this only show the posts with 1 in the table post_type ? If not, can you please tell me what's wrong... <?php require_once('Connections/check_mag.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_check_mag, $check_mag); $query_getRecent = "SELECT news.post_id, news.title, news.post_type FROM news WHERE news.post_type = 1 ORDER BY news.updated DESC "; $getRecent = mysql_query($query_getRecent, $check_mag) or die(mysql_error()); $row_getRecent = mysql_fetch_assoc($getRecent); $totalRows_getRecent = mysql_num_rows($getRecent); $var1_getDisplay2 = "-1"; if (isset($_GET['archive'])) { $var1_getDisplay2 = $_GET['archive']; $query_getDisplay = sprintf("SELECT news.post_id,news.title, news.blog_entry, DATE_FORMAT(news.updated, '%%M %%e, %%Y') AS formatted FROM news WHERE DATE_FORMAT(news.updated, '%%Y-%%m') = %s ORDER BY news.updated DESC", GetSQLValueString($var1_getDisplay2, "text")); } elseif (isset($_GET['post_id'])) { $var2_getDisplay3 = $_GET['post_id']; $query_getDisplay = sprintf("SELECT news.post_id,news.title, news.image, news.author, news.blog_entry, DATE_FORMAT(news.updated, '%%M %%e, %%Y') AS formatted FROM news WHERE news.post_id = %s", GetSQLValueString($var2_getDisplay3, "int")); } else { $query_getDisplay = "SELECT news.post_id,news.title, news.image, news.author, news.blog_entry, DATE_FORMAT(news.updated, '%M %e, %Y') AS formatted FROM news ORDER BY news.updated DESC"; } $getDisplay = mysql_query($query_getDisplay, $check_mag) or die(mysql_error()); $row_getDisplay = mysql_fetch_assoc($getDisplay); $totalRows_getDisplay = mysql_num_rows($getDisplay); ?> <!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>Blog</title> <link href="blog.css" rel="stylesheet" type="text/css" /> <style type="text/css"> a:link { color: #82BA63; text-decoration: none; } a:visited { text-decoration: none; color: #82BA63; } a:hover { text-decoration: none; color: #6FAE4D; } a:active { text-decoration: none; color: #82BA63; } </style> <script type="text/javascript"> function MM_swapImgRestore() { //v3.0 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; } function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_swapImage() { //v3.0 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} } </script> </head> <body onload="MM_preloadImages('images/techyoucation grey.png')"> <div id="blog"> <div id="header"><a href="http://techyoucation.com/blog" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Logo','','images/techyoucation grey.png',1)"><img src="images/full logo.png" alt="techyoucation logo" width="219" height="47" id="Logo" /></a></div> <?php do { ?> <div class="blog_post"> <h4><img src="images/clock.png" width="22" height="22" alt="clock" /> <?php echo $row_getDisplay['formatted']; ?> </h4> <img src="<?php echo $row_getDisplay['image']; ?>" height="200" alt="icon" /> <div id="blog_text"><span style="color:#A0A0A0;font-family:Arial;font-size:25px;"><a href="<?php echo $row_getDisplay['post_id']; ?>"><?php echo $row_getDisplay['title']; ?></a></span><br /> <span style="color:#D0D0D0;font-family:Arial;font-size:15px;">By <?php echo $row_getDisplay['author']; ?></span><br /> <br /> <?php echo substr ($row_getDisplay['blog_entry'],0 ,500); ?>...<br /> <a href="<?php echo $row_getDisplay['post_id']; ?>">Read More</a><br /> <br /> </div> </div> <?php } while ($row_getDisplay = mysql_fetch_assoc($getDisplay)); ?><span style="color:#82BA61;font-family:Arial;font-size:17px;"> <strong>© Copyright 2013 techyoucation.com</strong> </span> </div> </body> </html> <?php mysql_free_result($getRecent); mysql_free_result($getDisplay); ?> Thanks in advance Aled
-
Hey guys! I am trying to achieve the following functionality; Use javascript to display page content that is stored on one page by showing the requested content through the navigation, i.e. clicking the Home link, and making the previous page content invisible. I have been playing around with altering the CSS styling off the div's. I have 3 div's each name; Home, Portfolio and Enquire. Here is the CSS for them; #home { display: block; } #portfolio { display: none; } #enquire { display: none; } So from this the home div is the first that is seen when the page loads. Now using the navigation I have I am calling a function; <nav class="row"> <ul> <li class="above-border"> </li> <li class="nav-smallfont">about</li> <li><a href="javascript:toggle_visibility('portfolio');" alt="Portfolio" target="_self">PORTFOLIO</a></li> <li class="above-border"> </li> <li class="nav-smallfont">back</li> <li><a href="javascript:toggle_visibility('home');" alt="Homepage" target="_self">HOME</a></li> <li class="above-border"> </li> <li class="nav-smallfont">furniture</li> <li><a href="#" onclick="toggle_visibility('enquire');" alt="Enquire" target="_self">ENQUIRE</a></li> <li class="above-border"> </li> </ul> </nav> I was playing around with the difference between onclick and javascript: - I didnt really see any major difference. Now my Javascript is this; <script type="text/javascript"> function toggle_visibility(id) { var e = document.getElementById(id); if(e.style.display == 'block'){ e.style.display = 'none'; } else{ e.style.display = 'block'; } } </script> Now whenever I click on the home navigation it will show/hide the content and when I click on say, the portfolio link it will show this content as well as the home. Im pretty sure you understand what I am hoping to achieve; A navigation style functionality so that when the portfolio link is click, it hides the other content and show only that and visa versa for the other links. Thanks for your help! Sam
- 3 replies
-
- javascript
- help
-
(and 3 more)
Tagged with:
-
Hi there, I'm trying to add a frame to my site and learning as I go. Can somebody help me understand what I'm doing wrong/not doing? Thanks in advance, Lyndon <?php $title = "THINK DIFFERENT[LY] – PR for startups. From $175."; include('includes/header.php'); $pgKeywords="PR, Public Relations, Toronto, StartUp, Entrepreneur, PR-on-demand, public relations and marketing, marketing plan plan" <section <?php include "https://www.youtube.com/watch?v=eY8owu-_n7Q"; ?> </div> ?> <section class="row"> <div class="span12"> <div id="home"> <H1>Results. Not Retainers.</H2?> </div> </div> </section> <meta name="keywords" CONTENT="Startup Public Relations, startup pr, pr for startups, startup pr firm, the public relations, public relations in, Toronto, StartUp PR, Entrepreneur, PR-on-demand, PAYG PR, Pay As You Go PR, Startup PR, THINK DIFFERENTLY, public relations for, startups, about public relations"> <?php include('includes/footer.php'); ?>
-
Hi there, I'm trying to learn basic coding - starting with some work on my own website. I'm trying to add a video frame in to a page on my website and have followed various advice online... but it's still not working. Could somebody help me understand what I'm doing/not doing? This is what I have so far. Thanks in advance, Lyndon <?php $title = "THINK DIFFERENT[LY] – PR for startups. From $175."; include('includes/header.php'); $pgKeywords="PR, Public Relations, Toronto, StartUp, Entrepreneur, PR-on-demand, public relations and marketing, marketing plan plan" <section <?php include "https://www.youtube.com/watch?v=eY8owu-_n7Q"; ?> </div> ?> <section class="row"> <div class="span12"> <div id="home"> <H1>Results. Not Retainers.</H2?> </div> </div> </section> <meta name="keywords" CONTENT="Startup Public Relations, startup pr, pr for startups, startup pr firm, the public relations, public relations in, Toronto, StartUp PR, Entrepreneur, PR-on-demand, PAYG PR, Pay As You Go PR, Startup PR, THINK DIFFERENTLY, public relations for, startups, about public relations"> <?php include('includes/footer.php'); ?>
-
Hi, I'm trying to make a infinite picture cycle in jQuery; I know how to do it in Javascript but cross-referencing languages would be a little bit more harder so I'm wondering if they're a way I can do this in jQuery? Here's what I've attempted to do but doesn't work :/ Any ideas? Thanks. <script> $.seq = function() { $(this).fadeIn(2000); $(this).delay(5000); $(this).fadeOut(300, function() { $(this).next().seq(); }); return this; }; $(document).ready(function() { $("#picture_main_1").seq(); $("#picture_main_2").seq(); $("#picture_main_3").seq(); $("#picture_main_4").seq(); }); </script>
-
Hi, here is some code for my site, where images are displayed with text underneath. It is set up in a table, but all the images and text go horizontally, and I need it to go vertically. Please help. <center> <table border="1" rules="cols" width="100%"> <tr> <? foreach($top_ratings as $key => $image) : ?> <td valign="top"><img src="http://mywebsite.com/images/<?=$image->filename?>" width="100%"/></td> <? endforeach ?> </tr> <tr> <? foreach($top_ratings as $key => $image) : ?> <td valign="top">Score: <?=$image->score?></td> <? endforeach ?> </tr> <tr> <? foreach($top_ratings as $key => $image) : ?> <td valign="top">Performance: <?=$image->performance?></td> <? endforeach ?> </tr> <tr> <? foreach($top_ratings as $key => $image) : ?> <td valign="top">Won: <?=$image->wins?></td> <? endforeach ?> </tr> <tr> <? foreach($top_ratings as $key => $image) : ?> <td valign="top">Lost: <?=$image->losses?></td> <? endforeach ?> </tr> </table> </center>
-
Hello all, This is my very first post here and I hope someone could help me out on this as it has been a labour intensive time to try and learn all about this coding. I am trying to learn this coding using PHP and trying to do stuff myself and just through a lot of research.......I have found the holy grail of all XML feeds and this was the one feed that people who look to the main steam rankings for. Ok so I am very excited to share this with you guys and show you what I have done based on how you have educated me so far, please bear with me here: Ok the XML feed (the holy grail) is the GLOBAL USER RANKINGS, there is only one site using it now: www.aoe2stats.com They are doing what I a trying to achieve and I think I am 95% there based on what you guys have taught me through the coding, ok so here it is, I hope I still have peoples attention here. here is the link to the XML FEED: http://steamcommunity.com/stats/AgeofEmpiresIIHDEdition/leaderboards/131879/?xml=1 Ok, this information I am trying to extract is the following: http://steamcommunity.com/stats/Ageo...l=1&start=5001 ]]> </nextRequestURL> <resultCount>5000</resultCount> <entries> <entry> <steamid>76561198032048763</steamid> <score>689</score> <rank>1</rank> <ugcid>-1</ugcid> <details> <![CDATA[ ]]> </details> </entry> <entry> <steamid>76561198011427258</steamid> <score>632</score> <rank>2</rank> <ugcid>-1</ugcid> <details> <![CDATA[ ]]> ___________________________________________________ Into a table with 4 columns, with the names on each column: Steam Name - Score - Rank - Ugcid Now this is where I am learning also, I need to parse the (steamid) into the (community id) the steam id is the long number above and the community id is username on steam: website to show example: steamidfinder.com ok I have found a script to parse the <steamid>76561198032048763</steamid> into the person name: Huehnerbein as an example above, so I have been doing a lot of reaearching and I have found the following: _____________________________________________________________ Assuming that your input steam_id is $INPUT and your final output array is stored in $OUTPUT, this is the functional for each approach that you could use to convert steam_id to personaname: /** * Convert steam_id to personaname * @returns STRING The name associated with the given steam_id * BOOL FALSE if no match was found */ function steamID_to_name($INPUT, $OUTPUT) { // This gets the relevant part of the API response. $array = $OUTPUT['response']['players']; // Using your function to convert `steam_id` to a community ID $community_id = SteamID2CommunityID($INPUT); // Linear search foreach ($array as $array_item) { // If a match was found... if ($community_id == $array_item['steamid']) // Return the name return $array_item['personaname']; } // If no match was found, return FALSE. return false; } _________________________________________________________________ So the conclusion is the script below, unfortunately is does not work but I have tried to change the neccesary parameters in the script, so the objective is: as what www.aoe2stats.com are the only ones who have done it!! To have the 4 entries in a 4 column table: Steam Name - Score - Rank - Ugcid and to have the steamid parse into the community_id or username. OK THE ACTUAL SCRIPT I HAVE MODIFIED, IT DOES NOT WORK BUT CAN YOU GUYS SHARE WITH ME WHAT MISTAKES I HAVE MADE SO I CAN GET THIS HOLY GRAIL SCRIPT WORKING, I HAVE SPENT HOURS ON THIS: SCRIPT BELOW: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ <?php header("Cache-Control: no-cache, must-revalidate"); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); $sFeed = 'http://steamcommunity.com/stats/AgeofEmpiresIIHDEdition/leaderboards/131879/?xml=1' . microtime(true); /** * Convert steam_id to personaname * @returns STRING The name associated with the given steam_id * BOOL FALSE if no match was found */ function steamID_to_name($INPUT, $OUTPUT) { // This gets the relevant part of the API response. $array = $OUTPUT['response']['players']; // Using your function to convert `steam_id` to a community ID $community_id = SteamID2CommunityID($INPUT); // Linear search foreach ($array as $array_item) { // If a match was found... if ($community_id == $array_item['steamid']) // Return the name return $array_item['personaname']; } // If no match was found, return FALSE. return false; } $dom = new DOMDocument('1.0', 'utf-8'); $dom->load($sFeed); $steamid = $dom->getElementsByTagName('steamid'); if ($entry->length > 0) $score = $dom->getElementsByTagName('score'); if ($entry->length > 0) $rank = $dom->getElementsByTagName('rank'); if ($entry->length > 0) $ugcid = $dom->getElementsByTagName('ugcid'); if ($entry->length > 0) { ?> <style> table, td, th body { font-family:Verdana, Arial, Helvetica; font-size: 81%; margin: 0px; color: #5c3d0b; font-weight:bold; } { border:1px solid black; } th { background-color:e6cb9c; } </style> <table border="1"> <tr> <th>NAME</th> <th>SCORE</th> <th>RANK</th> <th>UGCID</th> </tr> <? foreach ($entry AS $entry) { $steamid = $entry->getElementsByTagName('steamid')->item(0)->nodeValue; $score = $entry->getElementsByTagName('score')->item(0)->nodeValue; $rank = $entry->getElementsByTagName('rank')->item(0)->nodeValue; $ugcid = $entry->getElementsByTagName('ugcid')->item(0)->nodeValue; printf("<tr><td>%s</td><td>%s</td></tr>" . PHP_EOL, $name, $percent); } print('</table>'); } ___________________________________________________________________ OK PLEASE PLEASE GUYS WOULD LOVE TO SEE WHAT I HAVE DONE WRONG TO GET THIS SCRIPT WORKING SO MANY THANKS!!
-
MYSQL version: 5.5.24 I've got a problem. For my project in a class I want to show the characters of the person who is currently logged in. I get it to show every character in the database "characters" but not the logged in. I've tried to put this code in the WHERE but it will just ignore it and all of the other code jsut gets commented away when I do the "" to make it visible (in php) a friend of mine have written a C++ program that does this exact same thing altough I don't get it to work. So my question is what should I put in the WHERE to get the characters.name of the "current user" I've thought of making the: WHERE accounts.id = " . htmlentities($_SESSION['username'] ." Altough these two " makes so the rest of the code gets commented away and I've tried to put an extra " but nothing happens and I need the two " too make the htmlentities correct. I know this is both PHP and MYSQL but since it's the SQL part I need help with I put it here. If any admin see this as the wrong place to have my post please move it in that case or tell me to redo it at the right place
- 8 replies
-
- help
- show current users characters
-
(and 2 more)
Tagged with:
-
Hello phpfreaks I found a basic php upload script which i find really useful but I have a problem, I'm new to php programming and need help in this code: <? $upload = $_GET["upload"]; if ($upload == "now") { $path1 = "uploads/"; $path="$path1".$_FILES['ufile']['name']; if($ufile !=none) { if(copy($_FILES['ufile']['tmp_name'], $path)) { echo "Success!<BR/>"; echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2; URL=uploads/\">"; } else { echo "<font color=red><b>Error!</b></font>"; } } } else { ?> <table width="250" border="0" align="left" cellpadding="0" cellspacing="1"> <tr> <form action="?upload=now" method="post" enctype="multipart/form-data"> <td> <table border="0" cellpadding="3" cellspacing="1"> <tr> <td>Select file <input name="ufile" type="file" id="ufile" /></td> </tr> <tr> <td align="left"><input type="submit" name="Submit" value="Upload" /></td> </tr> </table> </td> </form> </tr> </table> <a href="uploads">View Uploads</a> <? } ?> I want the script to change the name of a file to random numbers after being uploaded for example: If a person uploaded a file called: "catherine.jpg" The script will automatically rename it to: "1231421421421.jpg" while providing a link to the uploaded file. How can I do that? any help would be appreciated Thanks in advance, and sorry for my bad english.
-
<?php //session status block include "connect_to_mysql.php"; ?> <?php //script error reporting //error reporting error_reporting(E_ALL); ini_set('display_errors','1'); ?> <?php //parse form data to database //parse the form data and add inverntory items to the system //CHANGE ALL VALUES TO SUIT NEEDS OF CURRENT DATABASE //FORM DATA AND ADD BOOK TO THE SYSTEM DATABASE if (isset($_POST['BOOKNAME'])) { $BOOKNAME = mysql_real_escape_string($_POST['BOOKNAME']); $BOOKPRICE = mysql_real_escape_string($_POST['BOOKPRICE']); $CATEGORY = mysql_real_escape_string($_POST['CATEGORY']); $BOOKDESCRIPTION = mysql_real_escape_string($_POST['BOOKDESCRIPTION']); // See if that product name is an identical match to another product in the system $sql = mysql_query("SELECT ID FROM BOOK WHERE BOOKNAME='$BOOKNAME' LIMIT 1"); // Add this product into the database now $sql = mysql_query("INSERT INTO BOOK (BOOKNAME, BOOKPRICE, BOOKDESCRIPTION, CATEGORY, DATE) VALUES('$BOOKNAME','$BOOKPRICE','$BOOKDESCRIPTION','$CATEGORY',now())") or die (mysql_error()); $pid = mysql_insert_id(); // Place image in the folder $newname = "$pid.jpg"; move_uploaded_file( $_FILES['fileField']['tmp_name'], "inventory_images/$newname"); echo 'Book Successfully Uploaded <a href="index.php"><b>Click Here To Go To Home Page</b></a>'; exit(); } ?> <?php //this block grab the whole list for viewing //THIS BLOCKS GRABS THE WHOLE LIST FOR VIEWING $product_list = ""; $sql = mysql_query("SELECT * FROM BOOK ORDER BY date_added DESC"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { while($row = mysql_fetch_array($sql)){ $ID = $row["ID"]; $BOOKNAME = $row["BOOKNAME"]; $CATEGORY = $row["CATEGORY"]; $BOOKDESCRIPTION = $row["BOOKDESCRIPTION"]; $BOOKPRICE = $row["BOOKPRICE"]; $product_list = "Product ID: $ID - <strong>$BOOKNAME</strong> - $$BOOKPRICE - <em>Added $date_added</em> • <br />"; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); } } else { $product_list = "There are currently no books for sale, check back soon !"; } ?> <!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>NTU Book Browser</title> <link rel="stylesheet" href="style.css" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script> $(function() { $("#text-one").change(function() { $("#text-two").load("textdata/" + $(this).val() + ".txt"); }); }); </script> </head> <body> <div id="wrapper"> <?php include_once("template_header.php");?> <div id="wrapper_content"> <div id="headers"> <h2> Books </h2> </div> <div id="main"> <div id="add_item"> <p><i> <a href="books.php#bookForm">+Sell Book</a></i></p> </div> <?php echo $product_list; ?> <a name="bookForm" id="bookForm"></a> <h3> Add New Book Form </h3> <form action="books.php" enctype="multipart/form-data" name="myForm" id="myform" method="post"> <table width="90%" border="0" cellspacing="0" cellpadding="6"> <td align="right">Book Name</td> <td><select name="CATEGORY" id="text-one"> <option selected value="base">Select Book Category</option> <option value="biomedicalscience">Biomedical Science</option> <option value="history">History</option> <option value="spanish">Spanish</option> <option value="economics">Economics</option> <option value="sportsscience">Sports Science</option> <option value="forensicsscience">Forensics Science</option> <option value="computersystems">Computer Systems</option> <option value="english">English</option> <option value="psychologyandeducation">Psychology and Education</option> </select> </td> <br /> <td align="right"></td> <td> <select name="BOOKNAME" id="text-two"> <option>Select Book</option> </select> </td> </tr> <tr> <td align="right">Book Price</td> <td><label> £ <input name="BOOKPRICE" type="text" id="BOOKPRICE" size="12" /> </label></td> </tr> <tr> <tr> <tr> <td align="right">Book Description</td> <td><label> <textarea name="BOOKDESCRIPTION" id="description" cols="64" rows="5"></textarea> </label></td> </tr> <tr> <td align="right">Book Image</td> <td><label> <input type="file" name="fileField" id="fileField" /> </label></td> </tr> <tr> <td> </td> <td><label> <input type="submit" name="button" id="button" value="Add Book" /> </label></td> </tr> </table> </form> </div> <div id="footer"> <?php include_once("template_footer.php");?> </div> </div> </div> <div class="clear"></div> </body> </html>
-
Hi, I'm trying to make it so when the height of the browser is more than '900' it changes the style type bottom to 0. Here's my code but it doesn't work? Thanks. <script type="text/javascript"> function changeHeightLimit() { if(window.innerHeight >= 900) { document.getElementById("footer").style.bottom="0"; } } </script>
-
- footer
- javascript
-
(and 1 more)
Tagged with:
-
Hello everyone! I'm adding new fields to the feedback.tpl in DLE. The file is in engine/ajax/feedback.tpl Here is the code: $row['template'] = stripslashes( $row['template'] ); $row['template'] = str_replace( "{%username_to%}", $recipient['fullname'], $row['template'] ); $row['template'] = str_replace( "{%username_from%}", $name, $row['template'] ); $row['template'] = str_replace( "{%text%}", $message, $row['template'] ); $row['template'] = str_replace( "{%ip%}", $_SERVER['REMOTE_ADDR'], $row['template'] ); if(if(empty($_POST[team])) $_POST[team] = "none"; $row['template'] = str_replace( "{%team%}", strip_tags($_POST[team]), $row['template'] ); I'm adding the field, called 'team' and get this error: syntax error, unexpected T_IF But when I remove the first if and bracket, everything works fine, but I always get 'none' result, like the field is empty, but it's not... Help please ^^
-
Hi all, I am working on a project where I am creating a travel agency website. At the moment I am trying to get my search engine to get the details and show the result into next page, but nothing is working. can anyone please help? thanks in advance. sorry for my messy code as I AM VERY NEW TO PHP Here are my codes for the form on index.php <form id="search" Name ="sEngine" Method ="POST" ACTION ="search.php" style="background-image:url(images/background.jpg)"> <h2>Search Flights</h2> <fieldset> <input type = "radio" name = "type" id = "return" value = "yes" checked = "checked" /> <label for = "return">Return</label> <input type = "radio" name = "type" id = "single" value = "no" /> <label for = "single">Single</label> </fieldset> <fieldset id="des"> <ul> <li> <label for="depAirport">Deperture airport</label> <input type="text" id="depAirport" name="depAirport" placeholder="Type destination airport" required autofocus> </li> <li> <label for="arrAirport">Arrival airport</label> <input type="text" id="arrAirport" name="arrAirport" placeholder="Type arrival airport" required> </li> <li> <label for="dDate">Departure date</label> <input type="date" id="dDate" name="dDate" required> </li> <li> <label for="rdate">Return date</label> <input type="date" id="rDate" name="rDate" required> </li> </ul> </fieldset> <fieldset> <label for="adult" style="margin-left:10px;">Adult</label> <input type="number" id="adult" name="adult" min="1" max="20"> <label for="child" style="margin-left:8px;">Child </label> <input type="number" id="child" name="child" min="0" max="10"> <label for="infants" style="margin-left:8px;">Infants </label> <input type="number" id="infants" name="infants" min="0" max="10"> </fieldset> <fieldset> <label for="clsType" style="margin-left:80px;">Class type</label> <select id = "myList" name="myList"> <option value = "1" selected="selected">Economy</option> <option value = "2">Premium Economy</option> <option value = "3">Business</option> <option value = "4">First</option> </select> </fieldset> <br/> <button type= "submit" onclick="myfunc()">Search Now!</button> </form> Here are my codes for search.php <?php mysql_connect("localhost", "root", "masnobi");mysql_select_db("airline_database"); ?> <?php function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } $name=mysql_real_escape_string($_POST['depAirport']); //This value has to be the same as in the HTML form file $email=mysql_real_escape_string($_POST['arrAirport']); //This value has to be the same as in the HTML form file $sql= "SELECT * from 'flight' WHERE (departure_airport ='$depAirport' , arrival_airport = '$arrAirport', departure_date ='$dDate')"; echo "<table id='box' border='1' cellpadding='2' summary='Table holds flight information'> <tr> <th>flight_id</th> <th>flight_no</th> <th>departure_airport</th> <th>arrival_airport</th> <th>departure_date</th> <th>arrival_date</th> <th>flight_price</th> <th>flight_duration</th> <th>flight_name</th> </tr>"; while ($row = mysql_fetch_array($result)) {echo "<tr>"; echo "<td>" . $row['flight_id'] . "</td>"; echo "<td>" . $row['flight_no'] . "</td>"; echo "<td>" . $row['departure_airport'] . "</td>"; echo "<td>" . $row['arrival_airport'] . "</td>"; echo "<td>" . $row['departure_date'] . "</td>"; echo "<td>" . $row['arrival_date'] . "</td>"; echo "<td>" . '£' . $row['flight_price'] . "</td>"; echo "<td>" . $row['flight_duration'] . "</td>"; echo "<td>" . $row['flight_name'] . "</td>"; echo "</tr>"; } ?>
-
Hi, how would I make it so that my page returns and echos database information? I've used the mysqli method in most of my coding, examples below and basically I want it so that it querys the firstname and lastname to the correct session id. I managed to do something like this before by doing a $row search but the problem with that was that it was returning all of the first and lastnames not one that matches the id to the database. I know you can do $row searches but I'm not too sure on those and the ones that were shown are not safe as it displays things like the database name, database password ect in that document where I've done an include like > include 'dbConfig.php'; (Also please note even though it hasn't got any includes, that's because the pages themselves are includes and all the includes that are needed such as the database one, I've declared on previous pages.) How I would like it to work: <?php Do some kind of safe row search up here. if(<USERS ID IS VALID THEN DO THIS>) { Echo the firstname and lastname here. } ?> How I've tried to do it: <?php if ($stmt = $mysqli->prepare("SELECT id, firstname, lastname FROM users WHERE firstname = ? AND lastname = ? LIMIT 1")) { $stmt->execute(); $stmt->store_result(); $stmt->bind_result($user_id, $firstname, $lastname); $stmt->fetch(); if($stmt->num_rows == 1) { $_SESSION['user_id'] = $user_id; $_SESSION['firstname'] = $firstname; $_SESSION['lastname'] = $lastname; echo $firstname; echo $lastname; return true; } } ?>
-
Hi, I am Alfredo and I am 11 years old. I really want to lean php and other web development things. But I get confused when I see there are so many things. Makes my head spin. Tried w3 school, lynda.com. But as you people know php and all other stuffs in web development are huge and too much elaborate. I need a clear guide line. One day I start one thing and next day another. Eventually I am learn nothing All I want to become a good web developer. Please suggest me what should I do. Which thing I should start 1st, like html etc. and from where (lynda.com ; w3school; for dummies book ; youtube) Please give me some advice beginning to end (to become good web developer) Please help me and thank you, Alfredo off the topic: How much time a day I should spend on learning if I want to become a web developer in a year? [i know this is a stupid question but would love to know]
- 5 replies
-
- introduction
- help
-
(and 3 more)
Tagged with:
-
Hi, I am currently working on completing an online computer science course, and am in the last few weeks, with just a few programs left, but that said time is of the essence. What I am working on right now is a program that will let you buy and sell stocks. No transactions actually occur, it only looks like you are buying and selling. I was given a framework to start with, here I have linked to a example completed project: http://finance.cs50.net/login.php I am getting close, but am having some trouble with the "buy" function. Here is my php code for buy: <?php // configuration require("../includes/config.php"); // if form was submitted if ($_SERVER["REQUEST_METHOD"] == "POST") { if (((empty($_POST["symbol"])) == True) || ((empty($_POST["shares"])) == True)) { apologize("You MUST enter the Symbol, and ammount of stock that you want!"); } else if (preg_match("/^\d+$/", $_POST["shares"]) == False) { apologize("You must enter a postive whole number for the number of shares you want to buy!"); } else { $stock = lookup($_POST["symbol"]); $rows = query("SELECT LAST_INSERT_ID() AS id"); $id = $rows[0]["id"]; INSERT INTO table (id, symbol, shares) VALUES(7, , 10) ON DUPLICATE KEY UPDATE shares = shares + VALUES(shares) redirect("index.php"); } } else { // else render form render("buy_stock.php", ["title" => "Buy "]); } ?> And here is the code for the html front page of buy: <form action="buy.php" method="post"> <fieldset> <div class="control-group"> <input autofocus name="symbol" placeholder="SYMBOL" type="text"/> </div> <div class="control-group"> <input name="shares" placeholder="Number of shares" type="int"/> </div> <div class="control-group"> <button type="submit" class="btn">BUY</button> </div> </fieldset> </form> <div> or <a href="index.php">Home Page</a> </div> Here is a program defining functions, this program was provided buy the course: <?php /*********************************************************************** * functions.php * * Computer Science 50 * Problem Set 7 * * Helper functions. **********************************************************************/ require_once("constants.php"); /** * Apologizes to user with message. */ function apologize($message) { render("apology.php", ["message" => $message]); exit; } /** * Facilitates debugging by dumping contents of variable * to browser. */ function dump($variable) { require("../templates/dump.php"); exit; } /** * Logs out current user, if any. Based on Example #1 at * http://us.php.net/manual/en/function.session-destroy.php. */ function logout() { // unset any session variables $_SESSION = array(); // expire cookie if (!empty($_COOKIE[session_name()])) { setcookie(session_name(), "", time() - 42000); } // destroy session session_destroy(); } /** * Returns a stock by symbol (case-insensitively) else false if not found. */ function lookup($symbol) { // reject symbols that start with ^ if (preg_match("/^\^/", $symbol)) { return false; } // reject symbols that contain commas if (preg_match("/,/", $symbol)) { return false; } // open connection to Yahoo $handle = @fopen("http://download.finance.yahoo.com/d/quotes.csv?f=snl1&s=$symbol", "r"); if ($handle === false) { // trigger (big, orange) error trigger_error("Could not connect to Yahoo!", E_USER_ERROR); exit; } // download first line of CSV file $data = fgetcsv($handle); if ($data === false || count($data) == 1) { return false; } // close connection to Yahoo fclose($handle); // ensure symbol was found if ($data[2] === "0.00") { return false; } // return stock as an associative array return [ "symbol" => $data[0], "name" => $data[1], "price" => $data[2], ]; } /** * Executes SQL statement, possibly with parameters, returning * an array of all rows in result set or false on (non-fatal) error. */ function query(/* $sql [, ... ] */) { // SQL statement $sql = func_get_arg(0); // parameters, if any $parameters = array_slice(func_get_args(), 1); // try to connect to database static $handle; if (!isset($handle)) { try { // connect to database $handle = new PDO("mysql:dbname=" . DATABASE . ";host=" . SERVER, USERNAME, PASSWORD); // ensure that PDO::prepare returns false when passed invalid SQL $handle->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); } catch (Exception $e) { // trigger (big, orange) error trigger_error($e->getMessage(), E_USER_ERROR); exit; } } // prepare SQL statement $statement = $handle->prepare($sql); if ($statement === false) { // trigger (big, orange) error trigger_error($handle->errorInfo()[2], E_USER_ERROR); exit; } // execute SQL statement $results = $statement->execute($parameters); // return result set's rows, if any if ($results !== false) { return $statement->fetchAll(PDO::FETCH_ASSOC); } else { return false; } } /** * Redirects user to destination, which can be * a URL or a relative path on the local host. * * Because this function outputs an HTTP header, it * must be called before caller outputs any HTML. */ function redirect($destination) { // handle URL if (preg_match("/^https?:\/\//", $destination)) { header("Location: " . $destination); } // handle absolute path else if (preg_match("/^\//", $destination)) { $protocol = (isset($_SERVER["HTTPS"])) ? "https" : "http"; $host = $_SERVER["HTTP_HOST"]; header("Location: $protocol://$host$destination"); } // handle relative path else { // adapted from http://www.php.net/header $protocol = (isset($_SERVER["HTTPS"])) ? "https" : "http"; $host = $_SERVER["HTTP_HOST"]; $path = rtrim(dirname($_SERVER["PHP_SELF"]), "/\\"); header("Location: $protocol://$host$path/$destination"); } // exit immediately since we're redirecting anyway exit; } /** * Renders template, passing in values. */ function render($template, $values = []) { // if template exists, render it if (file_exists("../templates/$template")) { // extract variables into local scope extract($values); // render header require("../templates/header.php"); // render template require("../templates/$template"); // render footer require("../templates/footer.php"); } // else err else { trigger_error("Invalid template: $template", E_USER_ERROR); } } ?> I have been working on getting BUY working for the whole day, but have had nothing but errors... Does anything jump out as a problem to anyone??? If I haven't given you enough info, please let me know! Thanks in advance, I really am stuck on this one, and am running out of time, as this is not my last program. Josh
- 7 replies
-
- help
- computer-science
-
(and 2 more)
Tagged with:
-
Hello phpfreaks community, I really need your advice regarding this situation. In this program what i wanted is to fetch data from the database (sols.sql then grade_summary table) and show it in form18af.php by submit button from another page. Note: - subjects are dynamic - name of students appear more than once in the table - form18af.php is currently static - other tables were truncated from the system Please, i need your help and forgive me if my coding is noobish. Yeah, my friend suggested using arrays but i can't grasp the logic.. help.zip
- 4 replies
-
- fetch array tables help
- fetch
-
(and 3 more)
Tagged with:
-
Hi, I'm just wondering but if my webhost has SQL version 5.1, what are the syntax of that for PHP login & register forms? So like $q = "INSERT INTO `Table1` (`username`,`password`,`email`) " ."VALUES ('".$_POST["username"]."', " ."PASSWORD('".$_POST["password"]."'), " ."'".$_POST["email"]."')"; Would this be the right use of syntax? I'm having a few problems with making a clean and safe php login and register form. Thanks.
-
Warning: mysql_num_rows() expects parameter 1 to be resource
grifb posted a topic in PHP Coding Help
help!!! i have been trying things all day with this and it wont work! <html> <div align="center"> <?php $key = $_POST['key']; $answer = $_POST['answer']; $username = $_POST['username2']; $item = explode(" ", $key); $final = $item[0]; $removals = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"); $lower = str_replace($removals, "", $final); $newkey = strtolower($lower); $areplace = str_replace("," , "', '", $answer); $buff = "['$areplace']"; $finalanswer = strtolower($buff); if ($key&&$username&&$answer) { $connect = mysql_connect("fakedatabase","fakeuser", "fakepassword") or die("Couldn't Connect"); mysql_select_db("wordlist") or die("No Table"); $query = mysql_query("SELECT * FROM keylist WHERE keys='$newkey'"); $numrows = mysql_num_rows($query); echo $numrows; if ($numrows!=0) { $queryadduser1 = mysql_query("INSERT INTO userkeys Values('$username', 'Tried : $newkey')") or die("Unable to connect"); die("The key '$newkey' has already been added!"); } else $queryadd = mysql_query("INSERT INTO keylist Values('$newkey')") or die("Unable to connect"); $queryadd2 = mysql_query("INSERT INTO KeysAndAnswers Values('$newkey', '$finalanswer')") or die("Unable to connect"); $queryadduser1 = mysql_query("INSERT INTO userkeys Values('$username', 'Added : $newkey ')") or die("Unable to connect"); echo("The key '$newkey' and the answer '$finalanswer' Has just been submitted! Thank you!"); } else die("Key or answer or username was blank"); ?> </div> </html> You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'keys='123-123'' at line 1 -
Hey everyone! It's been a while ^^ So I've run into a regex problem, it was never my strong point tbh, however, I've come across an issue I can't seem to find a solution to Basically I'm using the following regex to check if a password meets the requirements, which are: Contains a letter Contains a number Can use only A to Z, a to z, 0 to 9 and any of these in the password too:!@#$%. What's going on? Heres line 81, and the error I'm getting. elseif(preg_match('^(?=.*\d+)(?=.*[A-z])[0-9A-z!@#$%]$', $pwds['pwd'])!=1) $problems['pwd']='Passwords must contain one letter and number. Also allowed: .!@#$%'; A PHP Error was encountered Severity: Warning Message: preg_match(): No ending delimiter '^' found Filename: controllers/daemon.php Line Number: 81 Thanks! Gergy.
-
Hi, I'm trying to create a Login & Register form which will create a profile for that user but I'm getting a lot of problems and I can't seem to figure out why it's not working correctly? I've created a post on the forums before about this problem but the problem was never resolved, I am new to PHP hence my noobieness. Basicly the problem at the moment is when I try to login it gives me a 'Wrong details error' which is expressed like so: elseif(!mysql_num_rows($r)) { $errorMsg = "* Sorry, couldn't log you in. Wrong login information."; } As far as the register form goes, it works fine to my knowledge as it's adding users to the database when they register and it's encrypting their passwords by using the crypt(); function. I'll link the Login form, the register form and the dbConfig below but I'll replace any sensitive details with '-HIDDEN-' for safety. I would really appreshiate if someone could help me out on this one cause I've been stuck with this problem for quite a while now and I can't figure it out, thanks a lot Register.php <?php include ("dbConfig.php"); if ($_SERVER['REQUEST_METHOD'] == "POST") { $usernameSQL = mysql_real_escape_string($_POST['username']); $emailSQL = mysql_real_escape_string($_POST['email']); $passwordSQL = mysql_real_escape_string($_POST['password']); $passwordSQL = crypt('$password'); $q = "INSERT INTO -HIDDEN-(username, email, password)VALUES('$usernameSQL', '$emailSQL', '$passwordSQL')"; $r = mysql_query($q); header("Location: register.php?op=thanks"); } ?> <form action="?op=reg" method="POST"> Username:<br><font color="red">*</font><input class="GeneralForm" type="text" name="username" id="username" maxlength="20"><br> <br> Email:<br><font color="red">*</font><input class="GeneralForm" type="text" name="email" id="email" maxlength="50"><br> <br> Password:<br><font color="red">*</font><input class="GeneralForm" type="password" name="password" id="password" maxlength="50"><br> <br> <input type="checkbox" name="tick"><font color="gray" size="3"> I agree to the Terms of Use<br> <br> <button type="submit" name="submit" class="InputButton" value="Submit">Submit</button> </form> <br><font size="2" color="gray">* You can edit details on your profile when you login!</font> Login.php <?php session_start(); include "dbConfig.php"; $errorMsg = ""; if ($_GET["op"] == "fail") { $errorMsg = "* You need to be logged in to access the members area!"; } if ($_SERVER['REQUEST_METHOD'] == "POST") { $username = trim($_POST["username"]); $password = trim($_POST["password"]); if (empty($username) || empty($password)) { $errorMsg = "* You need to provide a username & password."; } else { $usernameSQL = mysql_real_escape_string($username); $passwordSQL = crypt('$password'); $q = "SELECT id FROM -HIDDEN- WHERE username='{$usernameSQL}' AND password='{$passwordSQL}' LIMIT 1"; $r = mysql_query($q) or die("Error: " . mysql_error() . "<br>Query: " . $q); if(!$r) { //Error running query $errorMsg = "* Wrong username or password."; } elseif(!mysql_num_rows($r)) { //User not found $errorMsg = "* Sorry, couldn't log you in. Wrong login information."; } else { // Login good, create session variables and redirect $_SESSION["valid_id"] = $obj->id; $_SESSION["valid_user"] = $username; $_SESSION["valid_time"] = time(); // Redirect to member page header("Location: members.php"); } } } ?> <form action="?op=login" method="POST"> Username:<br> <input class="GeneralForm" type="text" name="username" id="username" maxlength="20" value="<?php echo htmlentities($usernameSQL); ?>"> <br><br> Password:<br> <input class="GeneralForm" type="password" name="password" id="password" maxlength="50"> <br><br> <button type="submit" name="Submit" class="InputButton" value="Login">Login</button> <h1 class="FailLoginState"><?php echo $errorMsg; ?></h1> </form> dbConfig.php <? $host = "-HIDDEN-"; $user = "-HIDDEN-"; $pass = "-HIDDEN-"; $db = "-HIDDEN-"; $ms = mysql_pconnect($host, $user, $pass); if ( !$ms ) { echo "Error connecting to database.\n"; } mysql_select_db($db); ?>