PlagueInfected Posted February 5, 2010 Share Posted February 5, 2010 I don't know what I'm doing wrong here. I'm trying to do a method to where if id=2 than the db will select the articleid from the table, than load articleid2's contents. so if I call this URL http://mysite.com/articles.php?id=1 it will load article 1 than if I call this URL http://mysite.com/articles.php?id=2 it will load article 2 Here's my form code <fieldset> <legend>Adding KB article on <?php echo date("l, F d, Y");?> on <?php echo $_SERVER['HTTP_HOST']; ?></legend> <form action="../admin/knowledge_base.php" method="POST"> <input type="hidden" name="date" value="<?php echo date("l, F d, Y"); ?>" border="0" /> <label>Article ID</label> <input type="text" name="articleid" /> <br /> <?php $connect = mysql_connect("localhost", "myusername", "mypassword") or die ('Error:' .mysql_error()); if (!$connect) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydatabse", $connect); $query = "SELECT articleid, COUNT(articleid) FROM knowledge_base"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo "There are currently " . $row['COUNT(articleid)'] ." article(s)" . "\n"; if ($row['COUNT(articleid)'] == "0") { $row['COUNT(articleid)'] = "0"; } } ?> <br /> <label> Article Name</label> <input type="text" name="articlename" id="admin_subject" /> <br /> <label>Article Information </label><br /> <textarea name="articleinfo" id="admin_textarea"></textarea> <br /> <input type="submit" value="submit" /> <input type="reset" value="reset" /> </form> </fieldset> here is my write code <?php $articleid = $_POST['id']; $articlename = $_POST['articlename']; $articleinfo = $_POST['articleinfo']; $date = $_POST['date']; $error = "no content inserted on update page"; //if not content is plugged in echo error if (!$articlename && !$articleinfo) { echo "Error: " . $error . "\n"; } //MySQL connection $connect = mysql_connect("localhost", "myusername", "mypassword") or die ('Error:' .mysql_error()); if (!$connect) { die('Could not connect: ' . mysql_error()); } if ($connect && !$articlename && !$articleinfo &&!$articleid) { die ('No information submitted to post to DB'); } mysql_select_db("mydatabse", $connect); //Created MySQL 'knowledge_base' table $sql = "CREATE TABLE knowledge_base ( articleid(4), articlename(20), articleinfo(2000), date(20), )"; mysql_query($sql,$connect); mysql_query("INSERT INTO knowledge_base (articleid,articlename, articleinfo, date) VALUES ('$articleid', '$articlename', '$articleinfo', '$date')"); echo "Article published on " . $date . "\r\n" . ' <a href="javascript:history.back(-2);">Click to go back!</a>'; mysql_close($connect); ?> and here is my calling code with the statements <?php /* Knowledge Base */ $id = $_GET['id']; $article_id_call = $row['articleid']; $connect = mysql_connect("localhost", "myusername", "mypassword"); if (!$connect) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydatabase", $connect); $result = mysql_query("SELECT articleid FROM knowledge_base"); mysql_close($connect); if ($id == $article_id_call) { $connect = mysql_connect("localhost", "myusername", "mypassword"); if (!$connect) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydatabse", $connect); $result = mysql_query("SELECT * FROM knowledge_base ORDER BY articlename"); while($row = mysql_fetch_array($result)) { echo "<h1>" . $row['articlename'] . "</h1>" . "\n"; echo " <div id='base'>" . $row['articleinfo'] . "</div>" . "\n"; } mysql_close($connect); } elseif ($id == !$article_id_call) { echo "this article does not exist!"; } else { echo "knowledge base test."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/191097-url-request-to-load-article/ Share on other sites More sharing options...
premiso Posted February 6, 2010 Share Posted February 6, 2010 Why do you insist on closing the connection? I would remove all of the mysql_close from your script, as unless you are switching databases it is not necessary as PHP will automatically close the connection for you. On another note, perhaps this tutorial I wrote will help you out: Fetch MySQL Data Using PHP and GET Quote Link to comment https://forums.phpfreaks.com/topic/191097-url-request-to-load-article/#findComment-1007725 Share on other sites More sharing options...
PlagueInfected Posted February 9, 2010 Author Share Posted February 9, 2010 thanks That did it for me, I knew I missed something when it came to calling. {myvar} never knew that was it to do it. Quote Link to comment https://forums.phpfreaks.com/topic/191097-url-request-to-load-article/#findComment-1009382 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.