SpeedCrazy Posted July 3, 2011 Posted July 3, 2011 I am just trying to learn all i can. Do you know of any good resource to learn about more complex php things like that? I am really enjoying backend construction, a lot more so than front end design. Share this post Link to post Share on other sites More sharing options...
flareback Posted July 3, 2011 Posted July 3, 2011 I have a few websites that I use but they aren't really tutorials. I use w3schools.com as a reference sometimes but my main reference site is php.net. Here is their info on classes. I've always just had an idea of something to build and then tried to figure out how to do it. Share this post Link to post Share on other sites More sharing options...
SpeedCrazy Posted July 3, 2011 Posted July 3, 2011 I've always just had an idea of something to build and then tried to figure out how to do it. Thats me, but i still dont have a good idea of the full scope of php so i dont always try and execute ideas i have. Also i am really good at getting bogged down in attaining perfection on a program. Thanks for the link to php.net looks quite useful. Share this post Link to post Share on other sites More sharing options...
SpeedCrazy Posted July 3, 2011 Posted July 3, 2011 (edited) Another question, i am building a redirect so that if the page the user is requesting doesn't exist they dont get a page full of mysql errors about undefined variables but are redirected to a 404 page. I have this code: $pc = "SELECT cmsPageID FROM cmspage WHERE cmsPageID ='$pageID'"; $pcr = mysql_query($pc, $conn) or die(mysql_error()); while ($pcra = mysql_fetch_assoc($pcr)){ if ($pcra["cmsPageID"] != "$pageID"){ header("Location: dbCMS.php?pageID=404"); extit; }// end if }//end while But i cant get the select statement to use a variable, i have tried every different combination of quotes, double quotes and concatenation(.). And i havent got anywhere. I have seen multiple questions about this online but none of the fixes used seem to work for me. I know this is the problem as when the variable is hard coded it works fine. Any ideas? Oh and thanks for all your help flareback, your assistance has been greatly appreciated. EDIT: Got the SELECT statement to work. but the snippet still does not work. It now reads: $pc = 'SELECT cmsPageID FROM cmspage WHERE cmsPageID="'.$pageID.'"'; $pcr = mysql_query($pc, $conn) or die(mysql_error()); while ($pcra = mysql_fetch_assoc($pcr)){ if ($pcra["cmsPageID"] < 1 ){ header("Location: dbCMS.php?pageID=1"); extit; }// end if }//end while So theoretically if the query returns an empty value it should redirect? or shoul i put == ""? I'll try that. Edited July 3, 2011 by SpeedCrazy Share this post Link to post Share on other sites More sharing options...
SpeedCrazy Posted July 3, 2011 Posted July 3, 2011 Doesn't work. This is frustrating. Probably something stupid I've missed. I am going to work on something else for now. Share this post Link to post Share on other sites More sharing options...
flareback Posted July 4, 2011 Posted July 4, 2011 (edited) Another question, i am building a redirect so that if the page the user is requesting doesn't exist they dont get a page full of mysql errors about undefined variables but are redirected to a 404 page. I have this code: $pc = "SELECT cmsPageID FROM cmspage WHERE cmsPageID ='$pageID'"; $pcr = mysql_query($pc, $conn) or die(mysql_error()); while ($pcra = mysql_fetch_assoc($pcr)){ if ($pcra["cmsPageID"] != "$pageID"){ header("Location: dbCMS.php?pageID=404"); extit; }// end if }//end while But i cant get the select statement to use a variable, i have tried every different combination of quotes, double quotes and concatenation(.). And i havent got anywhere. I have seen multiple questions about this online but none of the fixes used seem to work for me. I know this is the problem as when the variable is hard coded it works fine. Any ideas? Oh and thanks for all your help flareback, your assistance has been greatly appreciated. EDIT: Got the SELECT statement to work. but the snippet still does not work. It now reads: $pc = 'SELECT cmsPageID FROM cmspage WHERE cmsPageID="'.$pageID.'"'; $pcr = mysql_query($pc, $conn) or die(mysql_error()); while ($pcra = mysql_fetch_assoc($pcr)){ if ($pcra["cmsPageID"] < 1 ){ header("Location: dbCMS.php?pageID=1"); extit; }// end if }//end while So theoretically if the query returns an empty value it should redirect? or shoul i put == ""? I'll try that. You spelled exit wrong. I would also check that $pcr is not false before doing the mysql_fetch_assoc(). You might also check out mysql_num_rows. I'm not 100% sure I understand your code since I haven't looked at the db and all very close, but I think the num_rows function might work for you instead of the while loop. Here is what I'm thinking, maybe it helps I don't know $pcr = mysql_query($pc, $conn) or die(mysql_error()); if(!$pcr){ // error code } if(mysql_num_rows($pcr) == 0){ // no rows returned from query } Edited July 4, 2011 by flareback Share this post Link to post Share on other sites More sharing options...
SpeedCrazy Posted July 4, 2011 Posted July 4, 2011 (edited) That would work. I knew it would be some stupid mistake. It might be worth while to instal the spell checker for this studio. EDIT: Yeah i'll use your method, even with the correction it doesn't work properly, but hey thats the point of experimenting, learn new ways to do things. Thanks. EDIT2: Works a charm. Edited July 4, 2011 by SpeedCrazy Share this post Link to post Share on other sites More sharing options...
jjjrmy Posted July 4, 2011 Posted July 4, 2011 You're still using MySQL? Whhhhhhhhhy? PostGres > MySQL Also, use a classThis one: http://www.ricocheting.com/code/php/mysql-database-class-wrapper Share this post Link to post Share on other sites More sharing options...
SpeedCrazy Posted July 4, 2011 Posted July 4, 2011 jjirmy, i am a learner, i aint't gonna jump on a new bandwagon without learning the first one properly. Plus mysql works great, if it aint broke dont fix it. I cant yet use mysql to its full potential so why get something more complicated. Share this post Link to post Share on other sites More sharing options...
SpeedCrazy Posted July 4, 2011 Posted July 4, 2011 This tutorial is driving me nuts, different page from above. It declares an empty array to collect error messages in and when i load the page i get undefined array index errors. How do i get around that? Share this post Link to post Share on other sites More sharing options...
flareback Posted July 4, 2011 Posted July 4, 2011 This tutorial is driving me nuts, different page from above. It declares an empty array to collect error messages in and when i load the page i get undefined array index errors. How do i get around that? The only way to to assign values to it first. Share this post Link to post Share on other sites More sharing options...
SpeedCrazy Posted July 5, 2011 Posted July 5, 2011 Hmm, i just put error_reporting(0); And it works fine. Not i deal, but i am happy. My latest problem, and really none of this overly complicated stuff is in the tutorial, i am working on a spinoff project totally my own, is: i need to draw a php script from a db. How can i do that? I have a login page and i need to draw the whole script or an include to the script out of the database. Is that even possible? Share this post Link to post Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now