Jump to content

wattsup88

Members
  • Posts

    45
  • Joined

  • Last visited

    Never

Everything posted by wattsup88

  1. By "work" i mean that this block always returns true and therefore echos the message and exits. I want this block to return false (see code above). if(!$fp) { echo "Error opening file!"; exit; } Also i believe the file is writable but how do i tell... I right-clicked and check and the "read-only" box is not checked if thats what you mean... oh and the folder on my server is writable of course... and yes i know about the $_POST thing i copied and pasted some old code and i havent replaced it... Thanks for bringing that to my attention though Sorry to be so noobish but i have never dealt with this function before... Thanks for the help already and
  2. Hey guys! I cant get the fopen function to work in this block of code... Any idea why? or any alternative ideas... Just trying to create a newsfeed.... <?php //this should all go into one file. I would name it addnews.php if($HTTP_POST_VARS['submit']) { if($HTTP_POST_VARS['password'] == 'pass') { if(!$HTTP_POST_VARS['name']) { echo "You must enter a name"; exit; } if(!$HTTP_POST_VARS['news']) { echo "You must enter some news"; exit; } if(strstr($HTTP_POST_VARS['name'],"|")) { echo "Name cannot contain the pipe symbol - |"; exit; } if(strstr($HTTP_POST_VARS['news'],"|")) { echo "News cannot contain the pipe symbol - |"; exit; } $fp = fopen('news.txt','a'); if(!$fp) { echo "Error opening file!"; exit; } $line = date("m.d.y") . "|" . $HTTP_POST_VARS['name']; $line .= "|" . $HTTP_POST_VARS['news']; $line = str_replace("\r\n","<BR>",$line); $line .= "\r\n"; fwrite($fp, $line); if(!fclose($fp)) { echo "Error closing file!"; exit; } } else { echo "Bad Password"; } } ?>
  3. Hey guys i was just wondering the best way to go about making part of a page a "News Feed". I need it so that someone can log in to a page (i already have done this part), and then type into a text box and upload the content typed to a page. I was thinking of combining html's <form> tag with text box and then using some php to upload that to the homepage. Is this the best way? if there is a simpler one please let me know...
  4. I was just wondering if you can make cool interactive features with PHP? What i mean by that is like drop down interactive menus and cool looking stuff like that...
  5. what downside would there be to including the heading and the rest of the page separate would there be?
  6. i would say that a database is not a "quick fix" so i would go with jwk811's advice on this one...
  7. Thanks for the "little thing here and there" advice... i kept getting an error that i thought was related to that line but really wasn't...
  8. I have actually had some problems with if statements lately also... Unfortunately I can't help you when it comes down to fixing them... I havent even been able to fix my own... I would enjoy the answer to this question also...
  9. what is the correct way of stating this query? [code]SELECT * FROM jobs WHERE (jbcategory = '$value' AND jbstate = '$value1') AND (jbdateexpire > CURRENT_DATE()) ORDER BY $sortby LIMIT $from, $max_results[/code]
  10. Thanks so much guys oh and just so you know taith I won't be using the database I'm creating it for someone else... I of course want it to be user friendly, and I don't always have the knowledge to make it user friendly and practical. So I figured this would be the best way... again thanks for the help...
  11. I have a date that i need to work with, but in my database it is entered like 2006-03-07... i need to know how to "cut" all of the hyphens out of the date returned by the database... that way i can write a script to delete all of the rows with an expired date... Thanks, Jacob
  12. Yeah so i know you all hate me by now, but its STILL not displaying the else part... although just for grins i took the statement and flipped it like: [code] if(the psuedocode posted earlier){ show message }else{ show rows }[/code] and it returned the message whether there were rows being returned or not... and i tried reversing the >0 to <1 and it still would give only the if part if it was true, but no else part if the if statement was false... man thats confusing to me let alone you all... im sorry trying to explain best as i can... oh and i have seen psuedocoding before... how does it work? and if noone wants to elaborate where can i learn about it...
  13. thank you all i was definatly using the wrong query as thorpe pointed out i was using $getlist instead of $getcount... I changed it but it is still giving me nothing...
  14. no i just want php to be able to display it...I dont want that response to come from the database...
  15. oh and still nothing after trying what corbin said... sorry guys... thanks for the help so far...
  16. I apologize for not specifying that... It does not return the first part of the if statement... if there are rows returned then it displays them, but if there are no values it won't return the first if part... does that make sense?
  17. ok fine here is the specific code... <? $sql = "SELECT count(*) AS num FROM jobs WHERE jbcategory = '$value' AND jbstate = '$value1'"; $getcount = mysql_query($sql) or die(mysql_error()); $rows = mysql_num_rows($getlist); if ($rows==0){ echo "<tr><td> <table style=\"border-color:990101\" align=\"left\" border=\"0\" bgcolor=\"#990101\" width=\"800\" height = \"400\" cellpadding=\"20\"> <tr> <td width=\"800\" height=\"10\" bgcolor=\"#990101\" align\"center\"colspan=\"5\"> <em><font  size=\"+5\" color=\"#FFFFFF\" face=\"Arial, Helvetica, sans-serif\"><b>Please broaden your search or view all jobs.</b></font></em> </td></tr>"; }else{ Return query blah blah blah... } ?> oh and Shogun Warrior the problem is specifically posted in my first post and its not "not working"; its "how do you do this" and "here is how im attempting to do it..." id rather post all the code immediately than have people ask for parts of it later when its not posted, & im not at my keyboard to post it
  18. Then why isn't it working... here is the exact code: [code]<?php //calls up the job category selected if ( is_array( $_POST['category'] ) ) { foreach ( $_POST['category'] as $value ) { } } //calls up the state selected if ( is_array( $_POST['stabbrev'] ) ) { foreach ( $_POST['stabbrev'] as $value1 ) { } } $_SESSION['value'] = $value; $_SESSION['value1'] = $value1; //start up alternating rows $color2 = "#CCCCCC"; $color1 = "#AAAAAA"; $row_count = 0; //start up alternating rows //*********pagination variables************ $page = (is_numeric($_GET['page']) && $_GET['page'] > 0) ? $_GET['page'] : 1; $max_results = 5; $from = (($page * $max_results) - $max_results); $allowed = array('jbcategory','jbtitle','jbsalary','jbstate'); $sortby = (in_array($_GET['sortby'],$allowed)) ? $_GET['sortby'] : 'jbtitle'; //Query if ($value=="---Select Job Category---" AND $value1=="---Select State---"){ $sql = "SELECT * FROM jobs ORDER BY $sortby LIMIT $from, $max_results"; }else if ($value=="---Select Job Category---"){ $sql = "SELECT * FROM jobs WHERE jbcategory = '$value' OR jbstate = '$value1' ORDER BY $sortby LIMIT $from, $max_results"; }else if ($value1=="---Select State---"){ $sql = "SELECT * FROM jobs WHERE jbcategory = '$value' OR jbstate = '$value1' ORDER BY $sortby LIMIT $from, $max_results"; }else{ $sql = "SELECT * FROM jobs WHERE jbcategory = '$value' AND jbstate = '$value1' ORDER BY $sortby LIMIT $from, $max_results"; } $getlist = mysql_query($sql) or die(mysql_error()); // Figure out the total number of rows in table if ($value=="---Select Job Category---" AND $value1=="---Select State---"){ $sql = "SELECT count(*) AS num FROM jobs"; }else if ($value=="---Select Job Category---"){ $sql = "SELECT count(*) AS num FROM jobs WHERE jbcategory = '$value' OR jbstate = '$value1'"; }else if ($value1=="---Select State---"){ $sql = "SELECT count(*) AS num FROM jobs WHERE jbcategory = '$value' OR jbstate = '$value1'"; }else{ $sql = "SELECT count(*) AS num FROM jobs WHERE jbcategory = '$value' AND jbstate = '$value1'"; } $getcount = mysql_query($sql) or die(mysql_error()); $total_results = mysql_result($getcount, 0) or die(mysql_error()); // Figure out the total number of pages we will have $total_pages = ceil($total_results / $max_results); // Figure out the current page result numbers $fr = $from + 1; $to = $from + mysql_num_rows($getlist); //**********pagination variables******** //*********Displaying the query*********** $rows = mysql_num_rows($getlist); if ($rows==0){ echo "<tr><td> <table style=\"border-color:990101\" align=\"left\" border=\"0\" bgcolor=\"#990101\" width=\"800\" height = \"400\" cellpadding=\"20\"> <tr> <td width=\"800\" height=\"10\" bgcolor=\"#990101\" align\"center\"colspan=\"5\"> <em><font  size=\"+5\" color=\"#FFFFFF\" face=\"Arial, Helvetica, sans-serif\"><b>Please broaden your search or view all jobs.</b></font></em> </td></tr>"; }else{ echo "<tr><td> <table style=\"border-color:990101\" align=\"left\" border=\"0\" bgcolor=\"#990101\" width=\"800\" cellpadding=\"0\"> <tr> <td width=\"30\" rowspan=\"3\"><img src=\"/Images/strip.gif\" width=\"20\" height=\"400\" align=\"top\"></td> <td width=\"800\" height=\"10\" bgcolor=\"#990101\" colspan=\"5\"> <em><font  size=\"-1\" color=\"#FFFFFF\" face=\"Arial, Helvetica, sans-serif\"><b>Showing $fr to $to of $total_results results</b></font></em> </td></tr>"; print "<tr><td>\n"; print "<table style=\"border-color:990101\" align=\"left\" border=\"0\" bgcolor=\"#990101\" width=\"750\" cellpadding=\"20\">"; while ($row = mysql_fetch_array($getlist))   {         $jbc = $row['jbcategory'];         $jbt = $row['jbtitle'];         $jbs = $row['jbsalary'];         $jbst = $row['jbstate']; $jbid = $row['id']; $row_color = ($row_count % 2) ? $color1 : $color2;     print "<tr>\n"; echo "<td  width=\"240\" height=\"10\" bgcolor=\"$row_color\"><a href=\"viewid.php?id=$jbid\">$jbt</a></td>"; echo " <td height=\"10\" bgcolor=\"$row_color\">$jbc</td>"; echo "<td height=\"10\" bgcolor=\"$row_color\">$jbs</td>"; echo " <td height=\"10\" bgcolor=\"$row_color\">$jbst</td>"; //echo " <td width=\"45\" height=\"10\" bgcolor=\"$row_color\">".stripslashes($jbid)."</td>";   $row_count++;   }     echo "</table>"; //*********Displaying the query***********   //*********pagination links start************    echo "<tr><td bgcolor=\"#990101\" align= \"center\" width =\"800\" colspan=\"5\">";   if($page > 1){     $prev = ($page - 1);     echo "<a href='{$_SERVER['PHP_SELF']}?page=1&sortby=$sortby'>First</a> ";     echo "<a href='{$_SERVER['PHP_SELF']}?page=$prev&sortby=$sortby'>Prev</a> "; } // end if // build the links to the 2 previous and 2 next pages for($i = ($page - 2); $i <= ($page + 2); $i++){   // only make a link if the prev/next is a valid page number   if (($i >= 1) && ($i <= $total_pages)) {     echo ($page == $i) ? "[$i] " : "<a href='{$_SERVER['PHP_SELF']}?page=$i&sortby=$sortby'>$i</a> ";   } // end if } // end for     // Build Next and Last links. If on last page, we won't make a links if($page < $total_pages){     $next = ($page + 1);     echo "<a href='{$_SERVER['PHP_SELF']}?page=$next&sortby=$sortby'>Next</a> ";     echo "<a href='{$_SERVER['PHP_SELF']}?page=$total_pages&sortby=$sortby'>Last</a>"; } // end if echo "</tr></td>"; echo "<tr>     <td height=\"32\" colspan=\"4\"><img src=\"/Images/striphorizontal.gif\" width=\"795\" height=\"30\">     </tr>"; print "</table>\n"; /***** end of pagination ******/ }//end else statement ?>[/code] the database connection is not shown but it is connected of course...
  19. Hello all, I need to know how to return the value "no results found please broaden your search" or something like that when the mysql query comes up empty... Right now Im using something like this... [code] $sql = "SELECT count(*) AS num FROM jobs WHERE jbcategory = '$value' AND jbstate = '$value1'"; $getcount = mysql_query($sql) or die(mysql_error()); $rows = mysql_num_rows($getlist); if ($rows==0){ no results returned blah blah blah... }else{ display results here } [/code] this of course is only the concept... I assume that if the database is returning no results then it cant count rows that aren't returned... so it wont work... but what do i know... anyway i need a method that will return a value if the database doesn't return a row when queried...
  20. oh and by the way the echo $sql & the /* */ is around half of the code b/c i was just working with it... my bad i didn't see it before i posted it i sincerely apologize.... so just omit those and that is the code
  21. Ok i recently completed the expanding on pagination tutorial and it was great ( big thanks to crayon violet ). It worked great when i used on a basic level but when i tried to implement it into one of my search mods it returns "Resource ID #10" for the query... I have tried to search around on the internet (very briefly ) for a page that explains why it is doing that... there were a few sites but i couldn't understand any of them unfortunatley (b/c Im a noob)... here is the code i hope someone can help me understand why and how to fix it... [code]//calls up the job category selected if ( is_array( $_POST['category'] ) ) { foreach ( $_POST['category'] as $value ) { } } //calls up the state selected if ( is_array( $_POST['stabbrev'] ) ) { foreach ( $_POST['stabbrev'] as $value1 ) { } } //start up alternating rows $color2 = "#c8c8c8"; $color1 = "#224477"; $row_count = 0; //start up alternating rows //*********pagination variables************ $page = (is_numeric($_GET['page']) && $_GET['page'] > 0) ? $_GET['page'] : 1; $max_results = 4; $from = (($page * $max_results) - $max_results); $allowed = array('jbcategory','jbtitle','jbsalary','jbstate'); $sortby = (in_array($_GET['sortby'],$allowed)) ? $_GET['sortby'] : 'jbtitle'; //Query and displayed rows if ($value=="---Select Job Category---"){ $sql = mysql_query("SELECT jbtitle,jbcategory,jbsalary,jbstate FROM jobs WHERE jbcategory = '$value' OR jbstate = '$value1' ORDER BY $sortby LIMIT $from, $max_results"); }else if ($value1=="---Select State---"){ $sql = mysql_query("SELECT jbtitle,jbcategory,jbsalary,jbstate FROM jobs WHERE jbcategory = '$value' OR jbstate = '$value1' ORDER BY $sortby LIMIT $from, $max_results"); }else{ $sql = mysql_query("SELECT jbtitle,jbcategory,jbsalary,jbstate FROM jobs WHERE jbcategory = '$value' AND jbstate = '$value1' ORDER BY $sortby LIMIT $from, $max_results"); } echo $sql; /*$getlist = mysql_query($sql) or die(mysql_error()); //$result = mysql_query("SELECT * FROM jobs ORDER BY jbcategory"); // Figure out the total number of rows in table $sql = "select count(*) as num from jobs"; $getcount = mysql_query($sql) or die(mysql_error()); $total_results = mysql_result($getcount, 0) or die(mysql_error()); // Figure out the total number of pages we will have $total_pages = ceil($total_results / $max_results); // Figure out the current page result numbers $fr = $from + 1; $to = $from + mysql_num_rows($getlist); //**********pagination variables******** //*********Displaying the query*********** //pagination echo "<table style=\"border-color:990101\" align=\"center\" border=\"0\" bgcolor=\"#990101\" width=\"800\" cellpadding=\"20\"> <tr><td width=\"800\" height=\"10\" bgcolor=\"#990101\" colspan=\"5\"><em><font  size=\"-1\" color=\"#FFFFFF\" face=\"Arial, Helvetica, sans-serif\"><b>Showing $fr to $to of $total_results results</b></font></em></td></tr>"; while ($row = mysql_fetch_array($getlist))   {         $jbc = $row['jbcategory'];         $jbt = $row['jbtitle'];         $jbs = $row['jbsalary'];         $jbst = $row['jbstate']; $jbid = $row['id']; $row_color = ($row_count % 2) ? $color1 : $color2;     print "<tr>\n"; echo "<td height=\"10\" bgcolor=\"$row_color\">$jbt</td>"; echo " <td height=\"10\" bgcolor=\"$row_color\">$jbc</td>"; echo "<td height=\"10\" bgcolor=\"$row_color\">$jbs</td>"; echo " <td height=\"10\" bgcolor=\"$row_color\">$jbst</td>"; //echo " <td width=\"45\" height=\"10\" bgcolor=\"$row_color\">".stripslashes($jbid)."</td>";   $row_count++;   }     //*********Displaying the query***********   //*********pagination links start************    echo "<tr><td bgcolor=\"#990101\" align= \"center\" width =\"800\" colspan=\"5\">";   if($page > 1){     $prev = ($page - 1);     echo "<a href='{$_SERVER['PHP_SELF']}?page=1&sortby=$sortby'>First</a> ";     echo "<a href='{$_SERVER['PHP_SELF']}?page=$prev&sortby=$sortby'>Prev</a> "; } // end if // build the links to the 2 previous and 2 next pages for($i = ($page - 2); $i <= ($page + 2); $i++){   // only make a link if the prev/next is a valid page number   if (($i >= 1) && ($i <= $total_pages)) {     echo ($page == $i) ? "[$i] " : "<a href='{$_SERVER['PHP_SELF']}?page=$i&sortby=$sortby'>$i</a> ";   } // end if } // end for     // Build Next and Last links. If on last page, we won't make a links if($page < $total_pages){     $next = ($page + 1);     echo "<a href='{$_SERVER['PHP_SELF']}?page=$next&sortby=$sortby'>Next</a> ";     echo "<a href='{$_SERVER['PHP_SELF']}?page=$total_pages&sortby=$sortby'>Last</a>"; } // end if echo "</tr></td>"; print "</table>\n"; /***** end of pagination ******/ [/code] Oh and by the way the job category and the job state are being called up correctly... thanks in advance -Jacob
  22. Well i certainly don't want SQL injection... I took the quotes out and still no result same thing as before... if you would like to see the page it is "http://www.firstpriorityresources.com/tests/get1.php"... im only trying to get the concept down before i implement it on a larger scale so thats why the page is so simple...
  23. great idea man! thanks the only problem is i see that the id number is displayed in the address bar as usual but when i try echoing it, the id doesnt appear (im echoing to test whether the get part works...) here is my code for the first and second pages first page: [code]$result = mysql_query('SELECT `id` FROM `jobs` ORDER BY `id` ASC'); echo '<table>'; //query displayed while ($row = mysql_fetch_array($result)) {   // Display IDs in a table     echo '<tr><td width="200">'.$row['id'].'</td>'; echo '<td width="200"><a href="session2.php?id='.$row['id'].'">View Job</a></td></tr>'; } echo '</table>'; mysql_close( $db ); ?>[/code] second page: [code] <?php $_GET['id'] = preg_replace('|[^0-9]|', '', $_GET['id']); echo '.$_GET['id'].' /* $result = mysql_query('SELECT * FROM `jobs` WHERE `id` = '.$_GET['id'].' LIMIT 1'); $found = mysql_num_rows($result); if ($found) { echo $result } else {   echo "job not found"; } */ ?>[/code] sorry to be such a noob lol... thanks
  24. Using an array would be appropriate here...
  25. Well this is it... The last step to my giant project... I want to thank everyone who has helped me before now... especially the guru's... The last thing I need help with is... Well, let's start at the beginning so you can understand... I am trying to pass a value from a database to another page when it is clicked to queryed again... I hope that makes sense... Here is the code i have so far: [code]$result = mysql_query("SELECT * FROM jobs ORDER BY id"); echo "<table>"; $_SESSION['id'] = array(); //query displayed while ($row = mysql_fetch_array($result)) {     $id = $row['id'];     // Create multi-dimension array to store all ids $_SESSION['id'][] = $id;   // Display IDs in a table     echo "<tr><td width=\"200\">$id</td>"; echo "<td width=\"200\"><a href=\"session2.php\">View Job</a></td></tr>"; } echo "</table>"; mysql_close( $db ); ?>[/code] On the next page, I store all of the ids as variables: [code]<?php $id0 = $_SESSION['id'][0]; $id1 = $_SESSION['id'][1]; $id2 = $_SESSION['id'][2]; $id3 = $_SESSION['id'][3]; $id4 = $_SESSION['id'][4]; $id5 = $_SESSION['id'][5]; $id6 = $_SESSION['id'][6]; $id7 = $_SESSION['id'][7]; $id8 = $_SESSION['id'][8]; $id9 = $_SESSION['id'][9]; echo $id0; session_destroy(); ?>[/code] after using this segment of code i would like to be able to tell which of the session['id'] variables were clicked so i can query something else like this: [code]SELECT * FROM jobs WHERE id = 'one of the session[id's]'[/code] i hope this is do able thanks to all in advance as well as the guru's who have helped in the past -Jacob
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.