Jump to content

Perad

Members
  • Posts

    287
  • Joined

  • Last visited

    Never

Everything posted by Perad

  1. I'm new to php... whats a templating engine? As for the problem itself I rewrote my form and changed my php function to get it working.
  2. I have a dropdown box where the options are called directly from the database. I need this line at the top of the form. [code]<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">[/code] I have come up with this... [code] function add_article () { echo "<form action=\"<?php echo \$_SERVER['PHP_SELF']; ?>\" method=\"post\">"; echo "<select name=\"category\">"; $query = "SELECT category_id, category_name FROM article_category ORDER BY category_id"; $result = mysql_query ($query) or die("Problem with the query: $query on line:" . __LINE__ . "<br>" . mysql_error()); while ($row = mysql_fetch_assoc ($result)) {[/code] The form works, but doesn't loop back to the original page. Does anyone know a way around this?
  3. bah, thanks a lot, i was editing this directly from a news comment system... i missed that edit.
  4. Yeah sorry i put $scoreid as a global variable just trying anything to make it work. Score ID is defined like so. [code]echo "<tr><td><a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&scoreid={$row['scoreid']}\">See Detailed Report</a>" . "</td></tr>";[/code] I might as well post the full script. Its a bit messy  :-\ [code]<?php function viewmatchreports() { /* user config variables */ $max_items = 5; /* max number of news items to show */ /* make database connection */ $db = mysql_connect ('localhost','root','admin'); mysql_select_db ('UNC',$db); function displayNews($all = 0) {     /* bring in two variables     * $db is our database connection     * $max_items is the maximum number     * of news items we want to display */     global $db, $max_items;         /* query for news items */     if ($all == 0) {         /* this query is for up to $max_items */         $query = "SELECT scoreid, postdate, opponenttag, matchdatedd, matchdatemm, matchdateyyyy, outcome FROM matchreports ORDER BY postdate DESC LIMIT 5";     } else {         /* this query will get all news */         $query = "SELECT scoreid, postdate, opponenttag, matchdatedd, matchdatemm, matchdateyyyy, outcome FROM matchreports ORDER BY postdate DESC";     }     $result = mysql_query ($query) or die("Problem with the query: $query on line:" . __LINE__ . "<br>" . mysql_error());     while ($row = mysql_fetch_assoc ($result)) {   /* display news in a simple table */         echo "<TABLE border=\"1\" width=\"580\">\n";         /* place table row data in         * easier to use variables.         * Here we also make sure no         * HTML tags, other than the         * ones we want are displayed */         $ot = htmlentities ($row['opponenttag']); $mdd = ($row['matchdatedd']); $mmm = ($row['matchdatemm']); $myyyy = ($row['matchdateyyyy']); $outcome = ($row['outcome']);                      /* display the data */         echo "<tr><td>UNC vs " . $ot . " - " . $mdd . "/" . $mmm . "/" . $myyyy . "&nbsp;&nbsp;&nbsp;&nbsp;Outcome: " . $outcome . "</td></tr>";            echo "<tr><td><a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&scoreid={$row['scoreid']}\">See Detailed Report</a>" . "</td></tr>";                 /* finish up table*/         echo "</TABLE>\n";         echo "<BR>\n";     }         /* if we aren't displaying all news,     * then give a link to do so */     if ($all == 0) {         echo "<a href=\"{$_SERVER['PHP_SELF']}" .             "?action=all\">View all matches</a>\n";     } } function displayOneItem($scoreid) {     global $db;         /* query for item */     $query = "SELECT * FROM matchreports WHERE scoreid=$scoreid";     $result = mysql_query ($query);     /* if we get no results back, error out */     if (mysql_num_rows ($result) == 0) {         echo "Bad news id\n";         return;     }     $row = mysql_fetch_assoc($result);     echo "<TABLE border=\"1\" width=\"580\">\n";     /* easier to read variables and     * striping out tags */ $o = ($row['opponent']); $l = ($row['ladder']); $si = ($row['server']); $ot = htmlentities ($row['opponenttag']); $uncsecondmap = (($row['uncscore2']) - ($row['uncscore1'])); $oppsecondmap = (($row['oppscore2']) - ($row['oppscore1'])); $mdd = ($row['matchdatedd']); $mmm = ($row['matchdatemm']); $myyyy = ($row['matchdateyyyy']); $outcome = ($row['outcome']);     $report = nl2br (strip_tags ($row['report'], '<a><b><i><u>'));         /* display the items */     echo "<tr><td colspan=\"2\">United Nations Clan &nbsp; vs &nbsp; " . $o . "&nbsp;&nbsp;-" . $mdd . "/" . $mmm . "/" . $myyyy. "</td></tr>\n";     echo "<tr><td colspan=\"2\">" . $l . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $si . "</td></tr> \n"; echo "<tr><td width=\"200\" height=\"200\">Insert Map Photo</td><td> UNC Score: " . $row['uncscore1'] . "&nbsp;&nbsp;" . $ot . ": " . $row['oppscore1'] . "</td></tr>\n"; echo "<tr><td width=\"200\" height=\"200\">Insert Map Photo</td><td> UNC Score: " . $uncsecondmap . "&nbsp;&nbsp;" . $ot . ": " . $oppsecondmap . "</td></tr>\n"; echo "<tr><td>Total Score</td><td> UNC Score: " . $row['uncscore2'] . "&nbsp;&nbsp;" . $ot . " Score: " . $row['oppscore2'] . "</td></tr>\n";     echo "<tr><td colspan=\"2\">" . $report . "</td></tr>";     echo "</TABLE>\n";     echo "<BR>\n";         /* now show the comments */ } /* this is where the script decides what do do */ echo "<CENTER>\n"; switch($_GET['action']) {         case 'show':         displayOneItem($_GET['id']);         break;     case 'all':         displayNews(1);         break;     default:         displayNews(); } echo "</CENTER>\n"; } ?>[/code]
  5. OK... i just don't get this. Here is the problem bit of code. [code]function displayOneItem($scoreid) {     global $db, $scoreid;         /* query for item */     $query = "SELECT * FROM matchreports WHERE scoreid=$scoreid";     $result = mysql_query ($query);     /* if we get no results back, error out */     if (mysql_num_rows ($result) == 0) {         echo "Bad news id\n";         return;     }     $row = mysql_fetch_assoc($result);     echo "<TABLE border=\"1\" width=\"580\">\n";[/code] Now... this leads me to the following URL. http://localhost/matchreports.php?action=show&scoreid=9 This comes up with the following error [code]Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\webs\test\viewmatchreports.php on line 65 Bad news id[/code] Yet if i change [code]$query = "SELECT * FROM matchreports WHERE scoreid=$scoreid";[/code] to [code]$query = "SELECT * FROM matchreports WHERE scoreid=9";[/code] It comes up with the same URL as above but works! Whats going on? Could someone help me solve this problem. As you can see $scoreid generates the correct number but is still making an error.
  6. I have this code to check to see if information is entered into the form... [code] if (empty($_POST['oppscore1'])) { $os1 = FALSE; $message .= '<p>You forgot to enter the Opponents Score ht!</p>'; } else { $os1 = $_POST['oppscore1']; }[/code] Unfortunately when i enter "0" into the form field for Score, it gets rejected because it thinks 0(Zero) isn't a number/value. Could someone help me correct this please. Perad
  7. First i am newish to php so am mainly looking for some reassurance. I have a massive form where the user needs to enter 19 values for a match report. I will then have 2 pages pulling data off the database. The first page will show about 5 fields, the second will show them all. The website that i am making it for will start with low traffic then steadily rise. Is 19 values into 1 table going to be ok? Or should i try to separate the values?
  8. I know you can use value. But value doesn't show up on firefox. It also removes itself when the user selects the input box. I want to call data from the database and display it in an input box so a user can edit and change it. Does anyone know how i can do this?
  9. EDIT: Solved, the line above missed the $ on query. Thanks for the help mate ;)
  10. My script works in that it posts news onto my website. The problem is that when the news has been posted the script says that an error has taken place instead of posting that it was completed successfully. Could someone help me work out why? [code]<?php # Script 6.6 - addnews.php // Set the page title and include the HTML header. $page_title = 'Add News'; if (isset($_POST['submit'])) { // Handle the form. $message = NULL; // Create an empty new variable. // Check for a first name. if (empty($_POST['title'])) { $t = FALSE; $message .= '<p>You forgot to enter the title!</p>'; } else { $t = $_POST['title']; } // Check for a last name. if (empty($_POST['content'])) { $c = FALSE; $message .= '<p>You forgot to enter the content!</p>'; } else { $c = $_POST['content']; } if ($t && $c) { // If everything's OK. require_once ('../alink.php');// Connect to the db. // Make the query. $query = "INSERT INTO news(id, postdate, title, newstext) VALUES( '', NOW(), '$t', '$c')";   mysql_query($query); if ($result) { // If it ran OK. // Confirmation. echo '<p><b>The news article has been added successfully!</b></p>'; exit(); // Quit the script. } else { // If it did not run OK. $message = '<p>The news couldn\'t be added. If the problem persists please e-mail the administrator.</p><p>' . mysql_error() . '</p>'; } mysql_close(); // Close the database connection. } else { $message .= '<p>Please try again.</p>'; } } // End of the main Submit conditional. // Print the message if there is one. if (isset($message)) { echo '<font color="red">', $message, '</font>'; } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <fieldset><legend>Warning! You are posting news which will appear on the front page of the website!</legend> <p>Please check and double check everything you type before posting. Thanks</p>     <p>Title:<input type="text" width="30" name="title" value="title"></p>     <TEXTAREA cols="40" rows="5" name="content" value="content"></TEXTAREA><br />     <input type="submit" name="submit" value="submit" /> </fieldset></FORM>[/code]
  11. This error has got me baffled... I have spent a good 2 hours staring at this code and i just can't see what is wrong. The complete error message is [quote]Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /homepages/30/d148891800/htdocs/UNC/viewcomments.php on line 30[/quote] The error appears on the first page, the first page displays 5 news items. This makes it sound like a problem connecting to the database... however, if you click on the all news link below the error you can view the news article. You can check it out for yourself at www.jasonstanley(dot)co.uk/unc/index.php Its linked to my page by a function [code] <?php if( $userdata['session_logged_in'] ) { viewnews(); } else { viewnews(); } ?>[/code] [code]<?php function viewnews() { /* user config variables */ $max_items = 5; /* max number of news items to show */ /* make database connection */ $db = mysql_connect ('meh','blah','wohoo'); mysql_select_db ('test',$db); function displayNews($all = 0) {     /* bring in two variables     * $db is our database connection     * $max_items is the maximum number     * of news items we want to display */     global $db, $max_items;         /* query for news items */     if ($all == 0) {         /* this query is for up to $max_items */         $query = "SELECT id,title,newstext," .                 "DATE_FORMAT(postdate, '%Y-%m-%d') as date " .                 "FROM news ORDER BY postdate DESC LIMIT $max_items";     } else {         /* this query will get all news */         $query = "SELECT id,title,newstext," .                 "DATE_FORMAT(postdate, '%Y-%m-%d') as date " .                 "FROM news ORDER BY postdate DESC";     }     $result = mysql_query ($query);     while ($row = mysql_fetch_assoc ($result)) {         /* display news in a simple table */         echo "<TABLE border=\"1\" width=\"300\">\n";         /* place table row data in         * easier to use variables.         * Here we also make sure no         * HTML tags, other than the         * ones we want are displayed */         $date = $row['date'];                $title = htmlentities ($row['title']);         $news = nl2br (strip_tags ($row['newstext'], '<a><b><i><u>'));                 /* display the data */         echo "<TR><TD><b>$title</b> posted on $date</TD></TR>\n";         echo "<TR><TD>$news</TD></TR>\n";                 /* get number of comments */         $comment_query = "SELECT count(*) FROM news_comments " .                         "WHERE news_id={$row['id']}";         $comment_result = mysql_query ($comment_query);         $comment_row = mysql_fetch_row($comment_result);                 /* display number of comments with link */         echo "<TR><TD><a href=\"{$_SERVER['PHP_SELF']}" .             "?action=show&id={$row['id']}\">Comments</a>" .             "($comment_row[0]}</TD></TR>\n";                 /* finish up table*/         echo "</TABLE>\n";         echo "<BR>\n";     }         /* if we aren't displaying all news,     * then give a link to do so */     if ($all == 0) {         echo "<a href=\"{$_SERVER['PHP_SELF']}" .             "?action=all\">View all news</a>\n";     } } function displayOneItem($id) {     global $db;         /* query for item */     $query = "SELECT * FROM news WHERE id=$id";     $result = mysql_query ($query);         /* if we get no results back, error out */     if (mysql_num_rows ($result) == 0) {         echo "Bad news id\n";         return;     }     $row = mysql_fetch_assoc($result);     echo "<TABLE border=\"1\" width=\"300\">\n";     /* easier to read variables and     * striping out tags */     $title = htmlentities ($row['title']);     $news = nl2br (strip_tags ($row['newstext'], '<a><b><i><u>'));         /* display the items */     echo "<TR><TD><b>$title</b></TD></TR>\n";     echo "<TR><TD>$news</TD></TR>\n";         echo "</TABLE>\n";     echo "<BR>\n";         /* now show the comments */     displayComments($id); } function displayComments($id) {     /* bring db connection variable into scope */     global $db;         /* query for comments */     $query = "SELECT * FROM news_comments WHERE news_id=$id";     $result = mysql_query ($query);     echo "Comments:<BR><HR width=\"300\">\n";         /* display the all the comments */     while ($row = mysql_fetch_assoc ($result)) {         echo "<TABLE border=\"1\" width=\"300\">\n";                 $name = htmlentities ($row['name']);         echo "<TR><TD><b>by: $name</b></TD></TR>\n";             $comment = strip_tags ($row['comment'], '<a><b><i><u>');         $comment = nl2br ($comment);         echo "<TR><TD>$comment</TD></TR>\n";             echo "</TABLE>\n";         echo "<BR>\n";     }         /* add a form where users can enter new comments */     echo "<HR width=\"300\">";     echo "<FORM action=\"{$_SERVER['PHP_SELF']}" .         "?action=addcomment&id=$id\" method=POST>\n";     echo "Name: <input type=\"text\" " .         "width=\"30\" name=\"name\"><BR>\n";     echo "<TEXTAREA cols=\"40\" rows=\"5\" " .         "name=\"comment\"></TEXTAREA><BR>\n";     echo "<input type=\"submit\" name=\"submit\" " .         "value=\"Add Comment\"\n";     echo "</FORM>\n";     } function addComment($id) {     global $db;         /* insert the comment */     $query = "INSERT INTO news_comments " .             "VALUES('',$id,'{$_POST['name']}'," .             "'{$_POST['comment']}')";     mysql_query($query);         echo "Comment entered. Thanks!<BR>\n";     echo "<a href=\"{$_SERVER['PHP_SELF']}" .         "?action=show&id=$id\">Back</a>\n"; } /* this is where the script decides what do do */ echo "<CENTER>\n"; switch($_GET['action']) {         case 'show':         displayOneItem($_GET['id']);         break;     case 'all':         displayNews(1);         break;     case 'addcomment':         addComment($_GET['id']);         break;     default:         displayNews(); } echo "</CENTER>\n"; } ?>[/code]
  12. I have "timer" in a table called button timer has a number string in it. I want to request the number. I know i have to start with [code]require_once('mysql_connect.php');[/code] Could someone give me the other 1-2 lines please. Thanks a lot.
×
×
  • 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.