HI Guys
I am writing a News Article section and I have 2 form fields with the same value called article_section.
The reas9on I have 2 is because if you write an article you can create an article section by typing it in to a form text field or select an existing section from an article drop down menu form field.
I cant seem to et it working so I am assuming I cant call the form elements the same ame (article_section).
Heres the code
[php]<?php
$submit = $_POST['submit'];
//Form data
$articlesection = mysql_real_escape_string($_POST['article_section']);
$articletitle = mysql_real_escape_string($_POST['article_title']);
$articleptitle = mysql_real_escape_string($_POST['article_ptitle']);
$articlepdescription = mysql_real_escape_string($_POST['article_pdescription']);
$articlepkeywords = mysql_real_escape_string($_POST['article_pkeywords']);
$articlecontent = mysql_real_escape_string($_POST['article_content']);
$date = date('d/m/Y \a\t g:i.s a');
if ($submit){
//Open the database
mysql_connect("localhost","root","");
mysql_select_db("*************"); //Select the database
$pagecheck = mysql_query("SELECT `article_title` FROM articles WHERE `article_title` = '$articletitle'");echo mysql_error();
$count = mysql_num_rows($pagecheck);echo mysql_error();
if ($count != 0){
echo("<font size=\"2\" color=\"#ff0000\">Article already exists. Please edit the existing article!</font>");echo mysql_error();
}else{
//Check for existing fields
if ($articlesection && $articletitle && $articleptitle && $articlepdescription && articlepkeywords && $articlecontent && $date){
//Enter into Database
$queryreg = mysql_query("INSERT INTO articles (`article_section`, `article_title`, `article_ptitle`, `article_pdescription`, `article_pkeywords`, `article_content`, `date`) VALUES ('$articlesection', '$articletitle', '$articleptitle', '$articlepdescription', '$articlepkeywords', '$articlecontent', '$date')");
echo("<font size=\"2\" color=\"#00cc00\">Your article has been created! </font>");
}else{
echo ("<font size=\"2\" color=\"#ff0000\">Please complete <b>ALL</b> fields</font>");
}
}
}
?> [/php]
Heres the form
[php]<form action="addarticle.php" method="post" enctype="multipart/form-data" name="addarticle" target="_self" id="addarticle">
<!-- Form Starts -->
<div class="titlearea">Add News Article</div>
<div class="dataarea">
<div class="infowrap">Article title</div>
<div class="infowrap">Create Article Section</div>
<div class="infowrap">Select Article Section</div>
<div class="infowrap"><input name="article_title" type="text" id="article_title" size="25" maxlength="20" />
</div>
<div class="infowrap"><input name="article_section" type="text" id="article_section" size="25" maxlength="100" />
</div>
<div class="infowrap">
<label></label>
<label>
<select name="article_section" id="article_section">
<option><?php echo $row["article_section"]; ?></option>
</select>
</label>
</div>
</div>
<div class="titlearea">Meta Data</div>
<div class="dataarea">
<div class="metawrap">Title - Please use approx 65 characters</div>
<div class="metawrap"><input name="article_ptitle" type="text" id="article_ptitle" size="80" maxlength="20" />
</div>
<div class="metawrap">Description - Please use approx 155 characters inc spaces</div>
<div class="metawrap"><input name="article_pdescription" type="text" id="article_pdescription" size="80" maxlength="200" />
</div>
<div class="metawrap">Keywords - Please use approx 5 keyword per page</div>
<div class="metawrap"><input name="article_pkeywords" type="text" id="article_pkeywords" size="80" maxlength="200" />
</div>
</div>
<div class="titlearea">Article Content</div>
<div class="dataarea">
<textarea name="article_content" cols="80" rows="20" id="article_content"></textarea>
</div>
<div class="dataarea">
<input type="submit" value="Save" name="submit" /></div>
</form>[/php]
Is this the right way to do it?
