Jump to content

[SOLVED] Is there something wrong with my code?


Aureole

Recommended Posts

'Cause when I submit my form I get a white screen and nothing is getting added to the database.

 

<?php

if (isset($_POST['submitted'])) {

include("http://www.veraci7y.net/connectme.php");

if (empty($_POST['title'])) {
echo 'You did not enter a title.';
} else {
$t = $_POST['title'];
}

$c = $_POST['category'];

if (empty($_POST['shortstory'])) {
echo 'You did not enter a short story.';
} else {
$s = $_POST['shortstory'];
}

if (empty($_POST['fullstory'])) {
echo 'You did not enter a full story.';
} else {
$f = $_POST['fullstory'];
}

$a = $_POST['author'];
$m = $_POST['memberid'];


if ($t && $s && $f) {
$query = "INSERT INTO news (title, category, shortstory, fullstory, author, memberid) VALUES ('$t', '$c', '$s', '$f', '$a', '$m')";

$result = @mysql_query($query);

if ($result) {
echo 'News posted successfully.';
} else {
echo 'News could not be added.';
}
} else {
echo ' All fields are required.';
}
}

?>

Link to comment
Share on other sites

If it's just the include() that is wrong then can't someone tell me what's up with it...I'm guessing it'd take 20 seconds to explain and I'm new to coding in PHP so I have no idea why you're saying that there's something wrong with the include()

 

It all looks good to me...  ???

Link to comment
Share on other sites

<?php

DEFINE ('DB_USER', 'Teh Username');
DEFINE ('DB_PASSWORD', 'Teh Password');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'veraci7y_website');

$connectme = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error());
@mysql_select_db (DB_NAME) OR die('Could not select the database: ' . mysql_error() );

?>

Link to comment
Share on other sites

<?php
if (isset($_POST['submitted'])) {
    include("http://www.veraci7y.net/connectme.php");
    if (empty($_POST['title'])) {
        echo 'You did not enter a title.';
    } else {
        $t = $_POST['title'];
    }
    $c = $_POST['category'];
    if (empty($_POST['shortstory'])) {
        echo 'You did not enter a short story.';
    } else {
        $s = $_POST['shortstory'];
    }
    if (empty($_POST['fullstory'])) {
        echo 'You did not enter a full story.';
    } else {
        $f = $_POST['fullstory'];
    }
    $a = $_POST['author'];
    $m = $_POST['memberid'];

    if ($t && $s && $f) {
        $query = "INSERT INTO news (title, category, shortstory, fullstory, author, memberid) VALUES ('$t', '$c', '$s', '$f', '$a', '$m')";
        $result = @mysql_query($query);
        if ($result) {
            echo 'News posted successfully.';
        } else {
            echo 'News could not be added.';
        }
    } else {
        echo ' All fields are required.';
    }
}
?>

 

That's your code with some indentation of loops to make the code easier to follow.

 

Unless your form has a variable NAMEd submitted and uses the POST method, nothing would be executed at all. Does your form have variables NAMEd correctly?

Link to comment
Share on other sites

<form id="addnews" action="news/submit.php" method="post">

<label for="title">Title:</label><br />
<input size="10" type="text" name="title" id="title" /><br />

<label for="category">Category:</label><br />
<select name="category" id="category">
<option value="veraci7y" selected="selected">Veraci7y.net</option>
<option value="teamveraci7y">Team x Veraci7y</option>
<option value="misc">Misc.</option>
</select><br />

<label for="shortstory">Short Story:</label><br />
<textarea rows="4" cols="25" name="shortstory" id="shortstory">Enter a short summary here.</textarea><br />

<label for="fullstory">Full Story:</label><br />
<textarea rows="4" cols="25" name="fullstory" id="fullstory">Enter the full story here.</textarea><br />

<input type="submit" name="Submit" value="Submit" />

<input type="hidden" name="author" value="<?php echo $member['members_display_name']; ?>" />
<input type="hidden" name="memberid" value="<?php echo $member['id']; ?>" />

</form>

Link to comment
Share on other sites

Warning: mysql_query() [function.mysql-query]: Access denied for user 'veraci7y'@'localhost' (using password: NO) in /home/veraci7y/public_html/news/submit.php on line 33

 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/veraci7y/public_html/news/submit.php on line 33

Error: Access denied for user 'veraci7y'@'localhost' (using password: NO) with query INSERT INTO news (title, category, shortstory, fullstory, author, memberid) VALUES ('Test', 'veraci7y', '1', '2', 'Aureole', '1')

Link to comment
Share on other sites

All that's left - drop the include:

 

<?php
DEFINE ('DB_USER', 'Teh Username');
DEFINE ('DB_PASSWORD', 'Teh Password');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'veraci7y_website');

$connectme = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error());
mysql_select_db(DB_NAME) OR die('Could not select the database: ' . mysql_error() );

if (isset($_POST['submitted'])) {
    // include("http://www.veraci7y.net/connectme.php");
    if (empty($_POST['title'])) {
        echo 'You did not enter a title.';
    } else {
        $t = $_POST['title'];
    }
    $c = $_POST['category'];
    if (empty($_POST['shortstory'])) {
        echo 'You did not enter a short story.';
    } else {
        $s = $_POST['shortstory'];
    }
    if (empty($_POST['fullstory'])) {
        echo 'You did not enter a full story.';
    } else {
        $f = $_POST['fullstory'];
    }
    $a = $_POST['author'];
    $m = $_POST['memberid'];

    if ($t && $s && $f) {
        $query = "INSERT INTO news (title, category, shortstory, fullstory, author, memberid) VALUES ('$t', '$c', '$s', '$f', '$a', '$m')";
        $result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);
        if ($result) {
            echo 'News posted successfully.';
        } else {
            echo 'News could not be added.';
        }
    } else {
        echo ' All fields are required.';
    }
}
?>

Link to comment
Share on other sites

Like i said, it was the include.

 

You're including over HTTP, which would actually include nothing. It would be like you going to the link yourself.

 

You need to include locally. Like include('connectdb.php')

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.