-
Posts
2,965 -
Joined
-
Last visited
Everything posted by mikesta707
-
if (condition) echo "<a href=\"somelink.php\">link text</a>"; else echo "link text"; without more info and the code you currently have, I can't give a more definitive answer than this
-
yes I understand, but if your script doesn't know $gid, then it won't work. try echoing $gid at the top of the page and make sure its defined. I don't see anything else wrong with the script (aside from some possible security errors)
-
well you don't seem to include the page where you are defining $gid in the script you posted above. unless you left that part out. to debug, try echoing the values of some of your variables, and see if they have what you think they have. for example, use print_r on your $crow variable print_r($crow); to verify that you are actually selecting something
-
i dont see where you define $gid. Does that page cause any errors?
-
Yeah I was wrong, you don't need to specify length. Well I tried your query in my phpmyadmin console, and got the same error. There seems to be 2 problems. One, when you create an auto increment column, it must be defined as a key also (like primary key, unique key, etc.) However, this isn't whats causing your error. It has something to do with the mediumint data type. When I try this CREATE TABLE products ( id INT(10) NOT NULL AUTO_INCREMENT, product_name VARCHAR(225), product_category VARCHAR(225), price DECIMAL (4,2) ) I get a different error (the one pertaining to a primary key) when I use this CREATE TABLE products ( id INT(10) NOT NULL AUTO_INCREMENT primary key, product_name VARCHAR(225), product_category VARCHAR(225), price DECIMAL (4,2) ) it works. I'm not sure why, but for some reason, using MEDIUMINT doesn't work. I don't see why you are using medium int anyways. it will save a little bit of space because mediumint has a smaller range (so the storage space in memory will be smaller) but INTs are usually used for primary id keys in my experience
-
Your probably getting that error because there was a syntax error in your SQL. I believe that for mediumint data types, you have to specify the length (remember what I said in my post earlier?) so perhaps your creation code should look like $q=$db->query("CREATE TABLE products ( id MEDUIMINT(10) NOT NULL AUTO_INCREMENT, product_name VARCHAR(225), product_category VARCHAR(225), price DECIMAL (4,2) )"); If thats not it, then im not entirely sure, as my SQL is a little rusty. EDIT: um.. if your trying to copy paste that PHP code into the SQL console it wont work. PHP is NOT SQL. try just copying the query part into your SQL console
-
sorry, didn't even realize you posted before I did. that reply certainly wasn't there before I posted. Must have missed the "replys were made while you were posting" error while posting. No need to be so touchy, an honest mistake of course, not to mention double posts are common on most help forums
-
Alternatively, you could also use output buffering. Be aware, as Chemical said, there is a flaw in your CMS design. This should really be looked at as a bandaid and not a permanent fix. Check out the page for information on what output buffering is, and how it works. Without knowing how your website is formatted, My best guess as to where to use output buffering would simply be to put it at the top of your main including page (if you use dynamic includes) or at the top of every page that needs it (if you use static links) ob_start();//starts output buffering ... blah blah blah blah... //All output, like the following echo "hello"; //will not be output to the page, but instead be stored in an internal buffer //after we do all our stuff, we want to output everything and clear the buffer ob_end_flush();
-
one thing that sticks out to me is your creation code if(isset($create)) { $q=$db->query("CREATE TABLE products ( auto_increment INT, product_name VARCHAR(225), product_category VARCHAR(225), price DECIMAL (4,2) )"); if ($q) print('<br/>Products Table was Created'); } you never gave your auto_increment field a name (or specify the length of the INT field. Perhaps you should check PHPMYADMIN to verify the table is created, and then look at your auto_increment field. If all else fails, try dropping the table, and change your creation code to have a name for that column. Something like if(isset($create)) { $q=$db->query("CREATE TABLE products ( id auto_increment INT(10), product_name VARCHAR(225), product_category VARCHAR(225), price DECIMAL (4,2) )"); if ($q) print('<br/>Products Table was Created'); } should do. After you change the creation code, try creating the table again with the code, and then try inserting data into the table.
-
How would I do this to make a simple calculator?
mikesta707 replied to foobarbaz's topic in PHP Coding Help
implementing a stack may not be a bad idea, and would definitely make the coding easier if you are unable to use eval. A quick google search for PHP stack retrieved: http://www.phpclasses.org/browse/file/2710.html note: I don't have any experience with that class, so I can not recommend it fully. A more complete search would probably be necessary if you don't plan on implementing it your self. If you do plan to implement it, I don't imagine you would need a very robust stack, more of a array wrapper class that acts "stack-like". Also, a stack class is nice to have around. You could make a nice one, and use it in a lot of places. Unfortunately, there is no STL equivalent for PHP (though it has no templates, so I guess the T would be kind of weird) which would have some standardized data structures and algorithms, but this is life I suppose. Good luck on your project. after you make a stack, you could then turn the equation to a postfix (or is it prefix?) and evaluate it. -
missing a semi colon on this line $totalpages = ceil($numrows / $rowsperpage) should be $totalpages = ceil($numrows / $rowsperpage); just a tip, when you have parse errors and you just cant see whats wrong with the line it specifies, look to the line(s) above
-
How to change related video sort method from categories to tags
mikesta707 replied to Bledwings's topic in PHP Coding Help
well you seem to be doing the query here query_posts('showposts=10&orderby=rand&cat=... etc I'm not personally familiar with word press, but it seems that all you need to change is the orderby variable in the query string query_posts('showposts=10&orderby=tags&cat=.. etc note the changes. Again this is just a guess, as I don't know your column names (so you may need to change the tags part of the orderby=tags in the string to whatever column holds your tags). I also don't have much experience with wordpress, so I might also be off entirely -
it is indeed possible to create tables on the fly, However, I really have to ask why? how exactly is it "not working"? Is it are you getting an error? is the MYSQL failing (and thus showing the die() text, which is "go ahead ahmed" or something like that) If its the latter, change your die text with mysql_error() so you can see exactly whats going on
-
If you are asking if PHP can delete the history information that a browser collects? then no. Perhaps you should rethink your strategy for security
-
aside from the horrible formatting, everything looks fine. Can you show an example of the form maybe, or an example of some text that would be there?
-
you just want numbers in front of the usernames that are output by the query? in that case the fix is very simple you just need a counter variable, and increment it (add 1 to it) every pass of the loop. so instead of while ($top2 = mysql_fetch_array($tsel2)) { print "<tr><td height='20'><a href=$GAME_SELF?p=view&view=$top2[username]>$top2[username]</a></td></tr>"; } you could put $counter = 1;//out counter variable while ($top2 = mysql_fetch_array($tsel2)) { print "#$i <tr><td height='20'><a href=$GAME_SELF?p=view&view=$top2[username]>$top2[username]</a></td></tr>";//note the change I made after the first " $counter++;//increment the counter }
-
in order to get a good answer, you really need to describe the problems you are having. You have stated what you are "trying" to do, and assuming something is going wrong, you never indicate what exactly is happening. A quick look at your code showed this: $tsel2 = mysql_query("SELECT * FROM `user_info` order by `races` desc limit 10"); $tsel2 = mysql_query("SELECT * FROM `users` where `userlevel`='0'"); assuming that the first query is doing what you want (which is to get the top 10 users by races) you are overwriting the original query result with a new one (the select * where userlevel=0 one). Now tsel2 has the query results where the userlevel is 0. perhaps you mean these two variables to be separate $tsel2 = mysql_query("SELECT * FROM `user_info` order by `races` desc limit 10"); $tsel3 = mysql_query("SELECT * FROM `users` where `userlevel`='0'");//note there are two variables now // they are $tsel2, defined 3 lines above, AND $tsel3 defined 1 line above to really fix your problem though, we need way more information. For example, what is happening? blank page? are there errors? if so, what are the exact error messages? If you have a blank page, there may still be errors, but they may not be reported if error reporting is off. to turn it on put error_reporting(E_ALL); ini_set("display_errors", 1); at the very top of your page
-
for such a simple login, yes thats almost all you really need. You also want to unset() all you $_SESSION variables. for example unset($_SESSION['ID']; you can add that for all your variables, and it will pretty much erase the value from memory to prevent the variables from still being on the system. see session_destroy() for more information. the page pretty much has a description of why what I said is needed at the top of the page.
-
(New to PHP) Getting values from an array in another document
mikesta707 replied to alecsloman's topic in PHP Coding Help
actually I kind of jumped the gun when I mentioned constants. Only scalar (like ints, floats, strings, etc.) can be made into costants. There are some workarounds, like storing the serialized string of the array into a constant, but honestly, I wouldn't bother, as its not that big of a deal -
I CANT UNDERSTAND Y THIS IS NOT WORKING CAN ANY1 HELP? PLZ
mikesta707 replied to mattm1712's topic in PHP Coding Help
A little advice when asking questions: You need to clearly state the problem. Saying "OMG SOMETHINGS WRONG" won't get your question answered. You need to think about whats happening, and actual say what's going wrong. What is actually happening, and how is that different from what you expect to/want to happen? Were there any errors? Was the page completely blank? Do you have error reporting turned on? if not adding error_reporting(E_ALL); ini_set("display_errors", 1); to the top of your script will turn it on. also, put code in code tags -
(New to PHP) Getting values from an array in another document
mikesta707 replied to alecsloman's topic in PHP Coding Help
web, he's talking about how to use one file's variables in another file if I'm not mistaken. use include, but you may want to consider making the array a constant if the values never (or rarely) change. include("menus.php"); print_r($menu); -
Totally took a while to type this out, so im posting it anyways, but if your topic is solved, you can click the topic solved button at the bottom of the thread There needs to be a little more clarification i'm afraid. Now under what circumstances is the user returning to the form. Are they clicking a link? page redirect (via header or javascript/html redirect) can you send any post data? Or is the user simply told to click the back button, or navigate the to the form on their own? If you give the user a link or redirect some how, you can put some $_GET data right into the url. For example, a link back may look like Oops! There was a problem with your form! Please click <a href="form.php?dobyear=1990">here</a> to view the form obviously, for a redirect, just append the redirect url with whatever get data you want .Also note that in my example, I chose dobyear is my get data name, so I will have to refer to it in PHP as $_GET['dobyear']. If you use a different name, like dob_year, or birthyear, or something, make sure you change your script accordingly Now, in that case, we are basically sending some $_GET data through the url instead of through a form. Actually, when you use a form use's method is get, all it does is simply append the form data to the url in this fashion : page.php?form1=username&form2=password&submit=submit Now, using your select script you can do something like <select name="dob_year"> <?php $upper = intval(strftime('%Y')); $lower = $upper - 150; for($i = $upper; $i > $lower; $i--) { //choose the selected //using the ternary operator $select = (isset($_GET['dobyear'])) ? $_GET['dobyear'] : NULL; /*the ternary statement was equivalent to if (isset($_GET['dobyear'])){ $select = $_GET['dobyear']; } else { $select = NULL; } */ ?> <option value="<?php echo $i ?>" <?php if($select && $select == $i ) echo 'selected="selected"' ?>><?php echo $i ?></option> <?php } ?> </select> now if we want some default thing selected, thats pretty easy too, we can just add a simple if statement after the form loop <select name="dob_year"> <?php $upper = intval(strftime('%Y')); $lower = $upper - 150; for($i = $upper; $i > $lower; $i--) { //choose the selected //using the ternary operator $select = (isset($_GET['dobyear'])) ? $_GET['dobyear'] : NULL; ?> <option value="<?php echo $i ?>" <?php if($select && $select == $i ) echo 'selected="selected"' ?>><?php echo $i ?></option> <?php } //if no get data set, then we want to make the default on selected, otherwise, just make it unselected //again with ternary echo ($select) ? '<option value="0" >Year</option>' : '<option value="0" selected="selected">Year</option>'; ?> </select> now if you aren't, or can't send data, you can also use cookies. Cookies may be the better option, because it will work whether or not you send a link now, to set cookies, use setcookie() (the link above) Remember, like other headers, you must set cookies before any script output. Now the way we could use cookies here would be to set the cookies when the script starts, like //lets save the birth year $birth_cookie = $_POST['dob_year']; //set the cookie setcookie("dobyear", $birth_cookie); //setcookie(name of cookie, value of cookie, date it expires) //i left the last parameter out (date it expires) so it will expire when the //user closes the page, or ends the current session somehow. //now if we wanted to make it an hour from now, we use time() // and add 1 hour (in seconds) to time, like so setcookie("dobyear", $birth_cookie, time() + 60*60); ..do other stuff if (form was a success){ //do mysql stuff //now we can delete the cookies, because we dont need them any more //to delete cookies, we basically set the death time to somewhere in the past //there is some debate on the best way to do it, but using 1 as the expiration time //seems to be the best. 1 represents the time 1 second after midnight on the unix epoch (which was during 1970) setcookie("dobyear", '', 1);//i leave out the value, because it doesn't matter //this is optional by the way. The cookie will expire on its own, depending on what //you put the the date it expires parameter } else { //there were errors //do whatever error handling and stop } now, we can use the cookie like we used the get variable. But instead of using $_GET['dobyear'], replace all occurrences of it with $_COOKIE['dobyear']
-
Anyone fix this error :S not sure why its appearing :S?
mikesta707 replied to soupy127's topic in PHP Coding Help
very strange. I just tried your code, with slight modification, and it works perfectly on my wamp server. my code <?php if ($_POST['post']) { print_r($_POST); //get data $title = $_POST['title']; $body = $_POST['body']; //Check for existance if ($title&&$body) { //insert data } else echo "Please fill out Title and Body <p>"; } ?> <form method='POST'> Title:<br> <input type='text' name='title'><p> Body:<br> <textarea rows='6' cols='35' name='body'></textarea><p> <input type='submit' name='post' value='Post this news'> </form> can you post your whole script? The error happens on line 69, and if what you posted is your whole script, then line 69 doesn't exist. also comment where line 69 is please -
since magic quotes is no longer supported, I suppose you could just get rid of the if statement. something like function clean($var){ return mysql_real_escape_string(trim($var)); } should suffice. However, it may be a good idea to keep the if statement so your code is more portable. If you use that code on a server with php 4 or 5 (and magic quotes gpc is enabled) then it may not work as suspected.
-
the function is strtolower()