homepage Welcome to WebmasterWorld Guest from 54.167.75.155
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Inserted Data..does not show in Database
Senmar50




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

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




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

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




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

Dreamcatcher...

Thankyou so much! It worked perfectly!

Senmar

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved