Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. echo $statusCount['status 2'];
  2. This will create an array with the keys as the status description and the values as the count $statusCount = array(); while($row = mysql_fetch_assoc($result)) { //Code to display the record $status = $row['status']; //Add to the status count if(!isset($statusCount[$status])) { $statusCount[$status] = 1; } else { $statusCount[$status]++; } }
  3. Psycho

    Password

    <a href="somepage.php" target="_blank">Set Password</a>
  4. Here are my comments: 1. give your variables descriptive names. $b tells me nothing about what the value is supposed to be. Also, for $b, I would just define the base url and not the opening A tag. Then the resulting echo at the bottom would look proper. 2. The variable $count serves no purpose in that code. 3. It looks like you are querying all the records and then using PHP and stripos() to filter the results. You should just use the query to return only the records you want. <?PHP $connect = odbc_connect('museum9', '', ''); if (!$connect) {exit("Connection *** Failed: " . $connect);} $sql = "SELECT ID, Title, Author, CAT FROM BooksQuery WHERE Title LIKE '{$search}%' OR Author LIKE '{$search}%'"; $rs=odbc_exec($connect,$sql); if (!$rs) {exit("Error *** in SQL");} $baseURL = "bookdets.php"; while (odbc_fetch_row($rs)) { $id = odbc_result($rs,"ID"); $Title = odbc_result($rs,"Title"); $Author = odbc_result($rs,"Author"); $cat = rtrim(odbc_result($rs,"CAT")); echo "<tr>\n"; echo "<td>{$Title}</td>"; echo "<td>{$Author}</td>"; echo "<td><a href=\"{$b}?{$id}\">{$cat}</a></td>"; echo "</tr>"; } odbc_close($connect); ?>
  5. Do NOT do queries within loops. It creates a huge overhead on the server. You can process multiple inserts in a single query in the format INSERT INTO table (fieldA, fieldB, fieldC) VALUES ('val-1A', 'val-1B', 'val-1C'), ('val-2A', 'val-2B', 'val-2C'), ('val-3A', 'val-3B', 'val-3C') For your purposes: $count1 = count($large_images); //Create array of value statements $values = array(); for($i=0; $i<$count1; $i++) { $values[] = "('{$large_images[$i]}', '{$small_images[$i]}', '{$when_up}', '{$by_who}')"; } //Create single query to perform all inserts $query = "INSERT INTO images (image, thumb, when_up, who) VALUES " . implode(', ', $values); mysql_query($query);
  6. A field for date added would be better than using the ID, but with what you have: //First four $query = "SELECT * FROM videos ORDER BY ID ASC LIMIT 4"; //Last four $query = "SELECT * FROM videos ORDER BY ID DESC LIMIT 4"; Of course the last four will be in reverse order. If you need them in ascending order I think this will do it //Last four in ascending order $query = "SELECT * FROM (SELECT * FROM videos ORDER BY ID DESC LIMIT 4) ORDER BY ID ASC";
  7. I'd suggest using CSS to print only selected text on a page instead of making the functionality dependant upon javascript. There have been several posts on these forums on the subject which I have posted solutions for.
  8. From the manual, i.e. php.net In the documentation for the mssql functions: Requirements (http://us2.php.net/manual/en/mssql.requirements.php) Installation (http://us2.php.net/manual/en/mssql.installation.php)
  9. Well, of course it isn't working. If you walk through the process it is obvious what is happening. [And please use [ CODE ] tags when posting] So, when submit is not set (i.e. when the user first acess the page) the employee id IS set. But, when the user submits the form, it IS NOT set. if (!isset($_REQUEST['submit'])) { echo "IF-BROemail=". $email."<br>"; generatingForm(); } else { echo "ELSE-BROemail=". $email."<br>"; processingForm($email); } You apparently have different links to initally access this page that use the "?employee=1" parameter. So, when the user first accesses the page that value is set. But, when the user first accesses the page you are only displaying the form to the user. THEN, when the user submits the page the form posts to just "email.php" without the employee paramter. <form action=email.php method=post> So, when you process the form to actually send the email you do not have the employee id parameter! Since I had no idea how you were using this I couldn't anticipate this problem, but if you had read my earlier responses you should have identified it yourself So, you have some different options: 1. You could use the code I posted which is much cleaner than what you have anyway. I assumed that the page would post to itself, so in my code I left the action parameter of the form empty. By doing that, the form will post to the same URL (including the employee parameter). If you had even tried the code I posted, I'm betting it would have worked. So, I don't know why I even bother. 2. You could follow the previous advise I gave you and use teh employee parameter on initial form load to populate a hidden field on the form. Then use that when you process the form to determine the email.
  10. You should put the files in a folder that is not accessible through the web, i.e. not in the web root. You can then build a PHP front-end interface to allow a user to authenticate and request the files. PHP can then "read" the documents from the server-side and serve them to the user. Example: | |-Web Root | | | |-images | |-css | |-html files | |-php scripts | |-Secured documents
  11. Your query is only extracting one field from the database: sd.user_id. If you want other data returned you need to modify your query to get it.
  12. Just an FYI, I posted a question in the Guru forum (which you can't see) asking why this would not be a bug. Apparently the issue is that when in_array() and array_search() compare a string and an int, the string is converted to an int. If the string starts with a number, then it will have a numerical value. Otherwise, it is treated as a zero. Those functions do have a "strict" parameter to prevent this. However, that would also cause '3' != 3
  13. You don't need regular expressions for that! Just use if (fieldValue == 'select') { //error condition } else { //value is valid } However, I would suggest just making the default select value an empty string rather than the string 'select'
  14. I didn't read through your code, but the solution is simple. UPDATE table SET coins = coins + $amount WHERE username='$username'
  15. Well, although you have experience with C, I'm not sure what database experience you have. Learning how to properly set up and use a database is a different activity than learning PHP. Not only that, but to develop a fully working web application will involve several disciplines: PHP, database, HTML, CSS, and probably JavaScript - if not others. You have to at least have a working knowledge of some to build upon others. The first area to learn would be HTML. Without that the PHP knowledge is kind of worthless if you want to build a web app. CSS & JavaScript would be good to learn after that but could be done later. After you have a working knowledge of HTML, then I would move on to PHP only tutorials to get acquainted. Then, I would suggest moving on to PHP using a database.
  16. It seems this issue has already been reported as a bug (http://bugs.php.net/bug.php?id=30473), but I think the author did a poor job of explaining it as the issue was determined not to be a bug.
  17. I think you have uncovered a bug with the array_search() function! It seems that array_search() will return the key of the first values that matches the $needle OR the numerical value of 0. Here is the result of some testing I did: $array = array(0 => 'a', 1 => '0', 2 => 'b', 3 => '1', 4 => 'c'); echo array_search('c', $array); //Returns 4, correct //Change the string '0' to the number 0, for index 1 $array = array(0 => 'a', 1 => 0, 2 => 'b', 3 => '1', 4 => 'c'); echo array_search('c', $array); //Returns 1, incorrect
  18. Here is a complete rewrite of your code in a more logical fasion. I made the TO email addresses a select list in the form. If you don't want the user to choose, then make it a hidden field and decide how you will populate it. <?php // Create an array of valid emails $emails = array ( "1" => "employee1@test.com", "2" => "employee2@test.com", "3" => "employee3@test.com" ); //Create select list options for To email address $emailOptions = ''; foreach($emails as $id => $email) { $selected = ($email==$_POST['employee']) ? ' selected="selected"': ''; $emailOptions .= "<option value=\"{$id}\">{$email}</option>\n"; } //Process the form submission if (isset($_POST['employee'])) { //Define To email address $e_id = trim($_POST['employee']); //get URL parameter employee $mssg_toEmail = (isset($emails[$e_id])) ? $emails[$e_id] : $emails[1]; //Prepare the submitted data $fName = trim($_POST['fName']); $fEmail = trim($_POST['fEmail']); $fCompany = trim($_POST['fCompany']); $fPhone = trim($_POST['fPhone']); $fMessage = trim($_POST['fMessage']); //Validate data $errors = array(); if(empty($fName)) { $errors[] = "Name is required"; } if(empty($fEmail)) { $errors[] = "Email is required"; } if(count($errors)>0) { $error_msg = "The following errors occured:"; $error_msg .= "<ul>"; $error_msg .= "<li>" . implode("</li>\n<li>", $errors) . "</li>\n"; $error_msg .= "<ul><br />\n"; } else { //No errors, construct emails $mssg_subject = "Web Contact Form"; $mssg_body = "We have received the following information:\n\n"; $mssg_body .= "Name: $fName\n"; $mssg_body .= "Email: $fEmail\n"; $mssg_body .= "Company: $fCompany\n"; $mssg_body .= "Phone: $fPhone\n"; $mssg_body .= "Message: $fMessage\n"; $mssg_headers = "From: $fName"; $reply_toEmail = $fEmail; $reply_subject = "Thank you for contacting us"; $reply_body = "Thank you for contacting us. Somebody will get back to you as soon as possible, usually within 48 hours."; $reply_headers = "From: webmaster@test.com"; //Send the email $mssg = mail($mssg_toEmail, $mssg_subject, $mssg_body, $mssg_headers); //Check if email sent OK if(!$mssg) { $error_msg = "There was a problem sending yur message. Please try again.<br />\n"; } else { mail($reply_toEmail, $reply_subject, $reply_body, $reply_headers); header( "Location: http://www.mywebsite.com"); exit(); } } } ?> <html> <head> <title>Contact Web Form</title> </head> <body> <form action="" method="post"> <table bgcolor="#ffffcc" align="center"> <tr> <td colspan="2"><?php echo $error_msg; ?></td> </tr> <tr> <td colspan="2"><strong>Please contact us using this form:</strong></td> </tr> <tr> <td>Send to:</td> <td><select name="employee"><?php echo $emailOptions; ?></select></td> </tr> <tr> <td><font color="red">*</font>Your Name:</td> <td><input type="text" size="25" name="fName" value="<?php echo $fName; ?>" /></td> </tr> <tr> <td><font color="red">*</font>Your Email:</td> <td><input type="text" size="25" name="fEmail" value="<?php echo $fEmail; ?>" /></td> </tr> <tr> <td>Your Company:</td> <td><input type="text" size="25" name="fCompany" value="<?php echo $fCompany; ?>" /></td> </tr> <tr> <td>Your Phone:</td> <td><input type="text" size="25" name="fPhone" value="<?php echo $fPhone; ?>" /></td> </tr> <tr> <td colspan="2">Message:</td> </tr> <tr> <td colspan="2" align="center"><textarea name="fMessage" rows="15" cols="35"><?php echo $fMessage; ?></textarea></td> </tr> <tr> <td colspan="2" align="center"><small>A <font color="red">*</font> indicates a field is required</small></td> </tr> <tr> <td colspan=""2><input type="submit" name="submit" value="Send Mail"></td> </tr> </table> </form> </body> </html>
  19. I already did advise you on what you need to do - add some code to debug the problem. YOU should know what the values of all the variables should be at each step. Just echo them to the page to validate. I don't see in your page how you are passing the employee id in the URL.The form action is simply "email.php". If you want to give the user the option to choose who to send the email to then put a select list. Otherwise, use a hidden field and determine how you will populate it.
  20. Never, ever use user submitted data (POST, GET, COOKIE, etc.) in your code without validating it. I assume the email addresses of employee1, employee2, etc. were just for illustrative puposes and that they do not necessarily directly correspond to the email username. Which would break the method proposed by mikesta707. And, even if they did, you should still validate the email address. I would go with using an array as you posted. However, I would take a slightly different approach. $BROemployee = array ( "1" => array("Aemail" => "employee1@test.com"), "2" => array("Aemail" => "employee2@test.com"), "3" => array("Aemail" => "employee3@test.com"), ); $employee = $_GET['employee']; //get URL parameter employee if (isset($BROemployee[$employee]['Aemail'])) { //define variable $email $email $BROemployee[$employee]['Aemail']; } else { //Use a default email address or trigger error condition } After a cursory look at your code, however, I don't see any reason why it would not work. If it is not working you should put in some code for debugging purposes. 1) Echo out the value of $employee. Does it contain the number you expect? If so, check the value of $email that you define from the array. If not, do a print_r($_GET) to see all the values passed on the query string.
  21. You have your True/False backwards. That regex tests to see if there are any characters NOT in the list specified. Since you don't want those characters you should be returning false. Adding a space in the character list works fine for me. Also, assuming you want to allow capital letters you need to add A-Z, or better yet, just make the regex case insensitive using the "i" parameter. Lastly, no need to create an If/Else to return True/False since the preg_match will do that for you: function alphaNumTextCheck($string) { return (!preg_match('/[^a-z0-9 ]/i', $string)); } alphaNumTextCheck('word'); //Returns true alphaNumTextCheck('word123'); //Returns true alphaNumTextCheck(' word 123 '); //Returns true alphaNumTextCheck('word#123'); //Returns false alphaNumTextCheck('word:123'); //Returns false
  22. @bulrush You shouldn't comment on something that you don't understand. MS Access is a proprietary database and front end rolled into a single application. It is more like FileMaker than a true database that can be repurposed for many outputs. And, using backquotes around database table/field names is absolutely valid and would be the "most" proper method since it prevents table/field name conflicts with reserved words. @sharp.mac You shouldn't use * in your queries unless you need every field. List out the fields you need to make the queries more efficient. And, you should never do "looping" queries. I.e. do one query and then use the results to run several more queries. Do some searching to find a tutorial or two on using JOINS and get all the information you need in one query. Doing many queries like this is a huge overhead on the server. However, because you are listing the connect ids as a comma separated value you have really destroyed the value of using a database. You should really create another table (say 'connections') with two fields origin_id and connect_id. If you had that you would just need one query to get all the data you need: SELECT origin.name as origin, destination.name as destination FROM cities as origin JOIN connections ON cities.id = connections.origin_id JOIN cities as destination ON connections.destination_id = destination.id ORDER BY origin, destination That is how it should be done. However, with your current implementation you could see some improvement by doing a single query on the comma separated list (using "IN") instead of querying for each item in the list. Here is an improved version of your original code: <?php //Run query to get list of origin cities and connection IDs $query = "SELECT name as origin, connects FROM `cities`" $cities = mysql_query($query); $jscript = ''; while ($cityRow = mysql_fetch_array($cities)) { //Run query to get connection cities $query = "SELECT `name` as connection FROM `cities` WHERE `id` IN ({$cityRow['connects']})"; $connections = mysql_query($query); $jscript .= "if (chosen == '{$cityRow['origin']}') {\n"; while($connectRow = mysql_fetch_array($connections)) { $connection = $connectRow['connection']; $jscript .= "selbox.options[selbox.options.length] = new Option('{$connection}','{$connection}');\n"; } $jscript .= "}\n\n"; }; mysql_free_result($cities); echo $jscript; ?> Note: I would also suggest creating javascript arrays to store the data and have your function utilize those arrays instead of having to write out all the "new Option" lines.
  23. $q = mysql_query("SELECT * FROM `people` WHERE `type`=1"); $products = array(); while($r = mysql_fetch_array($q)) { $products[] = $r['product']; }
  24. I think your query is messed up. The select list is to select the season (named 'users'), but you use the post value 'q' as the ID from the rankings table. I suspect the ID is a unique identifier for each team? Can't be sure without knowing your database structure, but I think you should be using the season value something like this: $season_id = mysql_real_escape_string($_POST['users']); $sql="SELECT * FROM rankings WHERE season_id = '{$season_id}'"; Also, you should fix the opening TR tag for your headings.
  25. Here is your code modified to have the logic all at the top of the page and only output data to the browser if it should. There may be some typos as I have not tested this. <?php session_start(); // User chooses group to edit parts/features/spec tips/to order in. require_once('navmenu.php'); require_once('connectvars.php'); require_once('constants.php'); // Connect to the database $dbc = mysqli_connect($host, $user, $password, $database); $errcnt=0; if (isset($_POST['cmdEdit'])) //Try to save items first. { $error_msg = ''; //First get GID based on cbxGroupname. $s=$_POST['cbxGroupname']; $arr=explode('#',$s); $gname=$arr[0]; //Group name $basemodel=$arr[1]; $query="SELECT grid, groupname FROM hgroup WHERE groupname='{$gname}' AND basemodel='{$basemodel}';"; $result=mysqli_query($dbc, $query); if (!$result) { $error_msg = mysql_error().'<br/>'.$query; } else if (mysqli_num_rows($result)>1) { $error_msg = "ERROR: There was more than one group selected. Cannot save data.<br/>{$query}"; } else { $row = mysqli_fetch_array($result); $grid=trim($row['grid']); //Group id. Stored on other tables also. $_SESSION['grid']=$grid; $home='http://'.$SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/editpart.php'; header('Location: '.$home); exit(); } } //if isset($_POST['submit'] $error_msg2 = ''; $query = "SELECT grid, groupname, basemodel FROM hgroup ORDER BY groupname;"; $result = mysqli_query($dbc,$query); if (!$result) { $error_msg2 = mysql_error().'<br/>'.$query; } elseif (mysqli_num_rows($result)<1) { $error_msg2 = "ERROR: No groups selected: {$query}"; } else { //Create combo box options showing all group names. $options = ''; $selected = ' selected="selected"'; while ($row = mysqli_fetch_array($result)) { $value = $row['groupname'].'#'.$row['basemodel']; $options .= "<option value=\"{$value}\"{$selected}>{$value}</option>\n"; $selected = ''; } } mysqli_close($dbc); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Edit Part Search Screen</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <p class="error"><?php echo $error_msg; ?></p> <h2>Proto3: Product/Part Edit Search v.10b</h2> <p>This screen is used to search for existing groups, and their associated products, to edit. <!--------------------------------------------------------> <form action="<?php echo $_SERVER['PHP_SELF'].'?'.SID; ?>" method="post"> <hr/> <label for="cbxGroupname">Group name</label> <select name="cbxGroupname"> <?php echo $options; ?> </select> <p class="error"><?php echo $error_msg2; ?></p> <p>Commands: <input type="submit" name="cmdEdit" value="Edit"></p> </form> </body> </html>
×
×
  • 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.