Jump to content

Stuie_b

Members
  • Posts

    74
  • Joined

  • Last visited

Everything posted by Stuie_b

  1. Firstly ensure you make the input for $_GET safe or you'll be opening your site up for attack, "addslashes()" should surfice, $page = addslashes($_GET['page;]) (see addslashes for more info) Like with the select loop you need to tell the IF statement what to do if there wasn't a page request supplied, if(!$page){ //or if(!isset($page)) include("/subpages/main.php"); } elseif (file_exists('subpages/' . $page . '.php')) { require('subpages/' . $page . '.php'); }else { echo '<div id="main"><span>The page you’re looking for cannot be found.</span></div>'; } Now the if has a match for page requests that doesn't specify a page and will still maintain a result if the requested page doesn't exist. You need to add the guestbook IF statment into your existing one and assuming the gbook.php file exists in the location you have specified it should work as you expect. if(!$page){ //or if(!isser($page)) include("/subpages/main.php"); } elseif (file_exists('subpages/' . $page . '.php')) { require('subpages/' . $page . '.php'); } elseif ($page='gbook' && file_exists('subpages/guestbook/' . $page . '.php')) { require('subpages/guestbook/' . $page . '.php'); }else { echo '<div id="main"><span>The page you’re looking for cannot be found.</span></div>'; } hope it helps Stuie.
  2. Try the following Assuming your table has an id field, the following creates a hyperlink to the file do.php passing the id value to do.php <table> <?php do { ?> <tr><td> <?php echo $row_usersawtappr['username']; ?></td><td><?php echo $row_usersawtappr['email']; ?></td><td><?php echo $row_usersawtappr['registration_date']; ?></td><td><?php echo $row_usersawtappr['dob']; ?></td><td><a href="do.php?act=approve&id=<?php echo $row_usersawtappr['id']; ?>">approve</a> / <a href="do.php?act=delete&id=<?php echo $row_usersawtappr['id']; ?>">delete</a></td></tr> <?php } while ($row_usersawtappr = mysql_fetch_assoc($usersawtappr)); ?> </table> do.php This file does the work, depending on the action to perform ($act), $act = $_GET['act']; $id = $_GET['id']; if($act =="approve"){ mysql_query("UPDATE %TABLENAMEHERE% set approve='1' WHERE id='".mysql_real_escape_string($id)."'"); header("location: index.php"); //Reloads the index page (change to the page used to list contents }elseif($act =="delete"){ mysql_query("DELETE FROM %TABLENAMEHERE% WHERE id='".mysql_real_escape_string($id)."'"); header("location: index.php"); //Reloads the index page (change to the page used to list contents } Replace %TABLENAMEHERE% with your tables name Stuie
  3. You have number of errors in the proccess code, Try the following <?php //variable to hold the query to issue, creates new database $sql = "CREATE database homebudget"; //connection information $connection = mysql_connect("localhost", "script", "9sj7En4")or die (mysql_error()); //mysql_query() funtion $result= mysql_query($sql, $connection) or die (mysql_error()); //test value of $result if ($result){ $msg="<P>Database HomeBudget has been created!</P>"; } ?> //HTML portion <HTML> <HEAD> <TITLE>HomeBudget Database</TITLE> </HEAD> <BODY> <?php echo "$msg"; ?> this is where i keep getting an error </BODY> </HTML> Stuie
  4. Php has built in functions which allows you to do just that, see here for more info. try the following, <?php $target = "upload/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; //This is our size condition if ($uploaded_size > 35000000) { echo "Your file is too large.<br>"; $ok=0; } //This is our limit file type condition if ($uploaded_type =="text/php") { echo "No PHP files<br>"; $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo "Sorry your file was not uploaded"; } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { $to = addslashes($_POST['email']); $name = addslashes($_POST['name']); $pp = addslashes($_POST['paypal']); $from = "admin@server.com"; //set this to your email address or the servers address $msg = "New File Upload From: $to Name: $name Paypal: $pp File:".$_FILES['uploadedfile']['name']; //Change the above to the message you would like to send. echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; mail($to,$subject,$message,"FROM: $from"); //Send the Email to them mail($from,$subject,$message,"FROM: $to"); //Send the email to you } else { echo "Sorry, there was a problem uploading your file."; } } ?> Stuie
  5. You can either set the button to use an image or use javascript to submit the form, search google for submitting a form with an image Stuie Well how do you get it so that when you click register after all your data has been put in you receive an e-mail confirmation AND Activation? Also- How would I make a submit/cancel button be an image? which takes the user to a members only area ? codewise?
  6. try the following <?php $key = "A"; //looks for A //load file into $fc array $fc=file("some.txt"); //open same file and use "w" to clear file $f=fopen("some.txt","w"); //loop through array using foreach foreach($fc as $line) { if (preg_match("/$key/",$line)){ //look for $key in each line fwrite($f,$line); //place $line back in file } } fclose($f); ?> Stuie
  7. Because <tr> tells the table to create a new column not a new row, <td> is used for rows You will need to create the row outside of the for each loop and place only the <td> inside the loop, <?php $fileContentsArray = file_get_contents("./data.txt"); $lines = explode("\n", $fileContentsArray); echo "<table border = '1'>"; $aArray = preg_split("/,/", $lines[0]); echo "<tr>"; foreach ($aArray as $adata) { echo "<td>$adata</td>"; } echo "</tr>"; $bArray = preg_split("/,/", $lines[1]); echo "<tr>"; foreach ($bArray as $bdata) { echo "<td>$bdata</td>"; } echo "</tr>"; $cArray = preg_split("/,/", $lines[2]); echo "<tr>"; foreach ($cArray as $cdata) { echo "<td>$cdata</td>"; } echo "</tr>"; echo "</table>"; Stuie
  8. The features you are looking to make are not to do with php but more to do with html, You need to understand how Html forms work and how you can use php to manipulate the data, The following Example will hopefully help, <?php //Get the values Passed by the html form $fname = $_POST['fname'];$lname = $_POST['lname'];$email = $_POST['email'];$gender = $_POST['gender']; $uname = $_POST['uname'];$upass = $_POST['upass'];$about = $_POST['about'];$website = $_POST['website']; $mode = $_POST['mode']; ?> <!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>Untitled Document</title> </head> <body> <?php if(!$mode){ //No mode was set we can assume they want to submit it, Lets show the form ?> <form id="form1" name="form1" method="post" action=""> <p> <label for="fname">First Name:</label> <input type="text" name="fname" id="fname" /> </p> <p> <label for="lname">Last Name:</label> <input type="text" name="lname" id="lname" /> </p> <p> <label for="email">Email Address:</label> <input type="text" name="email" id="email" /> </p> <p> Gender: <input type="radio" name="gender" id="gender" value="male" /> <label for="gender">Male</label> <input type="radio" name="gender" id="gender" value="female" /> <label for="gender">Female</label> </p> <p> <label for="uname">Username:</label> <input type="text" name="uname" id="uname" /> </p> <p> <label for="upass">Password:</label> <input type="password" name="upass" id="upass" /> </p> <p> <label for="website">Personal Website:</label> <input type="text" name="website" id="website" /> </p> <p> <label for="about">Tell us a bit about yourself:<br /> </label> <textarea name="about" id="about"></textarea> </p> <p> <label for="register"></label> <input type="submit" name="register" id="register" value="Register" /> <input type="button" name="Cancel" id="Cancel" value="Cancel" /> <input name="mode" type="hidden" id="mode" value="doreg" /> </p> </form> <?php }elseif($mode=="doreg"){ //Ok they filled the form in lets process it. if($fname and $lname and $email and $gender and $uname and $upass and $website and $about){ //Check that all fields where filled (not best way of doing it) //Right we have all the fields filled and ready, now we can add them to the database if(mysql_query(%MYSQL QUERY HERE%)){ echo "Your registration was successful"; //Ok the query was done successfully show the registered message }else{ echo "We where unable to register you at this time, Please try again later"; //Oh Dear we couldnt enter the details into the database! echo "<br />".mysql_error(); //This will show you why! but do NOT use it on a production server!! } }else{ echo "You failed to supply all fields, Please go back and try again"; } }else{ //This should only happen if they try to access something which doesnt exist echo "Unexpected error occured"; } ?> </body> </html> Not exactly the best method but hopefully it's easy enough to understand A little light reading for you, Html forms Using html forms with php Stuie
  9. Sessions would be my choice, would allow you to prevent multiple submitions with very little code changes stuie
  10. by deafult move_uploaded_files() will fail to work if the destination directoy doesnt exist, you need to ensure it exists before moving the upload.. the following should surfice <?php if(!is_dir("DESTINATION DIR HERE")){ mkdir("DESTINATION DIR HERE"); } ?> Stuie
  11. yes you can you will need to use one of the GD2 libs to achieve it, your best bet is to use imagejpeg or ImageCopyResampled See here for info on using imagejpeg and here for ImageCopyResampled Stuie
  12. no GET and POST do the same job just slightly different.. the following example should get you started.. <?php $meth = $_POST['meth']; $value = $_POST['value']; if(!$meth or !$value){ ?> <form name="convertor" id="convertor" action="" method="post"> <input name="value" id="value" type="textbox" /> <select name="meth" id="meth"> <option value="1">Binary to Decimal</option> <option value="2">Decimal to binary</option> </select> <input type="submit" name="submit" id="submit" value="Convert" /> </form> <?php }elseif($meth and $value){ $out = $meth==1 ? bindec($value) : decbin($value); echo "Original Value - $value -- converted value - $out"; } ?> Stuie
  13. Php has built in functions to achieve this see here and here a quick example would be to post the text box to a php file convert using php and output to the page.. <?php $in = $_GET['bin']; if($in){ echo "Original Binary - $in -- Decimal equivilent - ".bindec($in); } ?> Stuie
  14. Your doing a loop within a loop.. try placing the foreach loop outside of the while (or just get rid of the while loop) eg $idarray = mysql_fetch_array($getids,MYSQL_ASSOC); foreach($idarray as $value){ echo "id=".$value; } the example above maintains the $idarray while giving the output... not sure if it will work for what every you have planned but it should hopefully be a starting point.. Stuie
  15. if its a case of the last 10 registered users, you could run a query and limit it to 10 for example <?php $qh = mysql_query("SELECT * FROM members_table WHERE active='1' LIMIT 0,10"); while($ret = mysql_fetch_array($qh)){ echo $ret['username']; } ?> Stuie
  16. you need to tell php to create the folder first take look at the example below <?php if(!is_dir("uploads/".$_GET['username'])){ mkdir("uploads/".$_GET['username']); } ?> as the example above shows we check to make sure the directory dosnt exist and then create it, <?php $uploaddir = './uploads/'; $file = $uploaddir . basename($_FILES['uploadfile']['name']); $size=$_FILES['uploadfile']['size']; if($size>500*1024) { echo "error file size > 500 MB"; unlink($_FILES['uploadfile']['tmp_name']); exit; } if(!is_dir("uploads/".$_GET['username'])){ mkdir("uploads/".$_GET['username']); } move_uploaded_file($_FILES["file"]["tmp_name"], "'.$_GET['username'].'/private/" . str_replace (" ", "",$_FILES["file"]["name"] . $file)); ?> Stuie
  17. To run php files locally on your system you need to have php running via apache (try XAMPP) once you have that installed and running the php files will be phrased correctly and display as they should. As for not displaying any results.. you may have an error within your code and would need error_reporting to show them.. try running your file with xampp and error_reporting on and see whats shown (if anything) Stuie
  18. not entirle sure what you mean here but if i understand correctly you want to use a mysql result within php. if so the answers yes. mysql_fetch_array/mysql_fetch_assoc will enable you to get mysql resulting data and use the results within php (see here and here) Not with that code alone you cant.. you would need to create an actual output from the results, the code you have is just the backbone (actually getting db data) see the basic pagination tut (link below) A few tutorials which may help basic database handling basic pagination If i've totally missed the point apologies Stuie
  19. You havnt closed the query at the end <?php function curlURL($url) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2'); $output = curl_exec($curl); return $output; } $curlResults = curlURL("http://southcoast.craigslist.org/sss/"); $pattern = '#<a href="(/[a-z]{3}/\d{10}\.html)">#'; preg_match_all( $pattern, $curlResults, $matches); echo "<pre>\n"; echo "Links:\n\n"; foreach ($matches[1] as $link): echo "\t" . '<a href="' . $link . '" target="_BLANK">' . $link . '</a>' . "\n"; endforeach; echo '</pre>'; echo file_get_contents("http://southcoast.craigslist.org".$link); $pattern = '#<sale-\K[a-z0-9]+-\d+@craigslist\.org(?=>)#'; //This is the attempted match for the email preg_match_all( $pattern, $matches); foreach ($matches[0] as $address): endforeach; $dbx= mysql_connect("localhost", "root", ""); //include before any database implematation if (!$dbx) { die('Could not connect: ' . mysql_error()); } mysql_SELECT_db("Craigslist", $dbx); mysql_Query("INSERT INTO addresses (sale_items) VALUES ('$address')"); mysql_close($dbx); ?> Stuie
  20. Why cant you divide by 5? your right a div cant be used in math but your putting the value of the text box into a variable and as such you can do pritty much anything with it... try the following <script type="text/javascript"> function showMsg(){ var userInput = document.getElementById('amount').value; document.getElementById('userMsg').innerHTML = userInput / 5; } </script> <div id=userMsg></div> <form method="post" action="guild_payout.php"> <input type="text" name="amount" id="amount" onkeyup="showMsg()" value="" size="15"/> <input type="submit" name="submit" value="Submit"> </form> what you will have todo is make sure that only numbers are entered and not text other wise js will return NaN Stuie
  21. Try the following... <?php $spots = array ("1st","2nd","3rd","4th","5th"); foreach($spots as $spot) { $query = mysql_query("select * from xlsdata where spot='$spot'") or die("SQL error: " . mysql_error()); $record = mysql_fetch_array($query); $count = mysql_num_rows($query); ?> Returned <h2><?php echo $count; ?></h2> Rows <h2><?php echo $record['date-event']; ?></h2> <p><?php echo $record['beginning']; ?> <blockquote> <?php if(!empty($record['bullet1'])) echo "<li>".$record['bullet1']."</li>"; ?> <?php if(!empty($record['bullet2'])) echo "<li>".$record['bullet2']."</li>"; ?> <?php if(!empty($record['bullet3'])) echo "<li>".$record['bullet3']."</li>"; ?> <?php if(!empty($record['bullet4'])) echo "<li>".$record['bullet4']."</li>"; ?> <?php if(!empty($record['bullet5'])) echo "<li>".$record['bullet5']."</li>"; ?> <?php if(!empty($record['bullet6'])) echo "<li>".$record['bullet6']."</li>"; ?> <?php if(!empty($record['bullet7'])) echo "<li>".$record['bullet7']."</li>"; ?> <?php if(!empty($record['bullet8'])) echo "<li>".$record['bullet8']."</li>"; ?> <?php if(!empty($record['bullet9'])) echo "<li>".$record['bullet9']."</li>"; ?> </blockquote> <?php echo $record['end']; ?></p> <?php } ?> Tbh the only changes where to put everything into one place instead of duplicating code and i added a line to show how many (if any) rows where returned.. This should ensure you are getting a return from mysql, also as DavidAM says make sure the correct error report levels are set and short tags are phrased.. Stuie
  22. The file uploads and it's contents are output without problems for me.. without knowing how CreateMap does it's setup i cant help.. if you can post the CreateMap() function so i can see how $map is setup, Stuie
  23. Try the following <?php session_start(); //get required files //config require_once("config.php"); //queries require_once("queries.php"); //theme $html = file_get_contents('./theme/index.html'); //get what the user requests //$request = $_GET['membership']; //connect to DB mysql_connect($host, $user, $pass) or die(mysql_error()); mysql_select_db($db) or die(mysql_error()); echo '<style type="text/css"> #membership { font-family: Helvetica, Arial; font-size: 13px; size: 13px; } </style>'; switch ($_GET['membership']){ #line 78 starts on next line //log in PROCESS case "LoginProcess": $user_email = mysql_real_escape_string($_POST['email']); if ($_POST['Submit']=='Login') { $md5pass = md5($_POST['pwd']); $loginprocess = "SELECT id,user_email FROM users WHERE user_email = '$user_email'"; $result = mysql_query($loginprocess) or die (mysql_error()); $row = mysql_fetch_array($result,MYSQL_ASSOC); if($md5pass != $row['user_pwd']) { // Incorrect Password $content = '<h2>Log In Error</h2> <h3 style="color: Red;">ERROR: You could not be logged in!</h3> <p> Please go back and try again. <br /> If you have forgotten your password, please contact support.</p>'; } else { // Correct Password $_SESSION['username'] = $row['user_name']; $_SESSION['userid'] = $row['id']; $_SESSION['loggedin'] = 'yes'; $_SESSION['admin'] = $row['admin']; $content = '<h2>Log In Complete!</h2> <p>Thank you for logging into the website.</p> <p>You have been sucesfully logged in.</p>'; } } $title = 'Login'; $html = str_replace('{pagetitle}', ''.$title.' | Membership', $html); $html = str_replace('{content}', $content, $html); echo $html; break; //login form case "Login": $content = '<h2>Please Login</h2> <p>Please login to the website for full access.</p> <p><strong>Not a member?</strong> <a href="Register">Register here!<br /></a></p> <h3 style="color: Red;">Login Notes: Please remember to use your EMAIL address to login. We do not reset passwords, so if you have forgotten yours, you will need to re-register.</h3> <form action="LoginProcess" method="post" name="login"> <p>Email Address:<br /><input name="email" type="text" /></p> <p>Password:<br /><input name="pwd" type="password" /></p> <p><input name="Submit" type="submit" value="Login" /></p> </form>'; $title = 'Login'; $html = str_replace('{pagetitle}', ''.$title.' | Membership', $html); $html = str_replace('{content}', $content, $html); echo $html; break; //logout case "Logout": //session_start(); unset($_SESSION['user']); $content = '<h3 style="color: Red;">You are now logged out.</h3> <p>Thank you for using our website!</p>'; $title = 'Logout | Thank you for logging out'; $html = str_replace('{pagetitle}', ''.$title.' | Membership', $html); $html = str_replace('{content}', $content, $html); echo $html; break; //register process case "RegisterProcess": ////session_start(); if ($_POST['Submit'] == 'Register') { if (strlen($_POST['email']) < 5) { $content = '<h3 style="color: Red;">Incorrect Email or Password. Try again.</h3>'; } if (strcmp($_POST['pass1'],$_POST['pass2']) || empty($_POST['pass1']) ) { $content = '<h3 style="color: Red;">Incorrect Email or Password. Try again.</h3>'; } if (strcmp(md5($_POST['user_code']),$_SESSION['ckey'])) { die("Invalid code entered. Please enter the correct code as shown in the Image"); } $rs_duplicates = mysql_query("select id from users where user_email='$_POST[email]'"); $duplicates = mysql_num_rows($rs_duplicates); if ($duplicates > 0) { $content = '<h2>User Account In Use</h2> <p>We&#38;#39;re sorry, but you specified a user account that is already in use. Please go back and try again.</p>'; } $md5pass = md5($_POST['pass2']); $activ_code = rand(1000,9999); $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); mysql_query("INSERT INTO users (`user_email`, `user_activated`, `user_pwd`,`country`,`joined`,`activation_code`,`full_name`) VALUES ('$_POST[email]','1','$md5pass','$_POST[country]',now(),'$activ_code','$_POST[full_name]')") or die(mysql_error()); unset($_SESSION['ckey']); $content = '<h2>Registration Complete!</h2> <p>Thank you for registering with our website. </p> <p>Your account is now activated, and you may now purchase a subscription.</p>'; } $title = 'Registration'; $html = str_replace('{pagetitle}', ''.$title.' | Membership', $html); $html = str_replace('{content}', $content, $html); echo $html; break; } ?> on a side note, try to echo out what is actually in the $row['user_pwd'], this will make sure the value is actually being set.. Stuie
  24. what error is given.. use mysql_error(); to tell you why the query failed. tbh your query appears to be fine so would suspect it's something else. Until i know why mysql is complaining i cant help you with this, so once you get chance post the mysql_error() output. Stuie
  25. The problem lies in the browser, because php doesn't handle file mime types, the mime is browser specific, one solution to this problem is to manually check the filename for the correct extensions, <?php if (!eregi(".jpg",$_FILES['uploaded']['filename']) OR !eregi(".gif",$_FILES['uploaded']['filename'])){echo "Your uploaded file must be of JPG or GIF. Other file types are not allowed<BR/>"; exit;} ?> Stuie
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.