Article SQL Database Insert - Joomla! Forum - community, help and support


hey all, working on own project create front-end submission form jxtended magazine. assumed work in same way article in need populate fields in database information represented article within component, right?

i new php coding , sql, in fact prior project have never done in php. therefore answer problem may incredibly simple, , such ask patience :)

before populating articles within magazine (i.e. different database jos_content different fields) trying create own article submission form .php , .html files bit of foundation of knowledge going.

my .php , html code follows, problem is: when try submit form, receive "your form has been received" when check in cpanel , through phpmyadmin check database content jos_content, there no new article. why might happening?

code: select all

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>untitled document</title>
</head>

<body>

<form action="sqltestform.php" method="post">
title:<input type="text" name="title" /><br />
fulltext:<input type="text" name = "fulltext" /><br />
alias:<input type="text" name = "alias" /><br />
introtext:<input type="text" name = "introtext" /><br />
created_by_alias:<input type="text" name = "created_by_alias" /><br />
<input type="submit" value="submit" />
</form>

</body>
</html>


code: select all

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>untitled document</title>
</head>

<body>


<?

$title=$_post['title'];
$alias=$_post['alias'];
$title_alias=$_post['title_alias'];
$introtext=$_post['introtext'];
$fulltext=$_post['fulltext'];
$created_by_alias=$_post['created_by_alias'];

mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("des49422_laboratory") or die(mysql_error());
mysql_query("insert `jos_content` values ('$introtext', '$title_alias', '$created_by_alias', '$title', '$fulltext', '$alias')");
$id= mysql_insert_id();
print "<p>your information has been added database.</p>";
?>


</body>
</html>


ps have removed username , password (just safe :) ), correct issue elsewhere.

thank very much!

unless have enabled short open tags in php.ini file, should use normal format <?php because short open tag <? deprecated.

here reason why insert fails: format of query assumes number of values in statement matches column count of table.

it better list names of columns want add new row. avoid problem id column auto-incremented , therefore not listed column in insert query.

during testing useful detailed error message if query fails, this:

code: select all

$q = "insert `test` ( text, text2, text3 ) values ('$value', '$value2', '$value3')";
$result = mysql_query( $q );
if ( !$result ) {
    $message  = 'error: ' . mysql_error() . "\n";
    $message .= 'query: ' . $q;
    die( $message );
}





Comments

Popular posts from this blog

Joomla site hacked, cant see front and - Joomla! Forum - community, help and support

Christian Home School Programs - Joomla! Forum - community, help and support

Trouble with PF_OutFlag_I_USE_AUDIO and PF_CHECKOUT_LAYER_AUDIO