Jump to content

perky416

Members
  • Posts

    177
  • Joined

  • Last visited

Everything posted by perky416

  1. Hi Guys, I am trying update some array values in my database. For some reason using the code below the $checked and $counter values are not working. I have added the echos for debugging purposes and nothing is being echoed. $query = mysql_query("SELECT * FROM offers WHERE seller='$username' AND buyer='$buyer'"); while ($row = mysql_fetch_assoc($query)) { $checked = $_POST['checkbox'][$y]; $counter = $_POST['counter'][$y]; echo $checked; echo $counter; $date = date("Y-m-d"); $time = date("H:i:s"); mysql_query("UPDATE offers SET offer='$counter',seller_status='Counter Offer Made',buyer_status='Counter Offer Received',date='$date',time='$time',seller_action='0',buyer_action='1' WHERE domain='$checked'"); } When i do the following it echos the $checked and $counter values perfectly so i know that the form is posting ok. foreach ($_POST['checkbox'] as $checked) { echo $checked; } foreach ($_POST['counter'] as $counter) { echo $counter; } Can anybody figure out what is wrong with my while loop? Iv been at it for ages and cant seem to crack it. Thanks
  2. Sorry i missed off them email part. To validate the email use: <td width='550px'><input name='email' type='text' id='email' size='32' />if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {$error[] = "The email address you have entered is invalid!";}</td> Id create another field in the database table called "private". Then you could use: if (isset($_POST['private'])){ $private = "yes"; } else { $private = "no"; } Then in your mysql query that you use to write your values to the database, add: private='$private' Finally on the page where you display the guest book data, you could use: if ($private == "yes"){ echo "Private"; } else { echo "$email"; } Again this is untested, but it should work. It may not be the most efficient method but im a little short on time to play around with it.
  3. Hi Big_R, I use the following for my form validation: Put this somewhere near the top of your page: $error = array(); Where you have your form field use: <td width='550px'><input name='name' type='text' id='name' size='32' /><?php if (empty(!$_POST['field_name'])) { $error[] = "Please enter your name"; } ?></td> Then where you write the input to your database use: if (empty($error)) { mysql_query("insert into guestbook values('','$date','$name','$email','$song','$part','$comments')"); } else { echo implode($error); This is basically saying if you dont have an error, write to the database, otherwise display the error message. For writing a default message you could use something like: if (empty($_POST['part'])) { $favourite_part = "--"; } else { $favourite_part = $_POST['part']; } This code is untested but it should work. Hope it helps.
  4. Iv managed to figure it out, It always seems that just after i post asking for help i get some inspiration that helps me figure it out lol. If anybody else needs this answer in the future i simply put a while loop inside the foreach with the query selecting results where product=$product.
  5. Hi Guys, Im using the code below to display the value of checked checkboxes on form submission, however im also trying to pull the price from the database for each checked value. foreach ($_POST['check'] as $product) { echo $row['price'] . " " . $row['currency'] . " for " . $product . "<br />"; } Please could somebody point me in the right direction as to what id need to do. As iv only been able to get it to display the price of the first checked value. Thanks
  6. Hi guys, session_start() is used on every one of my pages as I use it to identify if a user is logged in. Please tell me if im wrong but from what i have read, without using the GET or cookies (in case the user has cookies turned off), to store the form data in a session wouldn't it have to be posted? $_SESSION['price'] = $_POST['price']; As iv used pagination, effectively everything is the same page, however it displays a different part of the database depending on which link is pressed. Example: if the user clicks <a href'page.php?start=10'>Page 2</a>, they will still be on page.php, however the info shown on the page will only be displayed from the 11th result in the database onwards.
  7. I did consider passing it through the URL and then using GET however the user has the option to edit up to 100 fields at a time, then if they go over a few pages before submitting the form that could be 300 pieces of data in the URL which i thought was a bad idea. I also tried using $_SESSION, however i haven't used them that much before so i may have got it wrong. I simply tried using value="$_SESSION['form_name']'" in the form field. Would i have to do something else? Thanks
  8. Hi mate, I think i know what you mean. If you send the link via email you could include the link in the body, something like: http://yoursite.com/jointeam.php?team=$team_name $team_name would be taken from the users row in the database who is sending the link. When the user clicks the link, jointeam.php would take $team_name from the url using the $_GET method and then you could use a mysql_query to write the team name to the new members row in the database. Sorry i had to be brief im just on my way out. If nobody else helps you by the time i get back and its not too late i could write you up a quick example if you want. Hope it helps.
  9. Hi Eveyone, Is it possible in php to remember form data when scrolling through pages set up using pagination? Usually i use value="<?php echo $_POST['field_name']; ?>" to remember the form data if the submit button has been pressed. Im trying to get it so that if i fill out a field on page 1, then i go to page 2, if i come back top page 1 the field is still populated. Scrolling through the pages nothing is actually posted so the fields are becoming empty when returning to them. All help is greatly appreciated. Thanks
  10. Hi guys, Im completely at a loss with this. Im working on a domain script, so people could add domains such as 10.com, test1.com, ismell.com, so it will never be a fixed format. Im tearing my hair out lol. I cant seem to find anything on google about this to work with.
  11. Hi mate thanks for your response, I managed to figure out how to do it using the following: echo "<td><a href='products.php"; if ($sort == 'price_asc') { echo "?sort=price_desc'>Price</td>"; } else { echo "?sort=price_asc'>Price</td>"; }
  12. Hi Everyone, I have a page on my website that displays a list of products from a mysql database in a table. Currently when the column titles are clicked, the data is sorted in order with the highest first. $sort = $_GET['sort']; if ($sort == 'price') { $query = mysql_query("SELECT * FROM products ORDER BY price DESC"); } else{ $query = mysql_query("SELECT * FROM products ORDER BY product"); } ... echo "<a href='products.php?sort=price'>Price</a>"; Does anybody know how i would go about setting it up so that if the sort link is clicked a second time, the data is re ordered from descending to ascending? Then if the click is clicked again it would change back to descending, and so on.....? Many thanks
  13. Hi Guys, When im pulling data from my database and displaying it on my page, im using ORDER BY in my query to display the data in alphabetical order. When it comes to displaying data with numbers in it, it isnt ordering how i want it. Example: This is how it is currently ordering the data: test1 test10 test11 test12 test13 test14 test15 test16 test17 test18 test19 test2 test20 and so on.... How would i go about getting it to display like: test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 test11 test12 and so on.... Thanks
  14. Hi NUDD, You have said pretty much what i thought, its reassuring to get someone else's input. Iv decided to add check box's to the form that handles the data, now the query only updates rows where the box is checked, and im going to limit each page to a maximum of say 100 rows. Thanks mate
  15. Hi Everyone, Im working on a script that edits multiple rows of a database. Currently when the submit button is clicked, a mysql query updates the table with the new information. It is possible that my website users could have hundreds of rows to edit, so i was wondering will it make much difference speed wise if i let the script continue to update all of the fields in all of the rows, or would it be faster if it only updates fields that have changed? Thanks
  16. Thanks guys i got it to work. I did try it without the quotes in the first place but it still did not work. After reading into the deprecated split() iv decided to go with explode(). Thanks
  17. I have tried using the code below which i found in another post however nothing writes to the database. if ($_POST['submit']) { $values = $_POST['textarea_name']; $array = split("\r\n", $values); foreach($array as $line) { mysql_query("INSERT INTO table_name('field_name') VALUES($line)"); } }
  18. Hi Everyone, Hopefully this will be a quick one. How would i write each line in a textbox as a new row in a mysql database? I cant seem to find the solution on google. Thanks
  19. Hi Everyone Does anybody know if there an alternative to preg_match? I cant get my head round regex so im having difficulty setting different preg matches. Is there an easier alternative? Thanks
  20. Ahhh i understand now. I was getting the impression that people could easily de-hash an md5 password and reveal the plain text of the hash. Thats why i was starting to wonder lol. So what most of you are saying is that the hacker has a database with hashed words that he just checks against the user passwords. And adding the salt means the password wont pop up fro his list. Thanks guys,
  21. Hi guys, Iv been reading into password salting and im struggling to understand its purpose. From what iv read you can basic salt a password by doing the following: $salt = "randomtext"; $password = "apple"; $password = md5($password.$salt); I was wondering though, if a hacker is able to crack the md5, wont they see the password and the salt? Example: a hacker cracks the md5 to reveal applerandomtext. From applerandomtext it wont be hard for them to work out that the password is apple. So doesn't that make the idea of salting pointless?
  22. You can find another good upload and resize script here: http://www.phpmagicbook.com/upload-image-and-create-thumbnail/ It also creates a thumbnail for you, however if you dont need it you can always remove that part of the code.
  23. Hi alamnaryab, I use something similar for the messaging on my website. When a user clicks on the sender or subject I redirect to the page which displays the message and send the message id in the URL. $message_id = $messages_row['id']; echo "<a href='message.php?id=$message_id'>"; echo "From: " . $messages_row['sender']; echo "Subject: " . $messages_row['subject'] . "<br />"; echo "</a>"; Then on the page that displays the message i use $_GET to retrieve the message id from the URL. $message_id = $_GET['id']; $messages_query = mysql_query("SELECT * FROM messages WHERE id='$message_id' AND recipient='$username'"); $messages_row = mysql_fetch_assoc($messages_query); Hope it helps
  24. Hi Stefsoko, As Crayon Violent suggested, i use strlen(). An example you might use could be: if (strlen($message) < 15 || strlen($message) > 150) { echo "Your message must be between 15 and 150 characters!"; }
  25. Hi Mate, Im going to do a javascript/ajax uploader as well however i wanted a php backup incase the user has javascript disabled. I just tried what you said however im still getting an error for each upload field. Im trying to get it so that out of my 6 upload fields, if none of them have a file selected it should return only one UPLOAD_ERR_NO_FILE error instead of 6 errors, if only one field has a file selected, it should return no UPLOAD_ERR_NO_FILE errors. Its just so that i can say to my users something like "Please select a file to upload" if they click the upload button and no file has been selected. Any ideas? Thanks
×
×
  • 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.