ManiacDan
Staff Alumni-
Posts
2,604 -
Joined
-
Last visited
-
Days Won
10
Everything posted by ManiacDan
-
So all I have to do to break into your site is to delete my session cookie and change the userID cookie to someone else's user ID?
-
Well there really aren't many comments to make about it. The layout works fine in Chrome. The text is too small in many places for high resolution monitors. Otherwise, that's all there is. There's no actual functionality to critique. There's a page. The words stay inside the boxes. Nothing crashes when I click the button to change the words inside the boxes.
-
If you're letting the user select expiration, why is this even a question? Do you just want to know what value to make the default in the dropdown? Sessions almost always expire when the browser window is closed. If you don't do that, you have session files hanging around on your filesystem on your server forever. The way amazon, facebook, and PHPFreaks do it is by having another set of cookies which will automatically log you back in and re-populate the session with certain chosen bits of data. The session itself dies when I close the window though. If their session expires, it's gone, so you don't know if it's expired or if this is their first time on your site. Just kick them to a login page.
-
There is so much wrong with this code. I'll try to point out everything I can see. <b> This tag is never closed, that's why the whole page is bold. First number Second number Use tables or CSS to position your labels properly, don't just space them out. They'll only look ok on your monitor. <input name="numberone" type="number"> "Number" is not a valid type for inputs. You want "text" here. <input type="submit" name="operator" value="+ addition"> <input type="submit" name="operator" value="- subtraction"> <input type="submit" name="operatoe" value="* multiplication"> <input type="submit" name="operator" value="/ division"> One of these input names is not like the others. Also, the values should not be the labels, there are multiple ways to change the text displayed on the button while still submitting basic "+", "-", "/", and "*" as the value. $_POST['addition'] = $numberone + $numbertwo; Don't ever store values in $_POST. $_POST is for raw, user-submitted content and that's all. if ($_POST['operator'][0]) echo $_POST['addition']; What makes you believe $_POST['operator'] will be an array? You never made it an array. This whole structure should be switch ( $_POST['operator'] ). The switch statement is useful.
-
Xyph's solution is the right one. The answer to your direct question is the explode() and implode() pair of functions. However, redesigning your database now will save you lots of trouble in the future. Your data model is wrong.
-
The manual page for imagecopyresampled() has an example of how to resize an image to a standard size.
-
With 130+ posts, you should really know by now to do the following things: 1) Wrap your code in [ php ] and [/ php ] tags so it is properly displayed. We even have a button for it now. Highlight your code and click the "PHP" button in the toolbar. 2) Use error reporting and error handling, as well as the mysql_error() function to figure out errors on your own. Experts like thorpe don't just stare at non-functional code hoping they notice the error. The fact that thorpe was able to do so in this case doesn't mean that's how we normally debug something. Echo your own error, figure out what it means. 3) Form better questions. Or, in the case of this thread, form a sentence. You did nothing but paste a large block of unformatted code to a group of strangers. 4) Google the answers you receive. Thorpe's answer was perfect. If you don't know what a mysql identifier is, find out. If you had written a question, perhaps the answer you received would have been more complete.
-
Interesting. I bet OP got his answer elsewhere.
-
$pages = 10; $currentPage = 3; for ( $p = 1; $p <= $pages; $p++ ) { if ( $p == $currentPage ) { echo " <b>{$currentPage}</b> "; } else { echo " <a href='whateverPage.php?page={$p}'>{$p}</a> "; } }
-
A Tuple is usually a datatype that consists of two pieces of data. Sometimes called a "pair", especially by the popular C++ libraries.
-
Keep $oldGroupName in a variable. Check it with every iteration of the loop.
-
Make a new variable called $total. $total += $pts; You could also make an array for $total, so it can hold the points for each team.
-
Image upload and resize creating a black image
ManiacDan replied to andrew_biggart's topic in PHP Coding Help
have you also tried imagecopyresized? -
You could use the group_concat function. You could also simply order by the group ID, and only print it when it changes.
-
You're still not making sense. Tuple doesn't mean what you think it means.
-
Show multiple images but not selectoptions
ManiacDan replied to Joepiooo1988's topic in PHP Coding Help
Did you not read what I said? I'm not going to delete the * and type out merk_name for you. -
Is it ok to put an insert statement inside a foreach?
ManiacDan replied to bugzy's topic in PHP Coding Help
You can form one big INSERT query with multiple values and insert it in one block. that's more efficient: <?php $query = "Insert INTO item(item_code, item_description, item_price, item_stock, item_sale, item_reg) VALUES('{$item_code}','{$item_description}','{$item_price}','{$item_stock}', '{$item_sale}', NOW())"; $last_id = mysql_insert_id(); $query1 = "Insert into item_category (category_id, item_id) VALUES "; foreach($_POST['item_cat'] as $cat_get_ins) { $query1 .= "('{$cat_get_ins}','{$last_id}'),"; } $result1 = mysql_query(trim($query1, ','),$connection); ?> mysql_insert_id is the perfect function for this situation, yes. -
I told you already, but I'll try to explain again: Regular expressions are their own language entirely. They are not PHP, SQL, or anything else you're familiar with. Inside regular expressions you can have parts of the expression wrapped in parentheses. Those parentheses, when used in preg_match, are used as "capture groups." Capture groups are put into the matches array as their own entries in the $matches array.
-
The browser won't care? If I have a space in my URL...it shouldn't work.
-
Did you read the TWO posts now about other things you can try? Specifically, the one above yours that talks about how you don't seem to have read or understood the posts you've been given.
-
Ignace, those URLs wouldn't work anyway since the HTML would be invalid. bbmak, preg_match_all puts an array of matches into the third argument, in this case it's $matches. $matches[0] is an array of the matches for the full pattern, then $matches[1] through $matches[9] are arrays of the sub-pattern matches, the items inside parentheses inside the expression. When you use a string like $location as an array, it becomes an array of characters, which is why you were getting the individual letters of the string as results. Regular expressions as well as array access are both really complex problems, so this is a very very basic answer.
-
This is...pretty much the entire purpose of PHP. The direct answer to "how do I do this" is "use PHP." You don't need a templating language or anything, just take the query xyph gave you and start dumping the data out to the screen, performing more queries as necessary.
-
Show multiple images but not selectoptions
ManiacDan replied to Joepiooo1988's topic in PHP Coding Help
Only select the columns you need. If you're only displaying merk_name, then only select merk_name from the table. Then your DISTINCT will work. Also, this is not the right way to set up your database, look into normalization and third normal form. Your "merk"s should be their own table, with each row linking back to them. That way, you could have done a select * from merk to get your dropdown. -
Ignace's expression is correct as long as all the URLs are "double quoted" and none are 'single quoted' or unquoted at all. This should get all of them: if (preg_match_all('!(href|src)=[\'"]?([^\'"\s]+)[\'"\s>]!', $string, $matches)) { foreach ($matches[2] as $location) { //use $location } }
-
Database login not working on new host server
ManiacDan replied to AlohaSD's topic in PHP Coding Help
And when you added debug output, what happened? We can't just look at this and figure out what error message is being thrown by mysql. Make use of mysql_error to figure out why that query is failing. Also, unrelated to the current problem, but you have no security whatsoever. There's no hashing on your password table and there's not even basic sql injection protection.