DavidAM
Staff Alumni-
Posts
1,984 -
Joined
-
Days Won
10
Everything posted by DavidAM
-
If you copy-paste that query into mysqladmin or the mysql command-line, does it succeed? Report any errors? If you skip the first 12 entries, so the first insert is for #13, does it fail or does it work for 12 entries and fail at a different spot? How is that column defined? Could it be that the value is too long for the field? I think mysql would truncate it rather than discard it. What patterns do you see in the data that fails? Do they all have single-quotes, long lengths, ??? ? I really cannot think of a reason why mysql would discard a single column value from an insert with multiple columns. Have you tried rebuilding the table? What process are you using to check for the data? Could it be the view process that is failing? or have you checked the database directly.
-
Single Or Multiple User Login On One Page?
DavidAM replied to justlukeyou's topic in PHP Coding Help
You have 3 "databases" or you have 3 "tables"? which is it? Why are you using separate databases/tables for different user types? Unless there is a compelling business reason, "Type" should be an attribute of the User. It would be stored in the one and only Users table. The application should then make decisions based on the Type of the user. -
Write a single loop, and use the index for all three arrays. Collect each row in a separate variable, and output all three when you get to the split. Something like this: $one = array('title1','title2','title3','title4','title5','title6'); $two = array('image1','image2','image3','image4','image5','image6'); $three = array('text1','text','text3','text4','text5','text6'); $numFiles = count($one); $start = 0; $end = $numFiles; $split = 3; print "<table>"; $titles = $images = $texts = ''; for($i = $start; $i < $end; $i++) { $titles .= "<td>".$one[$i]."</td>"; $images .= "<td>".$two[$i]."</td>"; $texts .= "<td>".$three[$i]."</td>"; if(($i % $split) == $split-1){ print "<tr>" . $titles . "</tr><tr>" . $images . "</tr><tr>" . $text . "</tr>" $titles = $images = $texts = ''; } } // Just in case the count is not a multiple of the split if (! empty($titles)) { print "<tr>" . $titles . "</tr><tr>" . $images . "</tr><tr>" . $text . "</tr>" } print"</table>";
-
If you are not escaping the data, that example is going to fail. The single-quotes in the data are being treated as quotes in the query and causing it to fail. There will be no PHP error, but there should be an error from the database. If you are using mySql, you need to have a look at mysql_error and mysql_real_escape_string Since you have not posted any code, we cannot do any more than guess. If you are not using mySql, then you need to look at the API for the database you are using.
-
If job() is a function in the current scope, just execute it without the eval().
-
Turn on error reporting. That query will fail if there is more than one post in the forum. When using a subquery for an equals ("=") condition, the subquery must not return more than one row. You would have to use "IN" instead of "=" with the subquery approach. But, as Barand said, you should be using a JOIN instead.
-
Please Friends, I Have Problem That Have Been Bordering
DavidAM replied to stutego's topic in PHP Coding Help
Either define $warnings at the beginning of the script: $warnings = array() or use empty instead of count- 25 replies
-
- php coding problem
- form problem
- (and 2 more)
-
Please Friends, I Have Problem That Have Been Bordering
DavidAM replied to stutego's topic in PHP Coding Help
It is true that the language cannot know that $margin = $cost / $sales; is the wrong formula (a logic error). However, PHP issues a NOTICE or WARNING when I do some things wrong: $margn = $cst / $sales;. Oops! I spelled two of those variable names wrong. PHP will execute the statement, and issue a NOTICE, and set the value of $margn to null. Later on when I print $margin; I will get another NOTICE and PHP will print an empty value. If I ignore all these notices (or hide them), I can say my script "runs" or even "works", but it is NOT producing the correct results. By the way, in any compiled language, these notices (in my example) would be fatal compile-time errors, and you would not get an executable. The undefined index errors (from this thread) would not be, but would likely cause the program to crash when it runs.- 25 replies
-
- php coding problem
- form problem
- (and 2 more)
-
What exactly are you trying to do with that query? Your previous post called it "list number of already filtered products", but that phrase does not seem to fit the query. The way I read it, that query is returning the filter data and a count of products that have filters 77, 76, 16, AND 11. Dependent Subqueries are harsh on performance, and when you nest them like that, it compounds the problem. By the way, the LEFT JOIN is negated by the use of pf.idProduct in the WHERE clause. That WHERE clause will only be TRUE for rows that successfully JOIN so the extra filters (that don't match the JOIN condition) will not be returned.
-
Please Friends, I Have Problem That Have Been Bordering
DavidAM replied to stutego's topic in PHP Coding Help
Notices are logic errors. They may not be syntax errors; the script may continue to run; but the fact is that it is not able to do exactly what you told it to do. You can choose to ignore them but then, you can choose to not look both ways before crossing the street, too. At some point, there will likely be a problem. OP: Look at the error messages and look at your code. The message says all those errors are on line 8. My guess is this code at the beginning of your script: $required=array("fname" => "Firstname", "lname" => "Lastname", "email" => "Email address", "password" => "Password"); foreach ($required as $field => $label) { if (!$_post[$field]) { $warnings[$field] = "Required"; } } that IF statement is checking each of those elements in the POST array. You need to check to see if they are set. They will not be set when the page is first requested (before it is submitted). Try if (isset($_POST[$field])). But, TEXT fields will always be set when submitted even if the user left them blank. So you can check for empty, except if the user just types spaces. I usually wrap all of the validation code in an IF that checks for the SUBMIT element, but you have not given your SUBMIT element a name. You could wrap it in a check of the request method: if ($_SERVER['REQUEST_METOD'] == 'POST') { $required=array("fname" => "Firstname", "lname" => "Lastname", "email" => "Email address", "password" => "Password"); foreach ($required as $field => $label) { if (isset($_POST[$field])) { $check = trim($_POST[$field]); if (empty($check) $warnings[$field] = "Required"; } } }- 25 replies
-
- php coding problem
- form problem
- (and 2 more)
-
@Psycho: Correct me if I'm wrong, but won't PHP automatically do the url decode (on GET parameters)? Also, don't you then need to rawurlencode the individual path components in the IMG tag? I say individual components because if you encode the entire path string, the DIRECTORY_SEPARATORs will be encoded and the url will not be what it is.
-
You should try using single-quotes. Parameters are "expanded" inside double-quotes but not inside single-quotes -- Similar to PHP string quoting and variables.
-
If you need to use user input in a regular expression, you should run it through preg_quote first. That will escape any special characters so the user expression is searched as a literal string. $string = 'I want to be a PHP geek!'; if (preg_match('/'. preg_quote($_GET['no'], '/') . '/i', $string)) //do something This should get rid of the compilation error when the user's input contains unbalanced parenthesis
-
Call your lawyer. That's the only way you will get a definitive answer. Gotta love Texas. It's a right-to-work state, which works both ways. So I can fire you because I don't like brown eyes. Oops, I misread trq's response. I thought he was saying you could be prosecuted for not warning them first. Even in Texas, if the person being called a "retard" is aware of it and offended by it, the employer could be liable for allowing a "hostile work environment". Here, I would write up a disciplinary action form and then sit down with them and explain the issue. Tell them if I hear of it once more, they are out. Have them sign the form and put it in their file. Then, the next time it happened, ... bye-bye. Of course, you need to be sure that the person reporting the incident is not just trying to get the guy fired. Is this person referring to someone as stupid, or referring to someone who is mentally handicapped? It would make a difference to me. Being a jerk (calling someone stupid) is one thing; discrimination is quite another thing altogether. Depending on how reliable the information is, I'm not sure I would give the person another chance (in the later case), particularly if it is widely known that the company supports the mentally handicapped by providing employment. I would also circulate a (new) company policy memo about hostility in the work place. Make everyone sign it, including all future employees. Then you already have the warning in writing the next time the issue arises. Which is probably how 90% of all company policies come about. Disclaimer: I don't actually dislike brown eyes. I am actually indifferent to eye color (usually). It is just an example. So please, don't flame me about your beautiful brown eyes.
-
Multi-Table Query Returning Duplicate Results
DavidAM replied to nodirtyrockstar's topic in MySQL Help
Without a JOIN, that query will return a Cartesian product. Every row in "products" will be matched with every row in "merch". You need to specify how the tables are related: SELECT products.id, merch.id FROM products JOIN merch ON products.preferred_merchant_id = merch.id Of course the columns I used in the above query are just examples, the actual JOIN condition would depend on the structure of your tables. -
You should use LIKE if you need LIKE. I was just showing the structure to use when you need an AND along with an OR. Since AND and OR have the same precedence, they are evaluated from left to right (or top to bottom). If you have: "Condition1 AND Condition2 OR Condition3" it evaluates differently than having: "Condition2 OR Condition3 AND Condition1". So you use the parenthesis to make sure the conditions are evaluated the way you want: "Condition1 AND (Condition2 OR Condition3)" (which is also evaluated differently from either of the other two).
-
You need to group the OR part together (if that is what you want) WHERE user = 'username' AND ( phone = 'phone' OR name = 'name' ) This requires the user to match and either the phone or name to match.
-
I've never worked with sockets (directly) and don't have much experience with Java, but I'll take a swing at this. $reply = socket_read($sock, 10000, PHP_BINARY_READ) //Reading the reply from socket or die("error: failed to read from socket\n"); You are asking for 10,000 bytes. Are you sure the image file is not more than that? socket_read returns false on error (which you have covered) or an empty string if there is nothing to read. Check the strlen of the returned value $reply and the file.length() of the image you are reading in Java. They should be the same value. The header in your original post says "PNG" while the Java code is reading a "JPG". Was this more testing? The Content-Type needs to be correct. That error would indicate that the browser is not getting valid image data. Either it is missing some data, or the data is wrong. Could this be a big-indian, little-indian issue? Did you turn on error reporting when you tested the script directly? If you request the script in the browser, without the header call, you should see the image data. Make sure error reporting is turned on and try with and without the header. Are you certain there is no white-space or a UTF-8 BOM before the first opening tag? i.e. does the error reporting give a "Headers already sent" message?
-
You have the 'Content-Type' header call commented out. The PHP script will have to output headers appropriate for the image, so the browser will recognize it. If you tried to browse to the communication_socket.php script, how would the browser know it was supposed to be an image? Are you sure you did that correctly? What does the View Source of your browser show when you browse to that script?
-
Leave the last assignment out: if ($Terms == "Disagree") { $msg_error['Terms'] = "You Must agree with the terms to submit the application"; }elseif ($Terms == ""){ $msg_error['Terms'] = "You Must agree with the terms to submit the application"; }elseif ($Terms == "Agree"){ } Or better yet, rewrite it: if ($Terms != "Agree") { $msg_error['Terms'] = "You Must agree with the terms to submit the application"; }
-
I did not go through all of the code, but $msg_error is never going to be empty because of this statement: if ($Terms == "Disagree") { $msg_error['Terms'] = "You Must agree with the terms to submit the application"; }elseif ($Terms == ""){ $msg_error['Terms'] = "You Must agree with the terms to submit the application"; }elseif ($Terms == "Agree"){ $msg_error['Terms'] = ""; } Since it is not empty, it never writes to the database. Since the contents will, with perfect data, be a single element ("Terms") containing an empty string, there will be no "error" message printed on the form.
-
Converting Cahracters To Hexadecimal Equivalent
DavidAM replied to s4surbhi2218's topic in PHP Coding Help
sprintf -
Amend Php Script To Comply With Hosts New Security Settings
DavidAM replied to MacGuyUK's topic in PHP Coding Help
You should also change this to your server's email address: $headers = "From: $email\r\n"; You can add a Reply-To header so you can reply to the visitor $headers = "From: $SendEmail\r\n"; $headers = "Reply-To: $email\r\n"; $headers .= "Cc: $email\r\n"; -
Actually, you can suggest a filename using a header: header('Content-Disposition: attachment; filename="suggestFilename.ext"'); I say suggest, because the user can always change it in the "Save As" dialog box.
-
To expand on PFMaBiSmAd's answer: I would recommend not using it at all. If you really feel the need to use it, use the EXTR_PREFIX_ALL flag. This way you don't overwrite any existing variables, and the prefix can make it obvious where the variable came from: $row = mysql_fetch_assoc($res); extract($row, EXTR_PREFIX_ALL, 'DB_'); echo 'UserID: ' . DB_id;