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=1it will load article 1
than if I call this URL
http://mysite.com/articles.php?id=2it 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.";
}
?>