Jump to content

Submit button not working!!?


Perad

Recommended Posts

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]
Link to comment
Share on other sites

Hello, have not run the code you gave but i did notice you close your form tag before the submit button and then again after it. Im sure thats the problem.

Your html
[quote]
<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>
[/quote]

should read
[quote]
<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 />
<input type="submit" name="submit" value="Add Article" />
</form>
[/quote]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.