Jump to content

Perad

Members
  • Posts

    287
  • Joined

  • Last visited

    Never

Everything posted by Perad

  1. To make this clearer... displayCategories shows the following. Category 1 Description Category 2 Description displayList shows Article 1 Article 2 Article 3 displayOneItem shows Article Title Text The problem is with displayOneItem It shows ------------------- |Article Title |------------------ |Content | |------------------ There are no articles in this category Back As you can see "There are no articles in this category Back" Shouldn't be there as this is from the displaylist function. I was hoping someone could help remove this. My updated script is here [code]<?php $type = 1; $dbc = mysql_connect ('localhost','root','admin'); mysql_select_db ('UNC',$dbc); function displayCategories() { global $dbc, $username, $type; $query = "SELECT * FROM site_categories WHERE cat_type=$type"; $result = mysql_query ($query)or die("Problem with the query: $query on line:" . __LINE__ . "<br>" . mysql_error()); while ($row = mysql_fetch_assoc ($result)) { /* display categories in a simple table */ echo "<TABLE border=\"1\" width=\"580\">\n"; $description = htmlentities ($row['description']);  $title = htmlentities ($row['cat_name']); echo "<TR><TD width=\"300\"><b>$title</b></TD>"; /* get number of articles */ $comment_query = "SELECT count(*) FROM downloads WHERE cat_id={$row['cat_id']}"; $comment_result = mysql_query ($comment_query); $comment_row = mysql_fetch_row($comment_result); /* display number of articls with link */ echo "<TD><a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&cat_id={$row['cat_id']}\">Articles</a>" . "($comment_row[0])</TD></TR>\n"; echo "<tr><td colspan=\"2\">$description</td></tr>"; /* finish up table*/ echo "</TABLE>\n"; echo "<BR>\n"; } } function displayList($cat_id) { global $dbc, $type, $redirectpage; $dbc = mysql_connect ('localhost','root','admin'); mysql_select_db ('UNC',$dbc); /* query for item */ $query = "SELECT * FROM downloads WHERE cat_id='$cat_id'"; $result = mysql_query ($query)or die("Problem with the query: $query on line:" . __LINE__ . "<br>" . mysql_error()); /* if we get no results back, error out */ if (mysql_num_rows ($result) == 0) { echo "There are no articles in this category\n"; echo "<a href=\"{$_SERVER['PHP_SELF']}" . "?action=all\">Back</a>\n"; return; } while ($row = mysql_fetch_assoc ($result)) { echo "<TABLE border=\"1\" width=\"580\">\n"; /* easier to read variables and * striping out tags */ $title = htmlentities ($row['down_title']); $author = htmlentities($row['author']); $postdate = htmlentities($row['postdate']); /* display the items */ /* display number of articls with link */ echo "<TD><a href=\"{$_SERVER['PHP_SELF']}" . "?action=display&id={$row['down_id']}\">Article</a>" . "</TD></TR>\n"; echo "<TR><TD><b>$title</b></TD></TR>\n"; echo "<TR><TD>$postdate<br /><i>Posted by $author </TD></TR>"; echo "</TABLE>\n"; echo "<BR>\n"; } } function displayOneItem($id) { $dbc = mysql_connect ('localhost','root','admin'); mysql_select_db ('UNC',$dbc); global $dbc; /* query for item */ $query = "SELECT * FROM downloads WHERE down_id=$id"; $result = mysql_query ($query) OR die ('Could not connect to MySQL: ' . mysql_error() ); /* if we get no results back, error out */ if (mysql_num_rows ($result) == 0) { echo "Bad article id\n"; return; } $row = mysql_fetch_assoc($result); echo "<TABLE border=\"1\" width=\"580\">\n"; /* easier to read variables and * striping out tags */ $title = htmlentities ($row['down_title']); $news = nl2br (strip_tags ($row['comments'], '<a><b><i><u>')); $author = htmlentities($row['author']); $postdate = ($row['postdate']); /* display the items */ echo "<TR><TD><b>$title</b></TD></TR>\n"; echo "<TR><TD>$news<br /><i>Posted by $author </TD></TR>"; echo "</TABLE>\n"; echo "<BR>\n"; } echo "<CENTER>\n"; switch($_GET['action']) { case 'display': displayOneItem($_GET['id']); case 'show': displayList($_GET['cat_id']); break; case 'all': displayCategories(1); break; default: displayCategories(); } echo "</CENTER>\n"; ?>[/code]
  2. That has fixed it but now the message says [quote]There are no articles in this category Back[/quote] This is shoudn't even be there, it should just display the article.
  3. The script works and does everything i want it to do. Unfortunately it also does something else and final page is showing a database error for something it shouldn't even be calling. Basically the script contains 3 functions which take actions from a switch statement. It all works but but on the last page there is this error. [quote]Problem with the query: SELECT * FROM downloads WHERE cat_id= on line:64 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1[/quote] The script for some reason is doing a database query from displayList(); when it shouldn't be. Could someone help me make this stop please. Thanks [code]<?php $type = 1; //sorting out redirects $redirectpage = NULL; if ($type == 1) { $redirectpage = 'downloads.php'; } else if ($type == 2) { $redirectpage = 'articles.php'; } else if ($type == 3) { $redirectpage = 'demos.php'; } //End of redirects // type if ($type == 1) { $typetext = 'downloads'; } else if ($type == 2) { $typetext = 'articles'; } else if ($type == 3) { $typetext == 'demos'; } //End Type function displayCategories() { $dbc = mysql_connect ('localhost','root','admin'); mysql_select_db ('UNC',$dbc); global $dbc, $username; $type = 1; $query = "SELECT * FROM site_categories WHERE cat_type=$type"; $result = mysql_query ($query)or die("Problem with the query: $query on line:" . __LINE__ . "<br>" . mysql_error()); while ($row = mysql_fetch_assoc ($result)) { /* display categories in a simple table */ echo "<TABLE border=\"1\" width=\"580\">\n";   $title = htmlentities ($row['cat_name']); echo "<TR><TD width=\"300\"><b>$title</b></TD>"; /* get number of articles */ $comment_query = "SELECT count(*) FROM downloads WHERE cat_id={$row['cat_id']}"; $comment_result = mysql_query ($comment_query); $comment_row = mysql_fetch_row($comment_result); /* display number of articls with link */ echo "<TD><a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&cat_id={$row['cat_id']}\">Articles</a>" . "($comment_row[0])</TD></TR>\n"; /* finish up table*/ echo "</TABLE>\n"; echo "<BR>\n"; } } function displayList($cat_id) { global $dbc, $type, $redirectpage; $dbc = mysql_connect ('localhost','root','admin'); mysql_select_db ('UNC',$dbc); /* query for item */ $query = "SELECT * FROM downloads WHERE cat_id=$cat_id"; $result = mysql_query ($query)or die("Problem with the query: $query on line:" . __LINE__ . "<br>" . mysql_error()); /* if we get no results back, error out */ if (mysql_num_rows ($result) == 0) { echo "Bad news id\n"; return; } while ($row = mysql_fetch_assoc ($result)) { echo "<TABLE border=\"1\" width=\"580\">\n"; /* easier to read variables and * striping out tags */ $title = htmlentities ($row['down_title']); $author = htmlentities($row['author']); $postdate = htmlentities($row['postdate']); /* display the items */ /* display number of articls with link */ echo "<TD><a href=\"{$_SERVER['PHP_SELF']}" . "?action=display&id={$row['down_id']}\">Article</a>" . "</TD></TR>\n"; echo "<TR><TD><b>$title</b></TD></TR>\n"; echo "<TR><TD>$postdate<br /><i>Posted by $author </TD></TR>"; echo "</TABLE>\n"; echo "<BR>\n"; } /* now show the comments */ } function displayOneItem($id) { $dbc = mysql_connect ('localhost','root','admin'); mysql_select_db ('UNC',$dbc); global $dbc; /* query for item */ $query = "SELECT * FROM downloads WHERE down_id=$id"; $result = mysql_query ($query) OR die ('Could not connect to MySQL: ' . mysql_error() ); /* 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 */ $title = htmlentities ($row['down_title']); $news = nl2br (strip_tags ($row['comments'], '<a><b><i><u>')); $author = htmlentities($row['author']); $postdate = ($row['postdate']); /* display the items */ echo "<TR><TD><b>$title</b></TD></TR>\n"; echo "<TR><TD>$news<br /><i>Posted by $author </TD></TR>"; echo "</TABLE>\n"; echo "<BR>\n"; /* now show the comments */ } echo "<CENTER>\n"; switch($_GET['action']) { case 'display': displayOneItem($_GET['id']); case 'show': displayList($_GET['cat_id']); break; case 'all': displayCategories(1); break; default: displayCategories(); } echo "</CENTER>\n"; ?>[/code]
  4. If i send a variable like this http://localhost/downloads.php?action=show&down_id=5 How do i call it in the new script?
  5. Null means no value. Its used for optional database values. For example your profile contains many optional values which are null till you put something in them. Things like password and e-mail are NOT NULL
  6. Do you want help making this in general or have you got a more specific question?
  7. I found this script a while back and have used a modified version of this is used across my new site. The problem i am having is that i need to add another layer to it and don't understand how the switch statement that controls it works. Here's the script [code]<?php /* user config variables */ $max_items = 5; /* max number of news items to show */ /* make database connection */ $db = mysql_connect ('localhost','root','Berskin99'); 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] I have written what i want to add which you can see below. Each news article has a category. I want the user to be able to select a category which will lead them onto the news in that category. How would i modify the switch statement to allow this? [code]<? function displayArticles() { global $dbc, $max_items, $username; $query = "SELECT * FROM site_categories"; $result = mysql_query ($query); while ($row = mysql_fetch_assoc ($result)) { /* display categories in a simple table */ echo "<TABLE border=\"1\" width=\"580\">\n";   $title = htmlentities ($row['cat_name']); echo "<TR><TD width=\"300\"><b>$title</b></TD>"; /* get number of articles */ $comment_query = "SELECT count(*) FROM downloads WHERE cat_id={$row['cat_id']}"; $comment_result = mysql_query ($comment_query); $comment_row = mysql_fetch_row($comment_result); /* display number of articls with link */ echo "<TD><a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&cat_id={$row['cat_id']}\">Articles</a>" . "($comment_row[0])</TD></TR>\n"; /* finish up table*/ echo "</TABLE>\n"; echo "<BR>\n"; } }?>[/code]
  8. Sorry to take so long, until you editted it your post didn't make a great deal of sense :) It comes back with [code]Array (     [player] => Array         (             [0] => 1             [1] => 2         )     [submit2] => Next )[/code] 1 and 2 being the values which i put in. How would i incorporate this into a loop?
  9. [quote author=effigy link=topic=112677.msg457413#msg457413 date=1161787209] The name of the inputs should be[tt] [/tt], which will come across as an array named[tt] $_POST['player'][/tt]. You can then loop through the array and run your SQL statements. [/quote] Could you explain this more, do you mean... player[<input type="text" name="player'.$i.'" size="35" maxlength="35" />]
  10. I have come up with a loop which generates a form. I am pretty stunned that it worked first time 8). Anyway, i need to transfer data from this form into a database. Because the form size is constantly varying i don't know where i would start. Would i need to use a loop to generate a mysql command? [code]Heres my loop to generate the form. if ($players !== 0) { echo '<form id="form2" name="form2" method="post" action="">'; echo 'UNC<br /><br />';     for ($i=0;$i<$players;$i++) { if (($players/2)==$i) { echo '<br /><br />Opponent<br />Player:<input type="text" name="player'.$i.'" size="35" maxlength="35" /><br />'; } else {       echo 'Player:<input type="text" name="player'.$i.'" size="35" maxlength="35" /><br />'; }     } echo '</form>';   } [/code] Any ideas on how i would handle this form?
  11. I get those errors when either my SQL commands are wrong. Or i am trying to enter the wrong types of data into the database.
  12. This is my first switch statement and it isn't working. It is supposed to process the values in my form and change the $players value accordingly. Right now it returns 1 no matter what i select. Could someone have a look at it and tell me where i am going wrong. Cheers [code]<form id="form1" name="form1" method="post" action="">   <select name="matchsize">     <option>1v1</option>     <option>2v2</option>     <option>3v3</option>     <option>4v4</option>     <option>5v5</option>     <option>6v6</option>     <option>7v7</option>     <option>8v8</option>     <option>9v9</option>     <option>10v10</option>     <option>11v11</option>     <option>12v12</option>   </select>   <input type="submit" name="submit1" value="Save Changes" /> </form> <?php  function NumberOfPlayers() { $players = 0; if (isset($_POST['submit1'])) { switch(isset($_POST['matchsize'])) { case '1v1': $players = 1; break; case '2v2': $players = 2; break; case '3v3': $players = 3; break; case '4v4': $players = 4; break; case '5v5': $players = 5; break; case '6v6': $players = 6; break; case '7v7': $players = 7; break; case '8v8': $players = 8; break; case '9v9': $players = 9; break; case '10v10': $players = 10; break; case '11v11': $players = 11; break; case '12v12': $players = 12; break; default: $players = 0; } echo $players; } } NumberOfPlayers(); [/code]
  13. Are you running a forum? How are your members... err members?
  14. You could make people enter a valid e-mail to enter, you can then check the e-mail against your db and see if they have already entered. EDIT: If they are already members, you could add a new table for each servey. One of your columns could be user_id. When the member clicks the button first time their user_id will be saved. If they click it a second time it will check for the members id and reject the second application.
  15. Makes absolutely no sense, it was working fine last week, i made a minor adjustment to a different part of the script and poof, the function stops handling the form... I have tried everything, even imported a near identical working script and changed the query... nothing. Can someone have a quick look over it and see if they can spot anything out of place Thx [code]function one() { if (isset($_POST['submit'])) { // Handle the form. $message = NULL; // Create an empty new variable. // Check for a first name. if (empty($_POST['articletitle'])) { $at = FALSE; $message .= '<p>You forgot to enter the title!</p>'; } else { $at = $_POST['articletitle']; } // Check for a last name. if (empty($_POST['articletext'])) { $atext = FALSE; $message .= '<p>You forgot to enter the content!</p>'; } else { $atext = $_POST['articletext']; } if ($at && $atext) { // If everything's OK. $db = mysql_connect ('localhost','root','admin'); mysql_select_db ('UNC',$db); // Make the query. $query = "INSERT INTO articles (postdate, title, articletext, category_id) VALUES(NOW(), '$at', '$atext', '$cat_id')"; $result = 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>'; } } one(); [/code] [code]<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Article Title:<br /><input type="text" name="articletitle" size="50" maxlength="50" /><br /> Article Content:<br /><textarea cols="40" rows="5" name="articletext" value="articletext"></textarea><br /></form> <input type="submit" name="submit" value="Add Article" /> </form>[/code]
  16. I half achieved it on this page .. http://www.jasonstanley.co.uk/UNC/ You see how you can click on "comments" and it displays the news article and the comments. This was a script which i found and modified. It wasn't very well explained on how it works. I effectively want the above but 3 layers worth instead of 2. I want the initial screen to show the categories with the number of articles in each categories. Category 1 (5 articles) Category 2 (3 Articles) Category 3 (12 articles) I have actually made this much, i just can't work out how to do anymore with php When the user clicks on a category it will display the following. -------------------- Category 1 -------------------- --Article 1 --Article 2 --Article 3 --Article 4 --Article 5 Finally the user will click on an article name and it will display the article. ------------------ Article Title ------------------ Article Content. How would i do it? I thought i could create 3 functions, each one calling the relevant data then i would some how piece to it together. Unfortunately i can't find anything about this is my php book.
  17. Do you know what i would need to google to find a tutorial or example of this?
  18. I want to create a single script which has the following(see below). I am looking for a tutorial but don't have a clue what to search for.. I know how to make each of the pages individually but i don't have a clue how to combine the functions into 1 page. Could someone point me to a tutorial or quickly explain how to link a bunch of functions so the user stays on the same page when they go to different articles. Category View Category 1 Category 2 Category 3 Expanded Category View Category 1 -Article 1 -Article 2 Category 2 -Article 3 -Article 4 -Article 5 Article View Title Content Thanks for any help given Perad
  19. Gah, hadn't defined the $IsLoggedIn variable in the function..
  20. I am tiding up my code and i realised i could use the same script to do 2 functions. On the main page.. [code]$IsLoggedIn = 0[/code] When the user logs in, this is set to 1 [code]$IsLoggedIn = 1[/code] I know this works because the post comment area appears and disappears depending if the user is logged in. [code]if ($IsLoggedIn == 1) { /* add a form where users can enter new comments */ echo "<FORM action=\"{$_SERVER['PHP_SELF']}" . "?action=addcomment&id=$id\" method=POST>\n"; echo "<p>You are posting as " .$username. "<br />"; echo "<TEXTAREA cols=\"40\" rows=\"5\" " . "name=\"comment\"></TEXTAREA><BR>\n"; echo "<input type=\"submit\" name=\"submit\" " . "value=\"Add Comment\"\n"; echo "</FORM>\n"; } else { echo 'Please log-in to post a comment'; } }[/code] So why doesn't my switch statement work? No matter whether the user is logged in or not, the "else" part is always displayed. Could someone help me fix this please. The switch statement is below. [code] /* this is where the script decides what do do */ if ($IsLoggedIn == 1) { 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(); } } else { echo "<CENTER>\n"; switch($_GET['action']) { case 'show': displayOneItem($_GET['id']); break; case 'all': displayNews(1); break; default: displayNews(); } }[/code] thx Perad
  21. I have a form with a load of entry fields. I want to check to see if the field is empty, if the fields empty i want the variable to be set to null. I have all these variables... [code] $user_id = $userdata['user_id']; $f_name = $_POST['first_name']; $l_name = $_POST['last_name']; $gfx = $_POST['hw_gfx']; $mb = $_POST['hw_mb']; $pro = $_POST['hw_pro']; $mem = $_POST['hw_mem']; $mouse = $_POST['hw_mouse']; $fgame = $_POST['fav_game']; $ffilm = $_POST['fav_film']; $fbook = $_POST['fav_book']; $notes = $_POST['notes'];[/code] Please tell me there is a better way than [code] if (empty($_POST['first_name'])) { $f_name = NULL; } else { $f_name = $_POST['first_name']; } [/code]
  22. I have the code below... it doesn't work and the link is blank. When i click on View>>Source it shows the php echo in pink instead of processing it. Is this code wrong? If so could you help me fix it... if not could it be a problem with my apache/php installation? PHP Code [code]echo('Welcome back '.$userdata['username'] . '<br /> <a href="/forums/privmsg.php?folder=inbox"> <?php echo $l_privmsgs_text ?></a><br />'); [/code] HTML code [code]<a href="/forums/privmsg.php?folder=inbox"><?php echo $l_privmsgs_text ?></a>[/code]
  23. Is something unclear? Or is the lack of replies simply because people don't know. If you want me to try to rephrase it i will.
  24. I am really close to finishing this off. The problem is i don't have a clue how to do it. I think the problem is that i am going about it in the wrong way. Anyway the first function creates a form. [code] function add_article () { echo "Category:<br /><select name=\"category\">"; global $db; $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)) { /* display news in a simple table */ /* 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 */ $cat_id = ($row['category_id']); $cat_name = htmlentities ($row['category_name']);      /* display the data */ echo "<option>" . $cat_id . "-" . $cat_name . "</option>"; } echo "</select>"; /*End of Select Category*/ }[/code] The second uses the first function and enters data into the database when the submit button is pressed. The problem is with the last entry 'category_id'. What i am trying to do is allow the site administrator to select the category they want from above. Then when they press submit, it will take the category id of the dropdown box and insert it into the database. Unfortunately its just not happening. With the way my code is set-up is it even possible to do what i want? If not could you give me advice on how i would set it up to make it work. Second Function [code] function handle_article () { add_article(); /*Start of new form*/ if (isset($_POST['add_article'])) { $message = NULL; // Create an empty new variable. if (empty($_POST['articletitle'])) { $at = FALSE; $message .= '<p>You forgot to enter the article title!</p>'; } else { $at = $_POST['articletitle']; } if (empty($_POST['articletext'])) { $atext = FALSE; $message .= '<p>You forgot to enter the article text!</p>'; } else { $atext = $_POST['articletext']; } if ($at && $atext ) { global $db; // Make the query. $query = "INSERT INTO articles (postdate, title, articletext, category_id) VALUES(NOW(), '$at', '$atext', '$cat_id')"; $result = mysql_query($query); if ($result) { // If it ran OK. // Confirmation. echo '<p><b>A new category has been added!</b></p>'; exit(); // Quit the script. } else { // If it did not run OK. $message = '<p>The category 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>'; } } if (isset($message)) { echo '<font color="red">'. $message. '</font>'; } } [/code] Thanks for any help given Perad
×
×
  • 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.