Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. Your HTML is fouled up. There is a "span" element within the input tag along with the ID that is meant for the span tag. Also, the 2nd validation is checking the 'address' field which doesn't exist: <html> <head> <style type="text/css"> .error { color: #ff0000; } </style> <!-- using javascript to make sure fields are not left empty --> <script type="text/javascript" language="javascript"> function validate(form1) { var valid = true; if (form1.username.value) { document.getElementById('username_error').innerHTML = ''; } else { document.getElementById('username_error').innerHTML = 'Please enter a username.'; valid = false; } if (form1.password.value) { document.getElementById('password_error').innerHTML = ''; } else { document.getElementById('password_error').innerHTML = 'Please enter a password.'; valid = false; } return valid; } <!-- using javascript to set focus of the cursor on the username textfield --> window.onload = function(){ document.form1.username.focus(); } </script> <style type="text/css"> <!-- body { background-color: #FFFFFF; } .style3 {color: #000000} --> </style> <title></title> <style type="text/css"> p.c3 {text-align: center} div.c2 {text-align: right} div.c1 {text-align: center} </style> </head> <body> <p> </p> <p> </p> <p> </p> <p> </p> <table width="100%" height="36" border="0" cellpadding="0" cellspacing="0"> <tr> <td height="36"> <div class="c1"> <img src="pics/header.png" alt="header" width="433" height="37"> </div> </td> </tr> </table> <div class="c1"> <br> Hi, please log in. </div> <br> <form id="form1" name="form1" onSubmit="return validate(this);"> <table width="100%" border="0" cellspacing="3" cellpadding="0"> <tr> <td width="39%"> <div class="c2"> <label for="username">Username:</label> </div> </td> <td width="61%"> <input name="username" type="text" size="35" /> <span id="username_error" class="error"></span> </td> </tr> <tr> <td> <div class="c2"> <label for="password">Password:</label> </div> </td> <td> <input name="password" type="password" size="35" /> <span id="password_error" class="error"></span> </td> </tr> <tr> <td> </td> <td><input type="submit" name="submit" id="submit" value=" Log in"></td> </tr> </table> </form> <p class="c3">Don't have a username? <br> Click here to register.</p> </body> </html>
  2. You should ALWAYS use mysql_real_escape_string() on ALL[/b[ user data being used in a query. It will prevent the error you are having and more importantly it will prevent malicious users from utilizing SQL injection! $username = mysql_real_escape_string($_SESSION['user_logged']); $category = "null"; $title = mysql_real_escape_string($_POST['title']); $description = mysql_real_escape_string($_POST['description']); $item_condition = mysql_real_escape_string($_POST['item_condition']); $price_ask = mysql_real_escape_string(str_replace('$', '', $_POST['price_ask'])); $price_purchase = mysql_real_escape_string(str_replace('$', '', $_POST['price_purchase'])); $qty = mysql_real_escape_string($_POST['qty']); $contactby = mysql_real_escape_string($_POST['contactby']); $image = $uploadedimg; $date = date("Y-m-d"); $sold = 'no'; $paid = 'no'; $sql = "INSERT INTO listings (listing_id, username, title, description, item_condition, price_ask, price_purchase, qty, contactby, image, date, sold, paid) VALUES ('$new_id', '$username', '$title', '$description', '$item_condition', '$price_ask', '$price_purchase', '$qty', '$contactby', '$image', '$date', '$sold', '$paid')";
  3. The only reason it might be a problem would be depending on how you are using the text area value. Without knowing how you are using it and the error you are getting it is difficult to help you. Provide more info please.
  4. I thinkt he problem is that you are hard coding the indexes for the array - so if one is missing the for loop will try to reference an element that does not exist. Try this: while($a = mysql_fetch_assoc($q)) { $packages; if( $a['package'] == "ult" ) $packages[] = array( $a['package'] => $a['picks'] ); if( $a['package'] == "sngl" ) $packages[] = array( $a['package'] => $a['picks'] ); if( $a['package'] == "mnth" ) $packages[] = array( $a['package'] => $a['picks'] ); if( $a['package'] == "ssn" ) $packages[] = array( $a['package'] => $a['picks'] ); if( $a['package'] == "po" ) $packages[] = array( $a['package'] => $a['picks'] ); if( $a['package'] == "spl" ) $packages[] = array( $a['package'] => $a['picks'] ); for( $i = 0; $i < count($packages); $i++ ) { foreach($packages[$i] as $key => $value) { switch ($key) { case "ult": $key1 = "Ultimate Lock Pick Package"; break; case "sngl": $key1 = "Single Pick Package"; break; case "mnth": $key1 = "Month Package"; break; case "ssn": $key1 = "Season Package"; break; case "po": $key1 = "Playoffs Package"; break; case "spl": $key1 = "Special Package"; break; default: $key1 = "Nothing"; break; } } } echo "<strong>" . $key1 . "</strong><br />".nl2br($value)."<br /><br />";
  5. Here's one solution. <html> <head> <style> .error { color: #ff0000; } </style> <script type="text/javascript"> function validate(formObj) { var valid = true; if (formObj.uname.value) { document.getElementById('uname_error').innerHTML = ''; } else { document.getElementById('uname_error').innerHTML = 'User name is required.'; valid = false; } if (formObj.address.value) { document.getElementById('address_error').innerHTML = ''; } else { document.getElementById('address_error').innerHTML = 'Address is required.'; valid = false; } if (formObj.phone.value) { document.getElementById('phone_error').innerHTML = ''; } else { document.getElementById('phone_error').innerHTML = 'Phone number is required.'; valid = false; } return valid; } </script> </head> <body> <form name="theForm" onsubmit="return validate(this);"> Enter your info:<br><br> User Name: <input type="text" name="uname"> <span id="uname_error" class="error"></span><br> Address: <input type="text" name="address"> <span id="address_error" class="error"></span><br> Phone: <input type="text" name="phone"> <span id="phone_error" class="error"></span><br> <br> <button type="submit">Submit</button> </form> </body> </html>
  6. Well, I would do either onchange of the field or onsubmit of the form (or both). But I would change your logic a little. For one I would only check for an empty input onsubmit of the form. A user should be able to enter and exit a field on a form (even a required field) without getting an error. Only check for required field on submission of the form. function validateSubmission() { //Other validations emailObj = document.getElementById('email'); if (!emailObj.value) { //Present the error emailObj.focus(); return false; } else if (!validEmail(emailObj)) { //Present the error emailObj.focus(); return false; } //Other validations } function validEmail(emailObj) { var isEmail = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/mgi; if (!isEmail.test(emailObj.value)) { var error = '<p class="error">Please enter a valid email address.<br />eg. example@example.com</p>'; document.getElementById('error').innerHTML = error; return false; } } Actually for the submission validation I would test for all errors then display a single error with all of the problems, this was just a samle script
  7. Sorry, I should have been more specific. The code I provided above works in both IE and FF - at least with the versions I have on my PC. The page where you incorporated my code doesn't seem to work in FF. So, I have to assume there is other code in the page that is interfering with the code for the clouds. You might need to take out certain pieces of code to find the offending problem.
  8. Again, there is something else in yur page that is causing the problem. My page above works perfectly in FF, but yours doesn't seem to move the clouds at all.
  9. I don' know what to tell you. It works perfect for me: http://www.damato.net/clouds.htm There must be other probelms in the code you are working with.
  10. Here is one way: if (in_array('3', explode('_', $vote['urVOTED']))
  11. Something happened during a last minute edit. Here is the correct code: <html> <head> <script type="text/javascript"> var leftStart = -500; var leftEnd = 1100; var numberOfCounds = 20 var minSpeed = 1.0; var maxSpeed = 2.5; var y_variation = 200; var clouds_speed = new Array(); var clouds_x_pos = new Array(); function createClouds() { var cloudDiv = document.getElementById('cloudDiv'); for (var idx=0; idx<numberOfCounds; idx++) { clouds_speed[idx] = (minSpeed + (Math.random()*(maxSpeed-minSpeed+1))); clouds_x_pos[idx] = Math.floor((Math.random()*(leftEnd-leftStart)) + leftStart); var y_pos = Math.floor((Math.random()*(y_variation+1)) - parseInt(y_variation/2)); newCloud = document.createElement('img'); newCloud.id = 'cloud_' + idx; newCloud.src = 'http://jagf.net/cloudfooter.png'; newCloud.style.position = 'absolute'; newCloud.style.top = y_pos + 'px'; newCloud.style.left = clouds_x_pos[idx] + 'px'; cloudDiv.appendChild(newCloud); } moveClouds(); } function moveClouds() { for (var idx=0; idx<clouds_speed.length; idx++) { var cloud = document.getElementById('cloud_' + idx); var y_pos = parseInt(cloud.style.top); if (clouds_x_pos[idx]>leftEnd) { clouds_x_pos[idx] = leftStart; y_pos = Math.floor((Math.random()*(y_variation+1)) - parseInt(y_variation/2)); } else { clouds_x_pos[idx] = clouds_x_pos[idx] + clouds_speed[idx]; } cloud.style.left = Math.floor(clouds_x_pos[idx]); cloud.style.top = y_pos; } setTimeout(moveClouds, 30); } </script> <style type="text/css"> div {position: absolute; top: 0; left: 0; width: 50px; height: 50px;} </style> </head> <body onload="createClouds();" style="background-color:#000000;color:#ffffff;"> <div id="cloudDiv" style="position:absolute;left:0px;top:0px;z-index:1;overflow:hidden;width:100%;height:300px;"></div> <span>Here is the content of my page<br> Here is the content of my page<br> Here is the content of my page<br> Here is the content of my page<br> Here is the content of my page<br> Here is the content of my page<br> Here is the content of my page<br> Here is the content of my page<br> Here is the content of my page<br></span> </body> </html> However, your code above has these lines: <style type="text/css"> div {position: absolute; top: 0; left: 0; width: 50px; height: 50px;} </style> It doesn't mess up the script since the div for the clouds has style properties set in-line. But, I don't see why you would want to globally set the position of all divs on the page. You should remove that. If that is for the links at the top of the page, then set those properties directly in the div or create a class name that is defined in the STYLE and set within the appropriate div.
  12. This will get you started, but there is some more work I would do: 1. Dynamically set "leftStart" based upon the width of the image(s) 2. Dynamically set leftEnd based upon the width of the image(s) and the width of the window 3. Would revise the script to utilize multiple images 4. Dynamically set y_variation based upon the height of the div container <html> <head> <script type="text/javascript"> var leftStart = -500; var leftEnd = 1100; var numberOfCounds = 3 var minSpeed = 0.5; var maxSpeed = 2.0; var y_variation = 200; var clouds_speed = new Array(); var clouds_x_pos = new Array(); function createClouds() { clouds_speed[idx] = (minSpeed + (Math.random()*(maxSpeed-minSpeed+1))); clouds_x_pos[idx] = Math.floor((Math.random()*(leftEnd-leftStart)) + leftStart); var y_pos = Math.floor((Math.random()*(y_variation+1)) - parseInt(y_variation/2)); newCloud = document.createElement('img'); newCloud.id = 'cloud_' + idx; newCloud.src = 'http://jagf.net/cloudfooter.png'; newCloud.style.position = 'absolute'; newCloud.style.top = y_pos + 'px'; newCloud.style.left = clouds_x_pos[idx] + 'px'; cloudDiv.appendChild(newCloud); } moveClouds(); } function moveClouds() { for (var idx=0; idx<clouds_speed.length; idx++) { var cloud = document.getElementById('cloud_' + idx); var y_pos = parseInt(cloud.style.top); if (clouds_x_pos[idx]>leftEnd) { clouds_x_pos[idx] = leftStart; y_pos = Math.floor((Math.random()*(y_variation+1)) - parseInt(y_variation/2)); } else { clouds_x_pos[idx] = clouds_x_pos[idx] + clouds_speed[idx]; } cloud.style.left = Math.floor(clouds_x_pos[idx]); cloud.style.top = y_pos; } setTimeout(moveClouds, 20); } </script> <style type="text/css"> div {position: absolute; top: 0; left: 0; width: 50px; height: 50px;} </style> </head> <body onload="createClouds();" style="background-color:#000000;color:#ffffff;"> <div id="cloudDiv" style="position:absolute;left:0px;top:0px;z-index:1;overflow:hidden;width:100%;height:300px;"></div> <span>Here is the content of my page<br> Here is the content of my page<br> Here is the content of my page<br> Here is the content of my page<br> Here is the content of my page<br> Here is the content of my page<br> Here is the content of my page<br> Here is the content of my page<br> Here is the content of my page<br></span> </body> </html>
  13. Well, your processing code will need to be modified for the new code since all of the POST values will be sent as arrays. Post that code for more help.
  14. I think I am understanding your problem. What you need to do is set an ID value (or whatever is the unique value for your records) for all of the fields so the processing page knows what record to update. I would do it as arrays. Then the processing page just needs to loop through the checkbox array for the is_working to determine which ones to update. I also made a couple minor changes to clean up the code and make it more readable. <?php virtual('/Connections/del.php') mysql_select_db($db_del, $del); $query_r = "SELECT * FROM shukkin ORDER BY id ASC"; $r = mysql_query($query_r, $del) or die(mysql_error()); $row_r = mysql_fetch_assoc($r); $totalRows_r = mysql_num_rows($r); ?> ... <body> <form name="form1" method="POST" action="shukkin_update.php"> <table width="563" border="1"> <tr> <th width="65">Working today ?</th> <th width="124">name</th> <th width="293" align="center">From~End</th> <th width="53">ask to admin</th> </tr> <?php do { if ($row_r['is_working']=="Y"){ $is_working_value = " checked=\"checked\" value=\"N\""; } else { $is_working_value = "value=\"Y\""; } if($row_r['flag']=="N"){ $ask_to_admin_value = " value=\"N\""; } else { $ask_to_admin_value = " value=\"Y\""; } ?> <tr> <td align="center"><input name="is_working[{$row_r['id']}]" type="checkbox" <?php echo $is_working_value;?> /> </td> <td align="center"> <input type="hidden" name="name[{$row_r['id']}]" value="<?php echo $row_r['name'];?>" /> <?php echo $row_r['name']; ?> </td> <td align="center"> <select name="start_time_hour[{$row_r['id']}]"> <option value="00">00</option> <option value="01">01</option> <option value="02">02</option> ....... </select> : <select name="start_time_min[{$row_r['id']}]"> <option value="00">00</option> <option value="10">10</option> <option value="20">20</option> <option value="30">30</option> <option value="40">40</option> <option value="50">50</option> </select> ~ <select name="finish_time_hour[{$row_r['id']}]"> <option value="00">00</option> <option value="01">01</option> <option value="02">02</option> <option value="03">03</option> <option value="04">04</option> : <select name="finish_time_min[{$row_r['id']}]"> <option value="00">00</option> <option value="10">10</option> <option value="20">20</option> <option value="30">30</option> <option value="40">40</option> <option value="50">50</option> </select> </td> <td align="center"> <input type="checkbox" name="ask_to_admin[{$row_r['id']}]" <?php echo $ask_to_admin_value;?> /> </td> </tr> <?php } while ($row_r = mysql_fetch_assoc($r)); while(mysql_fetch_assoc($r)); ?> <tr> <td> </td> <td> </td> <td> </td> <td><div align="right"> <input type="submit" name="button" value="Submit" /></div></td> </tr> </table> </form> </body> </html> <?php mysql_free_result($r); ?>
  15. I think you are saying you want the PHP variable $tutorial1 used for the file. echo "so.addParam('flashvars','streamer=lighttpd&autostart=true&file={$tutorial}');";
  16. Create your query as a string variable and echo to the page when there is an error. Makes debugging much easier: mysql_select_db("MyTable") or die(mysql_error()); $query = "UPDATE products SET cat = '{$cat}', subcat = '{$subcat}', proname ='{$pname}', model = '{$model}', prodes ='{$pdes}', proid ='{$pid}', keywords ='{$pkey}', specs ='{$pspec}' WHERE proid = '$pid' "; mysql_query($query) or die ("Error:<br>".mysql_error()."<br>Query:<br>$query";
  17. You didn't read all of my last post! I stated you only need ONE function to perform the check all and the uncheck all. I provided the function and I modified the buttons to work with that one function.
  18. Using "list[]" for a field name creates an array such as $_POST['list'] (no brackets) in PHP But JavaScript sees it as an array with the name "list[]" (with brackets). So you will need to reference it like this: document.myform['list[]'] Also, you only need ONE function for both operations. Just pass a true/false parameter for the checked value: function checkAll(fieldSet, checked) { for (var i=0; i<fieldSet.length; i++) { fieldSet[i].checked = checked; } } <form method="post" name="myform" action="deletemail.php"> <?php foreach( $array as $key => $value ){ ?> <input type="checkbox" name="list[]" value="<?=$value?>"> <?php } ?> <input type="submit" name="Submit" value="Delete!"> <br><br> <input type="button" name="CheckAll" value="Check All" onClick="checkAll(document.myform['list[]'], true)"> <input type="button" name="UnCheckAll" value="Uncheck All" onClick="uncheckAll(document.myform['list[]'], false)"> </form>
  19. "How" are you wanting to validate the Country select value? Is the first optino something like "<--Select-->"? <html> <head> <script> function validEmail(emailStr) { //Return true/false for valid/invalid email formatTest = /^[\w`\-=~!#$%^&*'+{}|'/?]+(\.[\w`\-=~!#$%^&*'+{}|'/?]+)*@[-a-z\d]{2,}(\.[-a-z\d]{2,})*\.[a-z]{2,6}$/i lengthTest = /^(.{1,64})@(.{4,255})$/ return (formatTest.test(emailStr) && lengthTest.test(emailStr)); } function validPhone(fieldObj) { var phone = fieldObj.value.replace(/[^\d]/g, '') if (phone.length != { return false; } fieldObj.value = phone; return true; } function validCode(fieldObj) { var code = fieldObj.value.replace(/[^\d]/g, '') if (code.length != 6) { return false; } fieldObj.value = code; return true; } function validate(form1) { var errors = new Array(); //Validate name if (!form1['name'].value) { errors[errors.length] = 'Name is required.'; } //Validate contact phone if (!validPhone(form1.number)) { errors[errors.length] = 'Contact number must be 8 digits.'; } //Validate mailing address if (!form1.add1.value) { errors[errors.length] = 'Mailing address is required.'; } //Validate country if (!form1.country.value) { errors[errors.length] = 'Select a country.'; } //Validate postal code if (!validCode(form1.code)) { errors[errors.length] = 'Postal code must be 6 digits.'; } //Validate email if (!form1.email.value) { errors[errors.length] = 'Email address is required.'; } else if (!validEmail(form1.email.value)) { errors[errors.length] = 'Email is not in a valid format.'; } //Validate terms & conditions if (!form1.tnc.checked) { errors[errors.length] = 'Please read and agree to our terms and conditions.'; } //There were errors if (errors.length!=0) { var msg = 'The following errors occured:'; for (var i=0; i<errors.length; i++) { msg += '\n - ' + errors[i]; } alert(msg); return false; } //No errors return true; } </script> </head> <body> <form name="" onsubmit="return validate(this);"> Name: <input type="text" name="name" id="name" /><br> Contact Number: <input type="text" name="number" id="number" /><br> Mailing Address: <input type="text" name="add1" id="add1" /><br> Country: <select name="country" id="country" /> </select><br> Postal Code: <input type="text" name="code" id="code" /><br> Email: <input type="text" name="email" id="email" /><br> <input type="checkbox" name="tnc" id="tnc" /> Accept terms<br><br> <button type="submit">Submit</button> </form> </body> </html>
  20. Not in any easy way that would be worthwhile. The only way would be to maintain two fields: one where the user types and a hidden field which actually holds the password. As the user types you would need to capture the character pressed, add it to the hidden password field and then add a '#' to the password "display" field. but, it will get complex very quickly when you consider users can slect the middle part of the text and enter chancters anywhere, eginning, middle or end. Plus, they can backspace or delete characters and cut and paste. Definitely not worth the trouble in my opinion.
  21. <?php $query = "select * from iss"; $result = mysql_query($query ); echo "<table border=\"0\" cellspacing=\"5\" width=\"80%\"><tr valign=\"top\">\n"; $records_per_column = ceil(mysql_num_rows($result)/3); $current_record = 1; while($record=mysql_fetch_array($result)) { if ($current_record==1) { echo "<td width=33%>\n"; } $checked = (in_array($record['id'], $_POST['is'])) ? ' checked="checked"' : '' ; echo "<input type=\"checkbox\" name=\"is[]\" value=\"{$record['id']}\"$checked />{$record['isadi']}<br>\n"; $current_record++; if($current_record > $records_per_column) { echo "</td>\n"; $current_record = 1; } } if($current_record != 1) { echo "</td>\n"; } echo "</tr></table>"; ?>
  22. That's because '0' is considered an "empty" value so it fails the very first test of if (!empty($_POST['ipaddr'])) { So it will never get to the value test of if ($ipaddr < 1 || $ipaddr > 254) { See the manual for all the values that are determined to be "empty": http://us2.php.net/manual/en/function.empty.php You could try this: if (isset($_POST['ipaddr']) && strlen(trim($_POST['ipaddr']))) { $ipaddr = intval(trim($_POST['ipaddr'])); if ($ipaddr < 1 || $ipaddr > 254) { $msg = "IP # must be in range 1-254<br>"; send_error($msg); } }
  23. Your problem is not that those parameters require a transitional doctype. They work just fine with a transistional doctype. This simple test works just fine in IE & FF: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <script> function snow() { alert(document.body.clientWidth); alert(document.body.clientHeight); return; } window.onload = snow; </script> </head> <body> Test </body> </html> There must be something else wrong, but I'm unable to detemine from what you have provided so far.
  24. Well, first off I will state that you should just pre-select one of the radio options since the user can only change the selected option and cannot unselect all of the options. But, there are some cases where you do not want to pre-select an option. The problem is that a radio GROUP is an array of elements - each with it's own value (however, if there is only one element in the group then it is not an array). You need to determine which element is CHECKED and return the value of that element. Add this function to your page: function radioGroupValue(groupObj) { //Check if radio group has multiple options (i.e. is an array) if (groupObj.length) { //Radio group has multiple options //Iterrate through each option for (var i=0; i<groupObj.length; i++) { //Check if option is checked if (groupObj[i].checked) { //Return value of the checked radio button return groupObj[i].value; } } } else { //Radio group only has one option if (groupObj.checked) { return groupObj.value; } } //No ption was selected return false; } Then change your validation to this: if (radioGroupValue(formObj['gender'])!==false) { errors[errors.length] = Gender cannot be empty.'; }
  25. This page has an example: http://groups.google.co.ke/group/comp.lang.javascript/msg/011abc4a091f62c5
×
×
  • 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.