Jump to content

Ch0cu3r

Staff Alumni
  • Posts

    3,404
  • Joined

  • Last visited

  • Days Won

    55

Everything posted by Ch0cu3r

  1. the code I gave was an example for just the doing the addition operation. You'll need to write new functions for doing subtraction, multiplication and division operations. You don't modify the Calc function. To write the other three functions, copy and paste Calc function. Rename it to the operation you want to do, for example Sub for subtraction. Change field('a1') and field('a2') to so it gets the field values for the operation. So for subtraction that would be field('s1') and field('s2'). You'd change the sum to the operation, for subtraction change return $num1 + $num2; to return $num1 - $num2; When you want to perform the operation you'd call that function, for example the answer field for subtraction would be <input type="text" name="s3" value="<?php echo Sub(); /* print sum */ ?>" />
  2. Maybe better of linking to your css if your sending an HTML email. <html> <head> <title>Email title</title> <link rel="stylesheet" href="http://site.com/stylesheet.css" /> </head> <body> email message </body> </html>
  3. Yes that is the problem. When processing any kind of input you should always process it before you start outputting anything to the browser. The order of your code logic should be input -> process -> output. <?php /* INPUT */ if(isset($_POST['login'])) { /* PROCESS */ // query database // make sure username and password matches a record // set anY sessions variables required // redirect user // if database did not match any record set any errors to a variable // display errors near the login form } /* OUTPUT */ ?> <!-- now we output the login page --> <html> ... <!-- login form --> <form> <span><!-- display any errors --></span> ... </form> </form> ... </html>
  4. Using MySQL as the database? and you have a DATETIME column? You can use one of the mysql DATE functions within your query http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html Alternatively use PHP's strtotime function and date to reformat the date $date = '21-10-2013 14:30:00'; $timestamp = strtotime('+5 days 1 hours', $date); echo date('l jS \of F Y h:i:s A', $timestamp);
  5. What line is session_start(); on? Are you displaying your login form before this line? session_start and header() cannot be used if you are outputting anything before the use of these functions. To see if PHP is failing on calling this function, enable error reporting at the top of your script - as I showed you earlier. It probably worked ok on your development server because you had a setting called output buffering on, whereas your live site has this setting off. When developing you should always configure your development environment to be as close to your live production environment. So when you go to run your code on your live server there shouldn't any issues with your PHP code as you would of identified these issues earlier on.
  6. By that do you mean it displays a blank page? A blank page usually indicates an error. On production servers error reporting is usually turned off by default. To see if there is an error check your servers error log or at the top your php page change <?php to <?php display_errors(TRUE); error_reporting(E_ALL); To enable error reporting.
  7. The drop down list (<select></select>) needs to be enclosed in a form (<form></form>) that is the the body (<body></body>) of the webpage. How to add a form to a webpage https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/My_first_HTML_form When a form is submitted you can accss the forms values using the $_GET or $_POST superglobals. Information on how PHP deals with forms http://php.net/manual/en/tutorial.forms.php http://uk3.php.net/manual/en/language.variables.external.php To filter data in your query you'd use the WHERE clause http://www.tutorialspoint.com/mysql/mysql-where-clause.htm
  8. You should always check to see if mysql_qeuery executed the query, if there is a problem it will return false. When inserting/updating or deleting records use mysql_affected_rows to verify the query did perform the operation. // check that mysql_query did not return false if(($res = mysql_query($sql)) !== false) { // check that the query did the operation if(mysql_affected_rows() == 1) { echo "Saved!"; } else { echo 'Record not saved!'; } } // query could have a problem. Lets see else { echo 'DATABASE Error: ' . mysql_error(); }
  9. What have you tried so far? basically you store all comments in the database. When adding the comment to the database save your pages id with it, eg INSERT INTO comments SET page_id = $page_id, posters_name = '$posters_name', comment = '$comment' When you display your page and want to show the comments for that page. You'd run this query SELECT posters_name, comment FROM comments WHERE page_id = $page_id To protect from spam you can add something like ReCapture to verify the person that is submitting the comment is a human and not some spambot. If you only want members signed into facebook to be able to post a comment you'll have to look into using the facebooks api
  10. You need two forms. One form for the drop downs and the other form for setting/updating the rewards. So change echo ' <form action="" method="post">' . $dropdown.' '. $catdropdown. ' <input type="text" name="max_point_cont" value="" /> <input type="text" name="points_earn_cont" value="" /> <input type="submit" value="Get Results">; <input type="submit" name="update" value="Update Rewards" onclick="action='updaterew.php'">; </form>'; } // only qeury the rewards table when the form above has been submitted if(isset($_POST['mem'])) { $post_sql = "select member, cat_name, point_earn, max_point from rewards where member = '" . mysql_real_escape_string($_POST['mem']) . "' and cat_name = '". mysql_real_escape_string($_POST['catdp']) . "'" ; $result_post = mysql_query($post_sql); if(!$result_post) { //the query failed, uh-oh :-( echo 'Error while selecting rewards from database. Please try again later.'; } else { echo '<table border="1"> <tr> <th>Member</th> <th>Category</th> <th>Points Earned</th> <th>Max Points</th> </tr>'; while($row = mysql_fetch_assoc($result_post)) { echo '<tr>'; echo '<td>' . $row['member'] . '</td>'; echo '<td>' . $row['cat_name'] . '</td>'; echo '<td>'. $row['point_earn']. '</td>'; echo '<td>' . $row['max_point']. '</td>'; echo '</tr>'; } echo '</table>'; } } to echo ' <form action="" method="post">' . $dropdown.' '. $catdropdown. ' <input type="submit" value="Get Results"> </form>'; } // only qeury the rewards table when the form above has been submitted if(isset($_POST['mem'])) { $post_sql = "select member, cat_name, point_earn, max_point from rewards where member = '" . mysql_real_escape_string($_POST['mem']) . "' and cat_name = '". mysql_real_escape_string($_POST['catdp']) . "'" ; $result_post = mysql_query($post_sql); if(!$result_post) { //the query failed, uh-oh :-( echo 'Error while selecting rewards from database. Please try again later.'; } else { // display new form for changing points // mem and catdp are hidden form fields echo '<form action="updaterew.php" method="post"> <input type="hidden" name="mem" value="'.$_POST['mem'].'" /> <input type="hidden" name="catdp" value="'.$_POST['catdp'].'" /> <input type="text" name="max_point_cont" value="" /> <input type="text" name="points_earn_cont" value="" /> <input type="submit" name="update" value="Update Rewards">; </form>'; echo '<table border="1"> <tr> <th>Member</th> <th>Category</th> <th>Points Earned</th> <th>Max Points</th> </tr>'; while($row = mysql_fetch_assoc($result_post)) { echo '<tr>'; echo '<td>' . $row['member'] . '</td>'; echo '<td>' . $row['cat_name'] . '</td>'; echo '<td>'. $row['point_earn']. '</td>'; echo '<td>' . $row['max_point']. '</td>'; echo '</tr>'; } echo '</table>'; } } you need to be sanitizing all post fields in your update query //a real user posted a real reply $sql = "UPDATE `rewards` SET `max_point`= `max_point`+ '" . $_POST['max_point_cont'] . "',`point_earn`= `point_earn` + '" . $_POST['points_earn_cont'] . "' WHERE member = '" . mysql_real_escape_string($_POST['mem']) . "' and cat_name = '". mysql_real_escape_string($_POST['catdp']) . "'" ; Change the above to //a real user posted a real reply $sql = sprintf("UPDATE `rewards` SET `max_point`= `max_point`+ '%d',`point_earn`= `point_earn` + '%d' WHERE member = '%s' AND cat_name = '%s'", (int) $_POST['max_point_cont'], /* make sure only number */ (int) $_POST['points_earn_cont'], /* make sure only number */ mysql_real_escape_string($_POST['mem']), mysql_real_escape_string($_POST['catdp']) );
  11. WAre you unsure how to call the Calc function when someone enters values into the addition fields? How I'd do it is change the addition fields to <strong>Addition:</strong><br /> <input type="text" name="a1" value="<?php echo field('a1'); /* get field a1 value */ ?>" /> plus <input type="text" name="a2" value="<?php echo field('a2'); /* get field a2 value */ ?>" /> equals <input type="text" name="a3" value="<?php echo Calc(); /* print sum */ ?>" /> Now change the Calc function to function Calc() { $num1 = field('a1'); // get the value in a1 field $num2 = field('a2'); // get the value in a2 field if (!empty( $num1) && !empty( $num2 )) // make sure values are not empty { return $num1 + $num2; // return the sum } } // helper function to get values from $_POST function field($fieldname) { return isset($_POST[$fieldname]) ? $_POST[$fieldname] : ''; // return fields value }
  12. Remove $result from mysql_affected_rows( $result ). if ( $result && mysql_affected_rows() != 0 ) {
  13. I don't think LIKE can take multiple values to search. You have to perform like on each keyword. eg SELECT col FROM table WHERE col LIKE '%keyword1%' OR col LIKE '%keyword2%' OR col LIKE '%keyword3%' etc..
  14. All you did was add the name field to your form and then defined a php variable to store the name when the form is submitted. You have not modified the code that sends the email to also include the name. This is this code that sends the email. mail("tamir@tamirt.co.il", 'site email: '.$subject, $_SERVER['REMOTE_ADDR']."\n\n".$message "From: $from"); Where do you want the name to displayed in the email, before the message or after the message? For that you either need to set the charset or send a html email.
  15. Where is the variable $tour_id defined? You're using this variable in your query to only update the picture where the tour_id matches it. $sql = "UPDATE tourDB SET pic_1_name = '$pic_1_name', pic_1_file_size = '$pic_1_file_size', pic_1_file_type = '$pic_1_file_type', pic_1_content = '$pic_1_content', image_date_1 = '$image_date_1' WHERE tour_id = '$tour_id'"; //<-- $tour_id is not defined anywhere How can the database update a record based on a value you're not defining? Also storing the actual image within the database is not recommended. Only store the path to the image and save the image to file system.
  16. You want to create a new php page for each movie that is added to the database? This is bad design. You should have one file that retrieves the movies data from the database and then displays it on the page. How you let the file knows what movie to retrieve is by passing in the url query string. For example site.com/movie.php?move=terminator Now in movie.php you'd have <?php // connect to database etc. mysql_connect('localhost', 'user'. 'pass'); mysql_select_db('movies'); // what movie is being requested if(isset($_GET['movie'])) { // the movie being requested $move = mysql_real_escape_string($_GET['movie']); // sanitize user input // query the database and get the requested movie $sql = "SELECT * from movies_table WHERE movie='$movie'"; if($result = mysql_query($sql)) { // did the query find the requested movie if(mysql_num_rows($result)) { // get the data from the result $row = mysql_fetch_assoc(); // display move template page include 'movie.template.php'; } } // movie was not found else { echo 'Sorry that movie cannot be found'; } } // user hasn't requested for a movie else { // either display movie index or an error here } ?> Now in movie.template.php you'd have your html layout, example coded for this <html> <head> <title>My Movie Site - <?php echo $row['movie']; ?></title> </head> <body> <h1><?php echo $row['movie']; ?></h1> <p><?php echo $row['description']; ?></p> <p>Actors: <?php echo $row['actors']; ?></p> </body> </html>
  17. Read the following (red warning) http://php.net/manual/en/language.types.float.php
  18. Yeah, try changing it and see what happens.
  19. use urlencode when forming the link Use urldecode when retrieving the link
  20. You can call as many functions as you like. PHP does not impose any limits.
  21. The code you posted above should process the file upload just fine. However you will need to change if($_POST['upload']) { to if(isset($_POST['upload']) || $_REQUEST['action'] == 'upload') { and change $_POST['apartment'] to $_REQUEST['apartment'] Is the uid (username) and pwd (password) the same credentials required for authorising the user on your site?
  22. Any resource you link to within your page the browser will download it. Sounds over complicated the way you had it before. When the image is uploaded I'd save the original to site.com/images. Then I make a thumbnail of that image and save it to site.com/images/thumbnails. When displaying the thumbnail of the image I'd use <img src="site.com/images/thumbnails/image.jpg" />If I want to link to the full sized image I'd do <a href="site.com/images/image.jpg"><img src="site.com/images/thumbnails/image.jpg" /></a>If I need to delete the images with PHP then I'd use unlink function unlink("images/$image"); // delete orginal unlink("images/thumbnails/$image"); // delete thumbnail
  23. You're getting the dagogo message because the following query is not returning any results where the pin matches the entered pass code ($password). $query=mysql_query("SELECT * FROM pin_code WHERE pin='$password'"); How are you storing the pin codes in the pin_code table? Can you provide an example of what your pin codes look like.
  24. When add an image to page and resize it with the width and height attributes you're not modifying the image. The browser will download the whole original sized image and then scales the image to what ever you set the height and width to. If you dont keep the orginal aspect ratio, then the picture will distort. What you need to do is resize the image when you have uploaded it using the php gd image library. You will find many tutorials on resizing/modifying images with PHP gd
  25. Sorry, please post in full English not text speak. I don't understand that. please give examples.
×
×
  • 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.