Jump to content

Stuie_b

Members
  • Posts

    74
  • Joined

  • Last visited

About Stuie_b

  • Birthday 07/02/1988

Profile Information

  • Gender
    Male
  • Location
    Newcastle, UK

Stuie_b's Achievements

Newbie

Newbie (1/5)

0

Reputation

  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
×
×
  • 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.