Welcome to WebmasterWorld Guest from 54.163.35.238

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Inserted Data..does not show in Database

     

Senmar50

10:21 pm on Oct 10, 2004 (gmt 0)

10+ Year Member



Hi

This is the only script I'm having a problem with. I can very easily enter data into my database by using the "phpMyadmin" on our web-host's server. I would rather use a form to enter the data. The insert.php script tells me the data has been entered. When I display the data in the database only the "ID" field has increased, but the actually data is not there. Can you tell me what I am doing wrong.

Thanks in Advance,
Senmar

(insert.php script)
<?php
// connect to the mysql server
mysql_connect("localhost","moot","ok") or die (mysql_error());
echo "Connected to Mysql<br/>";

// select the database
mysql_select_db("News_Articles") or die
(mysql_error());
echo "Connected to Database<br/>";

// insert data into ccds_news table
$sql = "INSERT INTO ccds_news(article_title, author_name, subject, date_created, content, EMAIL) VALUES('', '', '', '', '', '' )";

// run the query
mysql_query($sql);
echo "DATA ENTERED!";

?>

(add_article.html)
................
<form method="post" name="add" action="insert.php">
<table><tr>
<td>Article Title:</td>
<td><input type="text" name="article_title" size="60" maxlength="70"></td>
</tr><tr>
<td>Author Name:</td>
<td><input type="text" name="author_name" size="30" maxlength="45"></td>
</tr><tr>
<td>Subject:</td>
<td><input type="text" name="subject" size="30" maxlength="45"></td>
</tr><tr>
<td>Date Created:</td>
<td><input type="text" name="date_created" size="15" maxlength="20"></td>
</tr><tr>
<td>Content:</td>
<td><textarea name="content" cols="40" rows="15"></textarea></td>
</tr></tr>
<td>EMAIL:</td>
<td><input type="text" name="EMAIL" size="25" maxlength="40"></td>
</tr><tr>
<td colspan="2" align="center"><input type="submit" name="add" value="Add Article">
<input type="reset" name="reset" value="Reset"></td>
</tr></table>
</form>

dreamcatcher

10:36 pm on Oct 10, 2004 (gmt 0)

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Well, your values are empty for starters.

$sql = "INSERT INTO ccds_news(article_title, author_name, subject, date_created, content, EMAIL) VALUES('', '', '', '', '', '' )";

Try something like:

$sql = "INSERT INTO ccds_news(article_title, author_name, subject, date_created, content, EMAIL) VALUES('" . $_POST['article_title'] . "', '" . $_POST['author_name'] . "', '" . $_POST['subject'] . "', '" . $_POST['date_created'] . "', '" . $_POST['content'] . "', '" . $_POST['EMAIL'] . "' )";

You`ll also want to use either addslashes or mysql_escape_string for problematic quotes or convert then to character entities before they get posted.

Senmar50

12:33 am on Oct 11, 2004 (gmt 0)

10+ Year Member



Dreamcatcher...

Thankyou so much! It worked perfectly!

Senmar

 

Featured Threads

Hot Threads This Week

Hot Threads This Month