[PHP-DB] nested ifs?
Before I delete something from the database, I need to make sure that there is only one entry, and not multiple ones. I can't do this via the database itself, because of the need for multiple entries that bear different names, but the same primary key (which I have since removed). I can't add names as a part of the primary key-- they're used often because someone will order multiple necessities on the same days and with the same order number. Here's the problem since I'm forced into doing this in code, how do I make a nested if that works or is it even possible??? This is the code that I have so far (please note, it is within a function)... any ideas of how I can make it work? $not_del = "SELECT FROM Orders WHERE req like '" . $GLOBALS["old_req"] . "' AND source like '" . $GLOBALS["old_src"] . "' AND number = " . $GLOBALS["old_num"]; $del = "DELETE FROM Orders WHERE req like '" . $GLOBALS["old_req"] . "' AND source like '" . $GLOBALS["old_src"] . "' AND number = " . $GLOBALS["old_num"]; if (mysql_num_rows($not_del) != 1) { $message .= "Multiple entries. Delete NOT allowed."; } elseif (mysql_num_rows($not_del) == 1) { if (mysql_query($del)) { $message .= "Remove OK."; } else { $message .= "Remove NOT."; } } return urlencode($message); Thanks, Liz -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] php/mysql error
This is the error that I've gotten since I switched servers a week-ish ago. No idea why, doesn't make any sense to me. I'm running MySQL 3.23 and the latest versions of Apache and PHP. We used the nusphere install. Warning: Supplied argument is not a valid MySQL result resource in /usr/local/nusphere/apache/htdocs/ese-lab/Protect/add.php3 on line 162 Any ideas??? Thanks!!! Liz Bander This is the function that it's in: #== # sub main() { if ($cancel != '') { include '../Include/conf.inc'; header("Location: http://$WEB_SERV/$WEB_SITE" . "search.php3"); exit; } elseif ($save != '') { include '../Include/conf.inc'; $err_str = validate(); if ($err_str == '') { add_log_entry($bcode); $message = write_to_db($bcode); #$A($message); exit; } else { if (substr($err_str, -1, 1) != '!') { $conflict_code = substr($err_str, -11, 10); $err_str = $err_str . " a href='box_edit.php3?bcode=$conflict_codedb=yesgoto=" . urlencode($goto) . "'--/a"; } } } else { include '../Include/conf.inc'; $cd_qry = "select max(code) from equipment"; connecttodb(); $result = mysql_query($cd_qry); LINE 162$temp = mysql_fetch_row($result); $bcode = $BCODE_START . str_pad((substr($temp[0], -6) + 1),6,'0',STR_PAD_LEFT); } include '../Include/ip_crd_tbl.inc'; include '../Include/show_list.inc'; #==
[PHP-DB] display login info
I want to display a user's full name and user id that would be from their login action. (The login stuff is already set up.) How would I be able to grab the user id from the login? Any ideas on where to look? Thanks, Liz -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] error and general problems
I am getting a parse error for the return line every time I try and view the page. Can anyone tell me why? The code is below. $results = "select req, source, number from orders where req=" . $GLOBALS["req"] . ", source=" . $GLOBALS["source"] . ", number=" .$GLOBALS["req"] . ""; if (mysql_fetch_row($results) != 0) { return "This has already been added."; Also (since this is part of the problem, I'm sure) how do I take the $GLOBALS values and set them equal to the req and source values in the select statement? Is this syntax correct? The $GLOBALS values are pulled earlier from a similar select statement. Thanks, Liz -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] dropdown menu
Okay, maybe this is simple, but I'm at wit's end. I have a drop down menu (code follows) and I want it to show full name (i.e. John Doe) ordered by last name. Works fine under normal circumstances, but then I need it to write the email id associated with the full name to the database. It won't do this. Any ideas??? Code follows. Thanks, Liz ldap table/db: cn= full name, sn= last name, uid= email id orders table/db: req=email id FROM SHOW_LIST.INC, CALLED BY ADD.PHP3 function show_users($users) { $query = "select uid, cn, sn from ldap order by sn ASC"; $db_link = mysql_pconnect('10.10.10.10'); mysql_select_db ('ldap', $db_link); $result = mysql_query ($query); if (($result) (mysql_num_rows($result) 0)) { while ($line = mysql_fetch_row($result)) { $opts[$line[0]] = $line[1]; } } else { $opts[0] = "Error in show_users()"; } show_select($opts, $users); } FROM ADD.PHP3 function write_to_db() { $temp = explode('-', $GLOBALS["submitted"]); $submitted = $temp[2] . '-' . $temp[0] . '-' . $temp[1]; $temp = explode('-', $GLOBALS["week_of"]); $week_of = $temp[2] . '-' . $temp[0] . '-' . $temp[1]; $ins = "INSERT INTO orders (req, source, number, project, submitted, amount, status, week_of) VALUES ('" . $GLOBALS["req"] . "', '" . $GLOBALS["source"] . "', '" . $GLOBALS["number"] . "', '" . $GLOBALS["project"] . "', '$submitted', '" . $GLOBALS["amount"] . "', '" . $GLOBALS["status"] . "', '$week_of')"; $message = ''; $db_link = mysql_pconnect('10.10.10.10'); mysql_select_db ('Order_Status', $db_link); $audit_message = "Created order number: " . $GLOBALS["source"] . $GLOBALS["number"]; #$audit_sql = "INSERT INTO audittrail (reqnum, date, text) VALUES (" . $GLOBALS["req"] . ", '" . date('Y-m-d H:i:s') . "', '$audit_message')"; if (mysql_query($ins)) { $message .= "ADDED " . $GLOBALS["source"] . $GLOBALS["number"] . " . "; #mysql_select_db ('op_requests', $db_link); #if (mysql_query($audit_sql)) { # $message .= "AUDIT OK."; #} else { # $message .= "AUDIT NOT."; #} } else { $message .= "ADD NOT. $ins"; } return urlencode($message); } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] mail function
I need to make an email link in a table. The username is displayed as text; I need it to be a link through which I can send email. Is this possible in php? The following is the code for that I'm using: function show_logged_users($user) { $query = "select distinct uid, cn from log left join ldap.ldap on log.user like ldap.ldap.uid order by ldap.ldap.sn"; connect(); $result = mysql_query($query); if (($result) (mysql_num_rows($result) 0)) { while ($line = mysql_fetch_row($result)) { $opts[$line[0]] = $line[1]; } } else { $opts[0] = "Error in show_logged_users()"; } show_select($opts, $user); } td font face="Arial, Helvetica, sans-serif" size="-1" color="#FF"bUser/b/font /td td select name="user" ? show_logged_users($user) ? /select /td What I need is the ? show_logged_users($user) ? statement to turn itself into a mailto: statement to that clicking on the user name will bring up an email addressed to username @domain.com Is this possible? Is there any code out there that I can get a look at? Thanks, Liz -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] sorting and links
OK, I'm sure that the answers are extremely simple, but I'm having two problems. 1. How do I sort a list through PHP alphabetically? This is a drop-down menu full of part numbers and it's a pain in the neck to search for the right one through about a thousand of them. Currently, the sort (or lack thereof) is based on a primary key code (which other aspects of the database are based on), and sorts it based on the number. This is not user-friendly, and an alphabetical sort would make it much more so (this is very important). 2. There is a button that deletes a row from a table in my database. What I need is for the button to delete the row and then return the user to the previous page. Can it do both of these things? This again, is part of the necessity for a user-friendly environment. Any ideas or places to look for more info would be great. I have several reference books, but they're not much help if you don't know exactly what you're looking for. This is MySQL version 3.23.29a-gamma and PHP 4.0.4 with Apache 1.3 on a Win2K Pro machine. Thanks, Liz -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] php to mysql probs.
I'm using PHP (v4.0.4) as a web front end for a MySQL (v3.23.29) database running on Windows 2000 machine. The problem is that I am relatively new (I've been messing with this for only a month) to this and don't really know where to look for information on the connection problems-- the web will not update the database, but only for one field. However, all the other fields are being updated as one would expect. The field in question is a drop down menu with at least a thousand items that are collected from one table in the database and then (are supposed to, if it would work) used to update another table-- could this be the problem? Is this a Windows problem (rebooting has solved every issue but this one so far)? Is there anything that I should look for specifically (note: I did not write the code that I'm using; I'm merely editing it for use)? Also, are there any good books out there written about using MySQL and PHP together? Most of the PHP books that I've seen online have had rather poor reviews by readers. Thanks, Liz Bander. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]