Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. Well, first off I would NOT include this line: <input type="hidden" name="mailto" value="someone@work.com"> You should never include an email address on a web page unless you want to receive a ton of spam. Instead handle the mailto address in the processing page. In the processing page I would use something like this: $send_to = 'someone@work.com'; if ($_GET['out']=='Int') { $send_to .= ';me@work.com'; }
  2. That the same link rhodesa posted in reply #1
  3. Your original post showed an example with parent and child records. It did NOT show, nor did you mention, that the child records could also have sub-child records. That is a VERY important piece of information that you left our. As my sig states "The quality of the responses received is directly porportional to the quality of the question asked." Even with that new information, what you originally asked in the first post doesn't solve that problem. You might want to look at the link rhodesa provided above. But, using the NEW parametes you have provided, it is still a fairly easy operation to delete a record and all it's child records. Although I abhore doing queries within loops the most straitforward appraoch would be a recursive function: function deleteRecord($recordID) { //Delete the parent record $query = "DELETE FROM table WHERE id = $recordID"; mysql_query($query) or die (mysql_error()); //Find the child records for the current record $query = "SELECT id FROM table WHERE parent = $recordID"; $result = mysql_query($query) or die (mysql_error()); //Repeat process for each child record while ($childRecord = mysql_fetch_assoc($result)) { $childID = $childRecord['id']; deleteRecord($childID); } }
  4. Then you aren't doing it right. in my example above you can delete ALL the child records for the parent with the ID of 10 with the following query DELETE FROM table WHERE parent = 10 OR you can delete the parent and all child records with a single query DELETE FROM table WHERE id = 10 OR parent = 10
  5. function isInt (value) { return (!isNaN(value) && (value==Math.round(value)); }
  6. Doing that would make it difficult to query for child elements. It would make much more sense to me, just to create a field for the parent (use 0 if the element is a parent) id | parent | cat_name ----+--------+------------- 9 | 0 | Parent 10 | 0 | Another Parent 11 | 9 | Sub Cat 13 | 10 | Sub Cat 2 12 | 10 | Sub Cat 3 You could then easily create the node at run time like so: if($record['parent']==0) { $node = sprintf("%03d", $record['id']); } else { $node = sprintf("%03d%03d", $record['id'], $record['parent']); }
  7. I fyou are on a linux server you can create a CRON job. If you are on a Windows server you can create a scheduled task.
  8. "How" is it not working? I don't have your database set up so I can't test the code - there may be syntax errors (as stated in my sig). The code you posted last does nothing to prevent the insert of records. The code I posted should be a valid process to handle the functionality you need - but it probably needs some massaging.
  9. Well, then he is using the wrong terminology. In the first post the OP stated he couldn't even use PHP. If that is the case (and there is no other server-side code that can be used) then he is SOL.
  10. Well, do they just have to be numeric? If so, you can use the isNAN function (is not a number). But, if you want the numbers to be of a certain precision (e.g. two decimal places you would want additional functionality. You should give the fields an id - I'd just give them an ID the same as their name. Then you could do this: valid() { var fieldObj = document.getElementById('Stockamount'); if (isNAN(fieldObj.value)) { alert('Stock amount must be a number'); fieldObj.focus(); fieldObj.select(); return false; } var fieldObj = document.getElementById('Price'); if (isNAN(fieldObj.value)) { alert('Price must be a number'); fieldObj.focus(); fieldObj.select(); return false; } return true; }
  11. Yes, there is nothing you can't do on a sub-domain that you can do on a domain. In fact a "domain" is in fact a sub-domain as well. php.net is a sub-domain of the TLD (Top Level Domain) .net
  12. There are a lot of problems with that code: 1. You are not using trim & not "cleaning" the user input 2. The line or die ('Registration was Unsuccessful, The P number already exists'); makes an assumption that may not be true 3. You need to validate that the passwords match. 4. I think this line is unnecessary if (mysql_affected_rows() == 1) If the query doesn't fail then a record is entered, correct? What does the file 'connect.php' do? You are already connecting to the db in this script. Typically I include the form processing in the same script page as the form, that way if validation fails you can repopulate the form with the entered values. Here's an example: <?php ini_set('session.gc_maxlifetime', 10); session_start(); $error = ''; if (isset($_POST['submit'])) { // if form has been submitted include('connect.php'); mysql_connect("$host", "$username", "$password") or die ("Cannot Connect To The Database"); mysql_select_db("$dbname") or die("Cannot Select Database"); //trim input and make DB safe $student_id = mysql_real_escape_string(trim($_POST['pid'])); $full_name = mysql_real_escape_string(trim($_POST['full_name'])); $course = mysql_real_escape_string(trim($_POST['course'])); $email_address = mysql_real_escape_string(trim($_POST['email_address'])); $password = mysql_real_escape_string(trim($_POST['password'])); $password_again = mysql_real_escape_string(trim($_POST['password_again'])); //Form validation if (empty($student_id) || empty($full_name) || empty($course) || empty($email_address) || empty()) { //Checked all required fields $error = 'You did not fill in all required fields.'; } else if ($password!=$password_again) { //Checked that passwords match $error = 'Your passwords do not match.'; } else { //Check for duplicate id number $query = "SELECT * FROM student WHERE student_id = '$student_id'"; $result = mysql_query($query) or die ("The query:<br>$query<br>Produced the error:<br>".mysql_error()); if (mysql_num_rows($result)!=0) { $error = 'That student ID number already exists.'; } } if (!$error) { $adduser = "INSERT INTO student (student_id, full_name, course, email_address, password) VALUES('','"$full_name','$course','$email_address','$password')"; $result = mysql_query($adduser) or die ("The query:<br>$adduser<br>Produced the error:<br>".mysql_error()); header("location:registercomplete.php"); } } ?> <html> <head></head> <body> <?php echo $error; ?> <form name="registration" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> Student ID: <input type="text" name="pid" value="<?php echo $_POST['pid']; ?>" /><br> Ful Name: <input type="text" name="full_name" value="<?php echo $_POST['full_name']; ?>" /><br> course: <input type="text" name="course" value="<?php echo $_POST['course']; ?>" /><br> Email: <input type="text" name="email_address" value="<?php echo $_POST['email_address']; ?>" /><br> Password: <input type="text" name="password"><br> Verify Password: <input type="text" name="passwd_again"><br> <button type="submit">Submit</button> </form> </body> </html>
  13. The fact that you are ona sub-domain does not preclude you from using PHP or any other server-side language. Don't rely on JavaScript for any type of login system.
  14. That should work, but you could run into problems due to differences in browsers. Especially if you ever need to add another event to one of those triggers. You would be wiping out all the trigger events by setting it to null. Instead I would suggest creating a single function to handle boththe onchange and the onclick events. That function would first determine if there is a single element or multiple and then act accordingly. I'm not 100% sure and too lazy to check at the moment - but does a select field even support "onclick"? May need to use "onfocus" function updateSelect (selectObj, trigger) { if ((selectObj.length>1 && trigger=='change') || (selectObj.length==1 && trigger=='focus')) //run the function } } <select name="name" onchange="updateSelect(this,'change');" onfocus="updateSelect(this,'focus');"> However, if hte field only has one value you could just fire the event automatically when loaded instead of forcing the user to click on the field.
  15. Oh, hell - I had a typo. Change this: //New title $current_episode_id == $row['EpisodeID']; To this: (remove the second equal sign) //New title $current_episode_id = $row['EpisodeID'];
  16. Try this: <?php function searchresult() { /************************************************************************************** * Main Search Page - search.php * Author: Your Name <email@something.com> * This file searches the database **************************************************************************************/ //search variable = data in search box or url $search = trim($_GET['search']); if (empty($search)) { //No search values entered echo "<table cellspacing=0 cellpadding=10 width=\"100%\" border=0>"; echo "<tr><td align=center><b>Please enter a search parameter to continue.</b></td></tr>"; echo "</table>"; } else { //Get variables from config.php to connect to mysql server include 'dbconfig.php'; include 'dbopen.php'; //Remove duplicate whitespace $search = preg_replace('/\s+/', ' ', $search); //seperate multiple keywords into array space delimited $keywords = explode(" ", $search); //Clean empty arrays so they don't get every row as result (not really needed) $keywords = array_diff($keywords, array("")); //Make values db safe foreach ($keywords as $key=> $value) { $keywords[$key] = mysql_real_escape_string($value); } //Create the query $titleClause = "Title Like '%" . implode("%'\n OR Title Like '%", $keywords) . "%'"; $artistClause = "Artist Like '%" . implode("%'\n OR Artist Like '%", $keywords) . "%'"; $albumClause = "Album Like '%" . implode("%'\n OR Album Like '%", $keywords) . "%'"; $query = "SELECT * FROM songtable JOIN episodetable ON episodetable.EpisodeID = songtable.EpisodeID WHERE $titleClause OR $artistClause OR $albumClause ORDER BY songtable.EpisodeID, songtable.SongID ASC"; //Store the results in a variable or die if query fails $result = mysql_query($query) or die("The query:<br />$query<br />Produced the error:<br />".mysql_error()); //Check returned results if (mysql_num_rows($result)==0) { //No reults returned echo "<table cellspacing=0 cellpadding=10 width=\"100%\" border=0>"; echo "<tr><td align=center><b>Your query \"$value\" returned no results from the database.</b></td></tr>"; echo "</table>"; } else { echo "<table cellspacing=0 cellpadding=10 width=\"100%\" border=0>"; echo "<tr><td align=center>You searched for <b>" . implode (", ", $keywords) . "</b></td></tr>"; $current_episode_id = ''; while($row = mysql_fetch_array($result)) { //Alternate album row colors $currentcolor = ($currentcolor=='#ffffff' ? '#f2f2f2' : '#ffffff'); if ($current_episode_id != $row['EpisodeID']) { //New title $current_episode_id == $row['EpisodeID']; echo "<tr><td style=\"text-align:center;background-color:#000000;color:#ffffff;\">\n"; echo "<div id=\"eptable\"><h2>Episode {$row['EpisodeID']}: {$row['EpisodeName']}</h2></div>\n"; echo "</td></tr>\n"; $currentcolor=='#ffffff'; } //Show the album record $artist = ($record['AA'] == "1")? $record['AAName'] : $row['Artist'] ; echo "<tr><td style=\"background-color:$currentcolor;text-align:left;\">\n"; echo "<b>Title:</b> {$row['Title']}<br>\n"; echo "<b>Artist:</b> {$row['Artist']}<br>\n"; echo "<b>Album:</b> <a href={$row['AlbumLink']}>$artist - {$row['Album']}</a><br>\n"; echo "</td></tr>\n"; } //Close results table echo "</table>\n"; } //Clean up db connection mysql_free_result($result); include 'dbclose.php'; } ?>
  17. If I am understaning what the script is supposed to be doing, it is not generating the correct time. Here is one way to accomplish a countdown in the format you asked: <script language="JavaScript"> <!-- var day_unit = 86400000; var hour_unit = 3600000; var minute_unit = 60000; var second_unit = 1000; function showtime() { nowTime = new Date(); if (sourcedate>nowTime) setTimeout("showtime();",1000) date_diff = sourcedate - nowTime; days = Math.floor(date_diff/day_unit); date_diff = date_diff - days * day_unit; hours = Math.floor(date_diff/hour_unit); date_diff = date_diff - hours * hour_unit; minutes = Math.floor(date_diff/minute_unit); date_diff = date_diff - minutes * minute_unit; seconds = Math.floor(date_diff/second_unit); time_remain = days+' Days '+hours+' Hours '+minutes+' Minutes '+seconds+' Seconds'; document.all["clock"].innerText = time_remain; return; } sourcedate = new Date(2008, 2, 24, 5, 5, 5); //--> </script>
  18. I stand corrected - interesting that a search for "static" at php.net doesn't bring up any results.
  19. Use the "onsubmit" trigger in the FORM tag, not the onclick event in your button: Example: <form name="name" onsubmit="return check(form,form.elements.length);"> Also, there is no need to pass "form.elements.length" in the function call - that can be deduced from the form object you are passing.
  20. "static" is not even a PHP function/command. Try "define" instead to create a constant: http://us.php.net/define
  21. Hmmm, it shouldn't repeat the title due to this if ($current_title != $row['Title']) { //New title $current_title == $row['Title'];
  22. How to fix "what"? What IS the problem? What is or isn't happening that you want to be different?
  23. You have a lot of unnecessary code in there. For example //search variable = data in search box or url if(isset($_GET['search'])) { $search = $_GET['search']; } But, then you use the variable $search anyway - whether or not you set it. I have made a lot of changes in the code below to fix some of the issues and to make the code easier to follow. I'm sure there are some syntax errors as I could not test it - but it should be close <?php function searchresult() { /************************************************************************************** * Main Search Page - search.php * Author: Your Name <email@something.com> * This file searches the database **************************************************************************************/ //search variable = data in search box or url $search = trim($_GET['search']); if (empty($search)) { //No search values entered echo "<table cellspacing=0 cellpadding=10 width=\"100%\" border=0>"; echo "<tr><td align=center><b>Please enter a search parameter to continue.</b></td></tr>"; echo "</table>"; } else { //Get variables from config.php to connect to mysql server include 'dbconfig.php'; include 'dbopen.php'; //Remove duplicate whitespace $search = preg_replace('/\s+/', ' ', $search); //seperate multiple keywords into array space delimited $keywords = explode(" ", $search); //Clean empty arrays so they don't get every row as result (not really needed) $keywords = array_diff($keywords, array("")); //Make values db safe foreach ($keywords as $key=> $value) { $keywords[$key] = mysql_real_escape_string($value); } //Create the query $titleClause = "Title Like '%" . implode("%'\n OR Title Like '%", $keywords) . "%'"; $artistClause = "Artist Like '%" . implode("%'\n OR Artist Like '%", $keywords) . "%'"; $albumClause = "Album Like '%" . implode("%'\n OR Album Like '%", $keywords) . "%'"; $query = "SELECT * FROM songtable JOIN episodetable ON episodetable.EpisodeID = songtable.EpisodeID WHERE $titleClause OR $artistClause OR $albumClause ORDER BY songtable.EpisodeID, songtable.SongID ASC"; //Store the results in a variable or die if query fails $result = mysql_query($query) or die("The query:<br />$query<br />Produced the error:<br />".mysql_error()); //Check returned results if (mysql_num_rows($result)==0) { //No reults returned echo "<table cellspacing=0 cellpadding=10 width=\"100%\" border=0>"; echo "<tr><td align=center><b>Your query \"$value\" returned no results from the database.</b></td></tr>"; echo "</table>"; } else { echo "<table cellspacing=0 cellpadding=10 width=\"100%\" border=0>"; echo "<tr><td align=center>You searched for <b>" . implode (", ", $keywords) . "</b></td></tr>"; $current_title = ''; while($row = mysql_fetch_array($result)) { //Alternate album row colors $currentcolor = ($currentcolor=='#ffffff' ? '#f2f2f2' : '#ffffff'); if ($current_title != $row['Title']) { //New title $current_title == $row['Title']; echo "<tr><td style=\"text-align:center;background-color:#000000;color:#ffffff;\">\n"; echo "<div id=\"eptable\"><h2>Episode {$row['EpisodeID']}: {$row['EpisodeName']}</h2>\n"; echo "<b>Title:</b> {$row['Title']}</div>\n"; echo "</td></tr>\n"; $currentcolor=='#ffffff'; } //Show the album record $artist = ($record['AA'] == "1")? $record['AAName'] : $row['Artist'] ; echo "<tr><td style=\"background-color:$currentcolor;text-align:left;\">\n"; echo "<b>Artist:</b> {$row['Artist']}<br>\n"; echo "<b>Album:</b> <a href={$row['AlbumLink']}>$artist - {$row['Album']}</a><br>\n"; echo "</td></tr>\n"; } //Close results table echo "</table>\n"; } //Clean up db connection mysql_free_result($result); include 'dbclose.php'; } ?>
  24. Tecnically, no. Images are always rectangles. You could probably "fill" the corners with white (or another color) or make then transparent if you are working with a gif. So, what type of file are you working with?
  25. I'm not sure what the specific problem is, but don't do queries within loops. Do a join instead and get all the data you need with one query: SELECT * FROM order_items JOIN isbn2 WHERE order_items.isbn = isbn2.isbn WHERE order_items.orderid = '$coolid'" Edit: here is at least part of your problem: $tmp .= $testingsamicans.' | '.SSC- $sscpartnumber |'.'; The pipe character (|) after $sscpartnumber is NOT within the single quote marks.
×
×
  • 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.