Jump to content

Viper69

New Members
  • Posts

    9
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Viper69's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. lynda.com is good but not free, there are loads of free resources, if money is no object then lynda.com will help with most things
  2. Here is a basic form I am currently using <form id="form2" name="form2" method="post" action="index2.php"> <label for="webnumber">Site Number</label> <input name="webnumber" type="text" id="webnumber" size="2" maxlength="2" /> <br/> <br/> <label for="likes">Likes</label> <textarea name="likes" id="likes" cols="50" rows="10"></textarea> <br/> <br/> <label for="dislikes">Dislikes</label> <textarea name="dislikes" id="dislikes" cols="50" rows="10"></textarea> <p> <input type="submit" name="Submit" id="submit" value="Submit" title="Submit the form button" /> <input type="reset" name="Reset1" id="reset1" value="Reset" title="Reset the form button" /> </p> </form> The php handler that deals with this form is <?php // connection to MySQL require ("connect.php"); // if this script is unavailable then the rest of the code is pointless as need a connection to the database. // collection of ip address //$ip = getRealIpAddr(); if($_POST['webnumber']) { // if this field has had data entered then process the data $webnumber = strip_tags($_POST['webnumber']); // Removing false entries/malicious code $likes = strip_tags($_POST['likes']); $dislikes = strip_tags($_POST['dislikes']); /* depending on what version of php being used will need to strip slashes also, if lower than version 6, mine is 4.4.9 $webnumber = stripslashes($_POST['webnumber']); $likes = stripslashes($_POST['likes']); $dislikes = stripslashes($_POST['dislikes']); */ /* Setting variables $webnumber = $_POST['webnumber']; $likes = $_POST['likes']; $dislikes = $_POST['dislikes']; */ // insert data to dbase $query="INSERT INTO datacollection2 (id, ip, webnumber, likes, dislikes) VALUES ('Null', '$ip', '$webnumber', '$likes', '$dislikes')"; // Null is in the id field as his is added automatically by the database. // message to say if database has been updated mysql_query($query) or die (mysql_error()); echo "The database has just been updated with the following information: ".'<br/>'; //echo "<b>Your IP address is: $ip</b> <br />"; /*function getRealIpAddr() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } return $ip; } */ echo $haveemail.'<br/>'; echo '<br/>'."<b>You liked the following </b>".$likes." <b>from website</b> ".$webnumber.'<br/>'; echo '<br/><br/>'."<b>You disliked the following </b>".$dislikes."<b> from website </b>".$webnumber.'<br/>'; echo '<br/><br/>'."Thankyou for your input".'<br/><br/>'; } ?> To connect the two so that the form calls the php into action my finished form xhtml code looks like [code] <?php include 'php/writedatacollection2.php'; ?> <!-- includes php script to write data to dbase--> <form id="form2" name="form2" method="post" action="index2.php"> <label for="webnumber">Site Number</label> <input name="webnumber" type="text" id="webnumber" size="2" maxlength="2" /> <br/> <br/> <label for="likes">Likes</label> <textarea name="likes" id="likes" cols="50" rows="10"></textarea> <br/> <br/> <label for="dislikes">Dislikes</label> <textarea name="dislikes" id="dislikes" cols="50" rows="10"></textarea> <p> <input type="submit" name="Submit" id="submit" value="Submit" title="Submit the form button" /> <input type="reset" name="Reset1" id="reset1" value="Reset" title="Reset the form button" /> </p> </form> [/code] the include statement prior to the form tags is what calls the php <?php include 'php/writedatacollection2.php'; ?> <!-- includes php script to write data to dbase--> Hope this helps
  3. This script works, I didnt write it but I have used it successfully to store ip addresses $ip = getRealIpAddr(); function getRealIpAddr() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } return $ip; }
  4. I would suggest trawling google for tutorials or youtube, there are hundreds on there covering everything youll need.
  5. I would also suggest html and css, before you even think of Php I would also read up on all the accessibility issues on www.w3c.org. Try to make small test pages and when you are feeling confident test your html code at http://validator.w3.org/ and your css at http://jigsaw.w3.org/css-validator/ then when you have the green light so to speak test your site for accessibility against http://wave.webaim.org/. This should keep you busy for a while.
  6. At the risk of answering a wind up go take a look at youtube, hundreds of tutorials on php
  7. A good place to start would be http://www.youtube.com/user/phpacademy#p/a/7C9AFC3942AC8E40/0/4oSCuEtxRK8 This is the first of a few tutorials
  8. No sorry, I commented it out because it does not work as it is, as I say I have placed the function where it is and outside of the _POST, still not working hence coming in here to see if someone can spot what I need to do. The function works independent of the rest of the code just not with the POST. Thanks in advance for any help
  9. I have a basic form for collecting data, I have a function for collecting the ip address of the visitors unfortunately I cannot get the ip collection working with the rest of the form once I put the if($_POST['emailaddress']) {.........} in. My aim is once the user has completed the form, data gone to MySQL database that the data will then be printed via the echo statements on to the form as the action sends it back to the same page. Currently my code is <?php /* This script is a form handler, each section is commented as to what it does. 1. connects to the database (see connect.php). 2. it gets the users ip address. 3. Strips tags from the data entered so that no malicious code can be entered and corrupt/cause problems with the database or site. 4. Inserts the relevant data into the database in this case it is the ip, haveemail, emailaddress, browser, otherbrowser, resolution, otherresolution. 5. Sends the data just entered by the user back to the screen so they can see what they entered */ // 1. connection to MySQL require ("php/connect.php"); // if this script is unavailable then the rest of the code is pointless as need a connection to the database. // if fields are completed if($_POST['emailaddress']) { // if this field has had data entered then process the data // 2. collect ip address //$ip = getRealIpAddr(); // 3. Strips tags and POST variables from the form $haveemail = strip_tags($_POST['haveemail']); $emailaddress = strip_tags($_POST['emailaddress']); $browser = strip_tags($_POST['browser']); $otherbrowser = strip_tags($_POST['otherbrowser']); $resolution = strip_tags($_POST['resolution']); $otherresolution = strip_tags($_POST['otherresolution']); // 4. insert data to dbase $query="INSERT INTO datacollection1 (id, ip, haveemail, emailaddress, browser, otherbrowser, resolution, otherresolution) VALUES ('Null', '$ip', '$haveemail', '$emailaddress', '$browser', '$otherbrowser', '$resolution', '$otherresolution')"; // Null is in the id field as this is added automatically in the database as it is set to auto increment upon an entry going in and is primary key. // message to say if database has been updated mysql_query($query) or die (mysql_error()); //echo "<b>Your IP address is: $ip</b> <br />"; /*function getRealIpAddr() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } return $ip; } */ // 5. displays information on form to advise what the user just entered echo '<br/>'."The database has just been updated with the following information: ".'<br/><br/>'; // echo "Your ip address is ".$ip.'<br/>'; echo "You answered ".$haveemail." to having an email address.".'<br/>'; echo "Your email address is ".$emailaddress.'<br/>'; echo "You use ".$browser." to browse the internet".'<br/>'; echo $otherbrowser.'<br/>'; echo "Your screen resolution is set at ".$resolution.'<br/>'; echo $otherresolution.'<br/>'; echo "Now you have completed this form, please follow onto the main form, this form seeks to get your valuable opinion regarding your likes and dislikes of the websites researched."; } mysql_close($db); // closes the database, this is good practice but the database will close once stopped running. ?> I have tried moving the function outside of the if($_POST['emailaddress']) but it still didnt get the ip address. Just as a side note everything else works, the data is written into the database bar the ip address. I would appreciate some help Thanks in advance.
×
×
  • 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.