PHP - New To Php, Looking For A Couple Basic Fixes
I'm working with a payment module for a zencart template. The files are in PHP and I know some HMTL over the years, but never touched PHP coding.
Here are three lines of text in my PHP....
define('MODULE_PAYMENT_DOLLARS_TEXT_TITLE', 'Pay with dollars!'); define('MODULE_PAYMENT_PAYPALWPP_MARK_BUTTON_TXT', 'Checkout with PayPal.'); define('MODULE_PAYMENT_PAYPALEC_MARK_BUTTON_IMG', 'https://www.paypalobjects.com/en_US/i/logo/PayPal_mark_37x23.gif'); Similar TutorialsOk, so I'm trying to develop/remake a web based browser game that I used to play back in 2006. I've got a fair amount set up, considering I knew nothing about php/mysql about a week ago. However, I've made a registration process, login system, and the game pages (member only). However, I was talking to some people the other day, and I'm using MD5 to encrypt the passwords. The suggestion given to me was to use SHA2 with Salt. The problem that I'm facing is that no matter what I try, I can't seem to get the system working.. I've followed the advice originally recieved: no success. I've followed a tutorial online: no success. SO, I was wondering if someone from here could help me. My database has the extra 'salt' field setup.. and here's my uneddited working MD5 code: Code: [Select] <?php //Start session session_start(); //Include database connection details require_once('config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $email = clean($_POST['email']); $login = clean($_POST['login']); $password = clean($_POST['password']); $cpassword = clean($_POST['cpassword']); $empire_name = clean($_POST['empire_name']); $race = clean($_POST['race']); $referrer = clean($_POST['referrer']); //Input Validations if($email == '') { $errmsg_arr[] = 'Email missing'; $errflag = true; } if($login == '') { $errmsg_arr[] = 'Username missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } if($cpassword == '') { $errmsg_arr[] = 'Confirm password missing'; $errflag = true; } if( strcmp($password, $cpassword) != 0 ) { $errmsg_arr[] = 'Passwords do not match'; $errflag = true; } if($empire_name == '') { $errmsg_arr[] = 'Empire Name missing'; $errflag = true; } if($race == '') { $errmsg_arr[] = 'Race not selected'; $errflag = true; } if(strlen($login) > 20) { $errmsg_arr[] = 'Username exceeds allowed charachter limit'; $errflag = true; } if(strlen($empire_name) > 20) { $errmsg_arr[] = 'Empire Name exceeds allowed charachter limit'; $errflag = true; } //Check for duplicate login ID if($login != '') { $qry = "SELECT * FROM members WHERE login='$login'"; $result = mysql_query($qry); } if($result) { if(mysql_num_rows($result) > 0) { $errmsg_arr[] = 'Username already in use'; $errflag = true; } @mysql_free_result($result); } else { die("Query failed"); } //Check for duplicate Empire Name if($empire_name != '') { $qry = "SELECT * FROM members WHERE empire_name='$empire_name'"; $result = mysql_query($qry); } if($result) { if(mysql_num_rows($result) > 0) { $errmsg_arr[] = 'Empire Name already in use'; $errflag = true; } @mysql_free_result($result); } else { die("Query failed"); } //If there are input validations, redirect back to the registration form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location:register-form.php"); exit(); } //Create INSERT query $qry = "INSERT INTO members(email, login, passwd, empire_name, race, referrer) VALUES('$email','$login','".md5($_POST['password'])."','$empire_name','$race','$referrer')"; $result = @mysql_query($qry); //Check whether the query was successful or not if($result) { header("location: register-success.php"); exit(); }else { die("Query failed"); } ?> My second question is: I've got a set of permissions in my members database.. These are guest, player, mod and admin. I'm currently running my updates page by calling the updates from the database... How would i go about adding a link to the first page you come to (after logging in) that can only be seen by members who are in the admin permission? Because I'd like to make an admincp with a page to submit a form to the database that updates the updates page.. However, I'd rather the link to it only showed up for me and was invisible to other members.. Again, I'm only asking because I cant seem to find any information online at any tutorials or worksheets that I've come across.. And believe me, I've been searching quite a bit.. :/ Any help would be very much appreciated.. Cheers, /zythion/ Ok If anyone read my recent topics they will know I am making a forum system This system for users is currently about 1/3 complete and I now have a couple of issues. Firstly: When a user logs in I am using $_SESSION['RAYTH_MEMBER_ID'] to save their member ID for when they return. However every time the browser/page is closed it doesn't save and then they are logged out. How would I set it so it keeps them logged in until they personally logout? Secondly: Since It's a forum you expect there to be new lines and stuff when you Read posts in threads (like we do here). How would I set it when a user posts it replaces every return character from the input (enter/newline etc) and replace it with <br> in the mysql database? Thanks for your help This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=330539.0 I am trying to store website address in a variable but when I do so the dots in the address are missing. I guess it takes it as string concatenation, for example: $address='www.lottocomplete.com'; will actually give me: wwwlottocompletecom How can I make sure these dots will be preserved? I am also trying to store email address in a variable but I get error, something about @ symbol being in wrong spot, wonder how this can be resolved as well. One more questions relates to the new line issue that I have when I concatenate string, for example if I do the following: $string = "1\n"; $string .= "2\n"; $string .= "3\n"; I would think that each number would be printed on new line but instead it shows up as: 123 What am I doing wrong? Having trouble figuring this out. 1) How can I check whether the user's input for a field is an integer with a value greater than 0? Was thinking of using regular expressions using 1-9 but then 10 might result in an error and that's not wanted. 2) For a field that's a drop-down, how can I have an error show if they choose the default option (value of "none") Thanks for the help. Hi, I have a search form which pulls info from a MySQL table and there are a few enhancements I would like to make. 1) I would like the search terms in my results table hilited in red. I made a class in my stylesheet for this, but it isn't working so I am missing a step or two 2) I would like a display for the number of results returned. Example. "There were 3 results found in your search". 3) This isn't php related, but if anyone has any ideas why my JQuery slideup doesn't work with my results let me know. I have posted in the JavaScript section, but haven't gotten a response. My code. Code: [Select] <html> <head> <link href="default.css" rel="stylesheet" type="text/css" media="screen" /> <script src="js/jquery.js"></script> <script src="js/jquery-fonteffect-1.0.0.js"></script> <script type="text/javascript"> $("#mirror").FontEffect({ outline:true }) </script> <script type='text/javascript'> var $ = jQuery.noConflict(); $(document).ready(function(){ $("#search_results").slideUp(); $("#search_button").click(function(e){ e.preventDefault(); ajax_search(); }); // $("#search_term").keyup(function(e){ // e.preventDefault(); // ajax_search(); // }); }); function ajax_search(){ $("#search_results").show(); var search_val=$("#search_term").val(); $.post("./find.php", {search_term : search_val}, function(data){ if (data.length>0){ $("#search_results").html(data); $(document).ready(function(){ $(".stripeMe tr").mouseover(function(){$(this).addClass("over");}).mouseout(function(){$(this).removeClass("over");}); $(".stripeMe tr:even").addClass("alt"); }); } }) } </script> <meta http-equiv="Content-Type" content="text/html; charset=iso- 8859-1" /> <title>Novo RPC Results Search Engine</title> <link href="default.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="mirror">Search RPC participants</div> <form id="searchform" method="post" action="find.php"> <div> <label for="search_term">Search RPC information</label> <input type="text" name="search_term" id="search_term" /> <input type="submit" value="search" id="search_button" /> </div> </form> <div id="search_results"></div> </body> </html> <?php define(HOST, "localhost"); define(USER, "username"); define(PW, "pw"); define(DB, "DBName"); $connect = mysql_connect(HOST,USER,PW) or die('Could not connect to mysql server.' ); mysql_select_db(DB, $connect) or die('Could not select database.'); $term = strip_tags(substr($_POST['search_term'],0, 100)); $term = mysql_escape_string($term); $sql = "SELECT * FROM Phase1A_1B_TotalScores_2011 WHERE CONCAT(last_name,first_name,employee_id,title,territory,district,Phase1A_Score,Phase1B_HS_Exam, Phase1A_HS_Exam_RT,Phase1B_HS_Exam ,Phase1B_HS_Exam_RT,Class_Date) LIKE '%$term%' order by last_name asc"; $string = ''; $string = "<table class='stripeMe' id='Results'><tr><th>Last Name</th><th>First Name</th><th>Employee ID</th><th>Title</th><th>Territory</th><th>District</th><th>Phase 1A Score</th><th>Phase 1B Score</th><th>Phase 1 Average</th><th>Phase 1A HS Exam</th><th>Phase 1A HS Exam Retake</th><th>Phase 1B HS Exam</th><th>Phase 1B HS Exam Retake</th><th>Class Dates</th><th>Awards</th></tr>"; $result = mysql_query($sql); /// This is the execution if (mysql_num_rows($result) > 0){ while($row = mysql_fetch_object($result)){ $string .= "<tr>"; $string .= "<td>".$row->last_name."</td> "; $string .= "<td>".$row->first_name."</td>"; $string .= "<td>".$row->employee_id."</td>"; $string .= "<td>".$row->title."</b>"; $string .= "<td>".$row->territory."</td>"; $string .= "<td>".$row->district."</td>"; $string .= "<td>".$row->Phase1A_Score."</td>"; $string .= "<td>".$row->Phase1B_Score."</td>"; $string .= "<td>".$row->Phase1_Average."</td>"; $string .= "<td>".$row->Phase1A_HS_Exam."</td>"; $string .= "<td>".$row->Phase1A_HS_Exam_RT."</td>"; $string .= "<td>".$row->Phase1B_HS_Exam."</td>"; $string .= "<td>".$row->Phase1B_HS_Exam_RT."</td>"; $string .= "<td>".$row->Class_Date."</td>"; $string .= "<td>".$row->Awards."</td>"; $string .= "<br/>\n"; $string .= "</tr>"; //print_r($row); } $string .= "</table>"; }else{ $string = "<span class='NMF'>No matches found!</span>"; // echo $sql; } echo $string; ?> and lastly my CSS Code: [Select] /*search term styling*/ #search_term{ font-weight:bold; color:#f00; } Question 1. Say I have a register form where a member registers with their full name but many people can have the same full name. What would be the best way to make the full name appear unique in the url(eg. website.com/member/johnsmith) for each member?
Question 2. I am not sure about other CMS but Shopify has this feature where you can change the colors of certain things on the website, in the backend. How is that achieved? I am a little lost on how you should connect css with php.
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! I have 3 tables (sectors, subsectors, and business). From the site a site user can select a sector, which then lists the subsectors, then when they select a sub sector they can view a list of the businesses within the selection. I am trying to remove a step so that they will see the sectors and be able to select, then will list the subsectors with the business names under the subsectors. The code I have is prior to removing the step is ...... Code: [Select] <?php $rs=mysql_query("select * from tblmain WHERE id='$view'"); while($row=mysql_fetch_row($rs)){ foreach ($row as $k => $v){ $row[$k] = nl2br($v); } echo("<h4>" . $row[1] . " Sectors </h4>"); } ?> <ul> <?php $pnds=1; if (isset($_GET["id"])) $pnds=$_GET["id"]; $sql = "select * from tblsub WHERE catid='$view' ORDER BY subsec "; $reccount=$sq->numsrow($sql); if ($reccount > 0) { $ata =$sq->query($sql); while($rs=$sq->fetch($ata)) { ?> <li><a href="listings.php?view=<?php echo $rs["subsec"];?>"><?php echo $rs["subsec"];?></a></li> <?php } } ?> </ul> I have tried to get this to work but the problem I am having is $view is an number but the actual business table is not id, it is by subsector name. I have tried ....... Code: [Select] <?php $rs=mysql_query("select * from tblmain WHERE id='$view'"); while($row=mysql_fetch_row($rs)){ foreach ($row as $k => $v){ $row[$k] = nl2br($v); } echo("<h4>" . $row[1] . " Sectors </h4>"); } ?> <ul> <?php $pnds=1; if (isset($_GET["id"])) $pnds=$_GET["id"]; $sql = "select * from tblsub WHERE catid='$view' ORDER BY subsec "; $reccount=$sq->numsrow($sql); if ($reccount > 0) { $ata =$sq->query($sql); while($rs=$sq->fetch($ata)) { ?> <li><a href="listings.php?view=<?php echo $rs["subsec"];?>"><?php echo $rs["subsec"];?></a></li> <?php $rs=mysql_query("select * from tblbusiness WHERE category='$view' ORDER BY name"); while($row=mysql_fetch_row($rs)){ foreach ($row as $k => $v){ $row[$k] = nl2br($v); } print(" . $row[2] . "); } <?php } } ?> </ul> But obviously category is by name and not $view which is an id. Any help would be greatly appreciated. I'm trying to create a website so that if I go to http://websiteaddress.com/, it will go to then index and if you are already logged in it will display the main page, but if you aren't logged in it'll show a login/registration page. Also, how does the following work: index.php?action=home index.php?action=register They show two seperate pages? So, could it go to the home page if logged in, but if not logged in it'll go the registration/login page? Hello, Im from the Netherlands and i have a little question about php. I have a form in php where administrators can make new users. They can fill in a name, password, age and can select a role. The role is a dropdown menu where they can select athlete, researcher and trainer. My problem is that when they select a role, i want that selected role transfert to a php variable. I want to use the variable in a if statment, when sporter selected a new dropdown appears with options like tennis, hockey.... I have seen a lot on google about this with jquery and stuff, but i cant find a good example. Can u help me? Thanks. Hi, can you help me please? I have some code written about 5 yrs ago that is for example like this echo"<div class=\"select\">"; echo"<br /><br />\n"; echo"</div>\n"; echo"</div>\n"; echo "<p><b>$address</b></p>\n"; Does it make any difference at all if I amended it to echo"<div class=\"select\"><br /><br /></div></div><p><b>$address</b></p>"; ie coding errors or increase load time? also when should I use \n"; or "; Please forgive my ignorance but I am a self taught php writer and have managed to teach myself but just need a little help. Cheers <?php include "C:/php-login/ASEngine/AS.php";
if (! app('login')->isLoggedIn()) {
This php code is in a file called test.php and is on my drive Letter O in a sub directory called my old photos . I'm having a problems referencing the include back to the the path of where ASEngine/As.php which is on c drive . I have tried all different relative and absolute paths . Any help would be appreciated Thank You I would like to keep all my classes in a folder placed within the htdocs folder where my php script runs. Let's say the classes folder is com\jimslounge\classes. From my script can I instantiate a class like this $myClass = new com\jimslounge\classes\Jimsclass(); Does it work something like that? I would hate to have to use include to access classes. This is what I want:
If comparisonTimeH isn't zero, I want it to check if comparisonTimeH is zero, and comparisonTimeM is larger than or equal to 2. If so, I want it to pass and run the script.
This is what I have, and it's not right. It runs the else statement, echo test 2.
if ($comparisonTimeH != 0 || $comparisonTimeH = 0 AND $comparisonTimeM >= 1) { echo "test"; } else { echo "test2"; } echo "<br />" . $comparisonTimeH . " " . $comparisonTimeM;My last echo, the one outside of the if statements - it returns 0 and 12. Thus, both conditions that I'm trying to get, are true. My if's logic is clearly wrong, and I can't figure out what operators to use. If I change the AND to &&, it breaks and my final echo doesn't return comparisonTimeH (it's blank). Please teach me, thanks! Edited by icor1031, 17 September 2014 - 07:48 PM. I'm working with the youtube API and the function Code: [Select] $relatedVideo->watchURL returns a video url However when I use Code: [Select] preg_replace("youtube","test",$relatedVideo->watchURL); it gives me the following error Code: [Select] preg_replace() [<a href='function.preg-replace'>function.preg-replace</a>]: Delimiter must not be alphanumeric or backslash in <b>C:\wamp\www\site\test.php</b> on line <b>317 Help please? Hello,
I hope I picked the right category.
I have an interesting situation. I'm building a website and I want to have the ability to work on it / prototype it without having the website accessible to the public. Currently it's not accessible because I placed a .htaccess file into my server but I think it didn't work correctly because I can't actually log in. That's not the main problem, I think the problem is that it's not ASCII but UTF-8. Been trying to figure out how to convert that.
I'm not sure if I even need web but I figure if I'm going to test it, which one of the things I have to test is capturing video with my phone then storing it to my server then retrieving it again. The capturing should be easy through HTML5 from what I've read.
I have access to php and sql. I just don't know if I need internet access. I don't know how to store locally.
Most php scripts don't even seem to mention a storage location. I have set up sql databases that used php to gather information. It's just not fresh in the mind at the moment.
I mean it had to work right? I mean I get the pop up that says "Authentication Required" which wasn't there until I uploaded the .htaccess file, which how can the .htpasswd file not be read if the .htaccess file is being read. I think it is in the right folder... anyway, maybe I don't need the web to prototype my website
Except for the phone part, I would like to see that the phone's camera UI and camcorder UI is easily accessed by one button
Any help would be appreciated
is it okay to name a column "date" in a table ??? just want to know whether this could mess up everything thanks in advance Does it matter where you start your session at? Does it have to be before the <!doctype> tag or can it go anywhere in the page? |