Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. You could simply populate a hidden field in the form when the page loads with a unique value (i.e. datatime+rand() number). Then when processing that page first check if any existing records have that value. If so, do not add the duplicate entry. If not, store the new record, including the unique value.
  2. The code you provided is of no help. To get help with JavaScript, please post the geneerated HTML code - i.e. not the PHP code.
  3. Javascript IS a great way to give the user immediate feedback, however it should NOT be relied upon as the only validation. You must ALWAYS have server-side validation. User can have JS turned off or submit data without using your form.
  4. if (ctype_digit($input) && strlen($input)==16) { echo "The input is numeric and is 16 characters long"; } else { echo "The input is not numeric and/or is not 16 characters long"; }
  5. Well the query would look something like this: $insertSQL = sprintf("INSERT INTO comments (Name, Comments) VALUES (%s, %s)", GetSQLValueString($_SESSION['username'], "text"), GetSQLValueString($_POST['comment'], "text") ); But, I don not know your database or where you are storing the username - if you even are. Make sure you know that the column names in the query are correct and that you are properly accessing the username.
  6. Well, where is the username stored when they log in? In many cases the username is stored to a session variable such as $_SESSION['username']. So, when the user submits a comment, just use that variable. Example: $query = "INSERT INTO table (name, comment) VALUES ('{$_SESSION['username']}', '{$_POST['commnet']}')";
  7. No need to use regex in that situation, just use strpos(): http://www.php.net/manual/en/function.strpos.php
  8. <html> <head> <script type="text/JavaScript"> <!-- var categoryAry = new Array("Jokes","Poems","Videos"); var subCatAry = new Array (); subCatAry['Jokes'] = new Array('Adult', 'Alcohol', 'Bar', 'Blonde', 'Brunette', 'Classic', 'Men', 'Sport', 'Women'); subCatAry['Poems'] = new Array('poem1', 'poem2', 'poem3'); subCatAry['Videos'] = new Array('Alcohol', 'Animals', 'Babies', 'Gender', 'Sports'); function changeCategoryOptions() { sel1Obj = document.getElementById('sel1'); changeOptions(sel1Obj, categoryAry); changeSubCatOptions(sel1Obj); } function changeSubCatOptions(sel1Obj) { changeOptions(document.getElementById('sel2'), subCatAry[sel1Obj.value]); for (var i=0; i<categoryAry.length; i++) { if (inputDiv = document.getElementById(categoryAry[i]+'_Input')) { inputDiv.style.display = (categoryAry[i]==sel1Obj.value)?'inline':'none'; } } } function changeOptions(fieldObj, valuesAry) { fieldObj.options.length = 0; for (var i=0; i<valuesAry.length; i++) { fieldObj.options[i] = new Option(valuesAry[i], valuesAry[i]); } } //--> </script> </head> <body onload="changeCategoryOptions();";> <form name="sform" method="post"> Category: * <select name="sel1" id="sel1" onchange="changeSubCatOptions(this);"></select> <br> Sub-category: * <select name="sel2" id="sel2"></select> <br><br> <div id="Jokes_Input"> Joke Title: * <input type="text" name="title" maxlength="35"><br> Joke Text: * <textarea name="text" style="width: 400px; height: 200px;"></textarea> </div> <div id="Poems_Input"> Poem Title: * <input type="text" name="title" maxlength="35"><br> Poem Text: * <textarea name="text" style="width: 400px; height: 200px;"></textarea> </div> <br><input type="submit" value="Submit"> </form> </body> </html>
  9. What is the threshhold? You would have to compare color variations, size, etc. There might be some third party tools that you could plug into. ImageMagick can do a mathmatical comparison betwen two images and has a command line interface, so that might be a possibility. http://www.imagemagick.org/script/compare.php
  10. I had to create a JS external source file that I gave an ID to so I can change the source of that external file with the function. With all due respect Obsidian, did you not read the part of my post that stated "This works in IE & FF, not tested in other browsers"? It absolutely DOES work, I have done this in the past. The code I posted works exactly as described.
  11. You just need a single query to accomplish all of that! Assuming word_count is the field you want updated by adding a number: the following script will attempt to insert all of the values intot he database, but if it finds a duplicate it will instead update the count field by 1. $var = "book programming"; $values = '(' . implode('), (', explode(' ', $var)) . ')'; $query = "INSERT INTO table (k_word) VALUES $values ON DUPLICATE KEY UPDATE word_count=word_count+1";
  12. As I said, going through all your code to figure out how to implement what you want would be time consuming. I only provided an example of how it could be accomplished. If you need someone to rewrite it for you then you could try the freelance forum. As for the database error - that is because the sample script doesn't include the code necessary to connect to the database. Again, it is just an example - the logic is sound.
  13. Trying to go through all of your code to see how to implement that would take a while. Instead I will provide a sample script that has the functionality you explained. Use it to modify your existing script: <?php if (isset($_POST['name']) || isset($_POST['email'])) { $name = trim($_POST['name']); $email = trim($_POST['email']); $nameError = false; $emailError = false; //Validate the name if (empty($name)) { $nameError = "You must enter a name."; } //Validate the email if (empty($email)) { $emailError = "You must enter an email."; } else { $query = "SELECT * FROM users WHERE email = '$email'"; $result = mysql_query($query) or die (mysql_error()); if (mysql_num_rows($result)!==0) { $emailError = "That email address already exists."; } } //Check for any errors if (!$nameError && !$emailError) { //Send email header('Location: http://www.mysite.com/thankyou.php'); exit(); } //Error exists, reformat values for repopulating fields $name = stripslashes($name); $email = stripslashes($email); } ?> <html> <head> </head> <body> <form name="testForm" method="POST"> Name: <input type="text" name="name" value="<?php echo $name; ?>" /><br /> <span style="color:red;"><?php echo $nameError; ?></span><br /> Email: <input type="text" name="email" value="<?php echo $email; ?>" /><br /> <span style="color:red;"><?php echo $emailError; ?></span><br /> <br /> <button type="submit">Submit Data</button> </form> </body> </html>
  14. Your query is failing - add some error handling $result = mysql_query($SQL) or die("Error:<br>".mysql_error()."<br>Query:<br>$SQL");
  15. Well, it will return the result as an array, but that's a non issue.The question is if there will only be one match or multiple. If on you can use preg_match, if multiple you will want to use preg_match_all() $input = '<content type="html"><p><a href="http://www.flickr.com/people/4353454@N4502/">user</a> has added a photo to the pool:</p> <p><a href="http://www.flickr.com/photos/999999@343/2808182892/" title="Sunset"><img src="http://farm4.static.flickr.com/3028/2808122892_e33d52ed02_m.jpg" width="240" height="180" alt="Sunset" /></a></p> </content>'; preg_match('/http:\/\/[^ ]*?jpg/', $input, $matches); $found = $matches[0]; echo $found;
  16. Or you could make the code just a little more verbose and include some proper error checking as well as add clarity. [Notice the use of isset()] while($dbarray = mysql_fetch_row($result)) { for($t=1; isset($dbarray[$t]); $t++) { echo "<input type=\"text\" name=\"".$dbarray[$t]."\" value=\"".$dbarray[$t]."\" /><br />"; } }
  17. You didn't answer my first question. Are the results ordered in any fashion? Can you show a representative sample of the results?
  18. Just create a link to an external script like you showed, but give it an ID. Then change the src of that external script on the fly. This works in IE & FF, not tested in other browsers. here is a very quick example - i.e. not production ready. HTML File <html> <head> <script type="text/javascript" id="validateScript" src="validate_ind.js"></script> <script type="text/javascript"> function changeValidation(validateID) { document.getElementById('validateScript').src = 'validate_' + validateID + '.js'; } </script> </head> <body> Form Type: <select onchange="changeValidation(this.value);"> <option value="ind">Individual</option> <option value="corp">Company</option> </select> <br /><span style="color:red;"> For Individual Name & Phone are required.<br /> For Company Name & Email are required.<br /> </span><br /> Name: <input type="text" name="name" id="name" /><br /> Phone: <input type="text" name="phone" id="phone" /><br /> Email: <input type="text" name="email" id="email" /> <br /><br /> <button onclick="validate();">Test Validation</button> </body> </html> validate_ind.js function validate() { nameObj = document.getElementById('name'); phoneObj = document.getElementById('phone'); if (!nameObj.value || !phoneObj.value) { alert('Validation Falied!\n\nName/Phone not entered.'); } else { alert('Validation Passed!'); } return; } validate_corp.js function validate() { nameObj = document.getElementById('name'); emailObj = document.getElementById('email'); if (!nameObj.value || !emailObj.value) { alert('Validation Falied!\n\nName/Email not entered.'); } else { alert('Validation Passed!'); } return; }
  19. So, what do the results look like? Are they ordered at all? Try putting backquotes around all field names. Type may be interpreted as a reserved word instead of a column name.
  20. echo "<table style=\"border: 1px solid black;\">\n"; $max_cols = 12; $max_rows = 12; for ($row=0; $row<=$max_rows; $row++) { echo "<tr>\n"; for ($col=0; $col<=$max_cols; $col++) { if ($col==0 || $row==0) //Header cell { echo "<th style=\"background-color:#cecece;\">"; if ($row==0 && $col==0) { echo " "; //Blank cell for top left } else { echo (($row==0) ? $col : $row) ; //Display row/column header } echo "</th>"; } else //data cell { echo "<td style=\"border: 1px solid #000; width: 25px; padding: 4px; text-align:center;\">"; echo ($row * $col); echo "</td>"; } } echo "</tr>\n"; } echo "</table>";
  21. You should create your queries as string variables so you can echo them to the page when they fail for debugging purposes! And put an on die() handler on there to see what the error is. $query = "SELECT fice FROM characteristics WHERE offering IN ($offering_sql) AND $public_private_sql AND $twofour_sql"; $result = mysql_query($query) or die("Error:<br />".mysql_error()."<br />Query:<br />$query");
  22. I don't see the need for the hidden field. Can't you just use the SELECT field value for the category ID? Always try to implement your JavaScript such that the page will still work without it. It might be true that some implementations are for a closed network where the browser settings is a known variable, but it is good practice, nonetheless. In the implementation above, if the category text is not populated, that is OK since the user is wanting to edit the value anyway. But, relying upon JavaScript to populate a hidden field is very bad practice in my opinion. If the JavaSCript fails the page fails.
  23. I don't think the OP wants the VALUE, I think he wants the TEXT. <select name="menu1" onchange="edit_cat.hidden_category.value=this.options[this.selectedIndex].text;"> Although, it dioesn't make any sense to me - why not just make the text and the value of the select field the same so youdon't need a hidden field. Using JS to populate a hidden field is about the worst use of JS that I can think of.
  24. Well, you've already marked the topic as solved, but I have to ask. If you already have a select field that allows multiple inputs, why do you need to populate the selected values into a hidden field?
×
×
  • 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.