/    Sign up×
Community /Pin to ProfileBookmark

php not inserting article into database-no errors

I have a database, for a articles system, and I have a table, and in this table, I have articles, and I know its putting it there, because the rest is there, and the query is right because, I accidently left off the $ in the variable of what to put in there, and it put the variable name into the database, but the data is being lost somewhere in between the form, the variable being set, and the insertion into the database.

Here is the code for my html form:

[code=html]<form action=”newArticle.php” method=”post”>
<b>Title: </b><input type=”text” name=”title”><p>
<b>Tagline: </b><input type=”text” name=”tagline”><p>
<b>Section: </b><input type=”text” name=”section”><p>
<b>Article: </b><textarea name=”thearticle” cols=”50″ rows=”6″></textarea><p>
<input type=”submit” value=”Submit” name=”submitarticle”><input type=”reset”>
</form>[/code]

Here is my code for the variables and the insertion into the database:

[code=php] $title = $_POST[‘title’];
$tagline = $_POST[‘tagline’];
$section = $_POST[‘section’];
$thearticle = $_POST[‘thearticle’];
$insertQuery = “INSERT INTO cmsarticles (title, tagline, section, thearticle) VALUES (‘$title’, ‘$tagline’, ‘$section’, ‘$thearticle’)”;[/code]

Note: The actuall insertion is done later, but this is the code that sets it up.
Another Note: the article column in the table is “thearticle text latin1_swedish_ci Yes NULL” and thats, “Field Type Collation Null Default”

to post a comment
PHP

14 Comments(s)

Copy linkTweet thisAlerts:
@The_Little_GuyAug 06.2006 — [code=php]mysql_query("INSERT INTO cmsarticles (title, tagline, section, thearticle) VALUES ('$title', '$tagline', '$section', '$thearticle'))";[/code]
Copy linkTweet thisAlerts:
@Heavy_MetalauthorAug 06.2006 — i told you the insertion is done later, its inserting everything except the article itself, the title and all that is inserted fine, the article data is just being lost, i dont need help with the insertion
Copy linkTweet thisAlerts:
@NogDogAug 06.2006 — Without having the whole code to view/test (not that I really want to, mind you!), all I can suggest is to put some debug code in. Do a [b]print_r($_POST);[/b] and make sure everything that you expect to be there is there. Put a [b]error_reporting(E_ALL);[/b] at the start of your code to make sure you get all warnings from the parser. Do an echo of your query just before you use it so you can see what is actually being sent to the database. Etc., etc., and so forth.
Copy linkTweet thisAlerts:
@Heavy_MetalauthorAug 06.2006 — ok, when i put the error reporting thing in, it returned this "Notice: Undefined index: thearticle in /home/codersa/public_html/v3/cms/cmsadmin/newArticle.php on line 18" i dont know what undefined index means though
Copy linkTweet thisAlerts:
@The_Little_GuyAug 06.2006 — have you tried this (assuming that this is how your inserting):
[code=php]mysql_query($insertQuery) or die(mysql_error());[/code]
Copy linkTweet thisAlerts:
@Heavy_MetalauthorAug 06.2006 — actually, im using this [code=php]if ($result = $connector->query($insertQuery)){

// It worked, give confirmation
echo '<center><b>Article added to the database</b></center><br>';

}[/code]
to do it, i have a system of classes and stuff set up, and it works fine this way anyway.

EDIT: I googled around and I found the problem. I think undefined index means that no $_POST['thearticle'] exists, which would mean, that I would have named it badly in the form, but it is named correctly, i'v checked it several times. So, Now that the problem is found, how could we correct this, since it says its a problem, but it really isn't. I dont know what to do here.
Copy linkTweet thisAlerts:
@NogDogAug 06.2006 — Give your form code a careful look and make sure there are no unclosed quotes, unclosed tags, etc. (You might want to run it through the [url=http://validator.w3.org/]validator[/url] to see if it finds any problems.)
Copy linkTweet thisAlerts:
@NogDogAug 06.2006 — Also, to see what actually was received by the form handler, try this:
[code=php]
echo "<pre>";print_r($_POST);echo "</pre>n";
[/code]
Copy linkTweet thisAlerts:
@Heavy_MetalauthorAug 06.2006 — I posted my form code above, [code=html]<form action="newArticle.php" method="post"> <b>Title: </b><input type="text" name="title"><p> <b>Tagline: </b><input type="text" name="tagline"><p> <b>Section: </b><input type="text" name="section"><p> <b>Article: </b><textarea name="thearticle" cols="50" rows="6"></textarea><p> <input type="submit" value="Submit" name="submitarticle"><input type="reset"> </form>[/code] and it definatly doesn't look like I have left anything un-opened, and i'll add the thing above to see what happens.
Copy linkTweet thisAlerts:
@Heavy_MetalauthorAug 06.2006 — Okay, It returned, this Array
(
[title] =&gt; test
[tagline] =&gt; a test post
[section] =&gt; 1
[article] =&gt; testing, testing slbaslknsdlksnmda
[submitarticle] =&gt; Submit
)

which is what i put in, its just giving the error for no reason maybe, im more confused now.
Copy linkTweet thisAlerts:
@NogDogAug 06.2006 — From the print_r, the field is called 'article', but you have it as 'thearticle' in your code samples. Are you sure it's not just name='article' in the form?
Copy linkTweet thisAlerts:
@Heavy_MetalauthorAug 06.2006 — OMG, i feel so stupid, I forgot one of the basic things about when you edit code, reload the page, I was just backspacing and therefor, it wasn't loading the code again, so it wasn't changing, it is working fine now. Thanks for your help, and sorry for wasting your time. Feel free to slap me across the face.
Copy linkTweet thisAlerts:
@NogDogAug 06.2006 — *slap*

?
Copy linkTweet thisAlerts:
@Heavy_MetalauthorAug 06.2006 — Yeah, I deserved that ?
×

Success!

Help @Heavy_Metal spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...