Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Adding data to SQL database
Old 08-22-2009, 10:56 PM Adding data to SQL database
Average Talker

Posts: 27
Trades: 0
Ok so I made a simple forum thing, but the problem is that users cannot post replies since my code does not seem to allow them to add anything to the database. Here is my code after they press submit

<?php
session_start();
function quote_smart($value)
{
$value = stripslashes($value);
if (!is_numeric($value))
$value = "'" . mysql_real_escape_string($value) . "'";
return $value;
}
include("../common.php");
?>

<?php
$uname = $_SESSION['name'];
$com = $_POST['comments'];

$uname = htmlspecialchars($uname);
$com = htmlspecialchars($com);

$user_name = "root";
$pass_word = "";
$database = "TestForum";
$server = "127.0.0.0";

$db_handle = mysql_connect($server, $user_name, $pass_word);
$db_found = mysql_select_db($database, $db_handle);

if($db_found)
{
$uname = quote_smart($uname, $db_handle);
$com = quote_smart($com, $db_handle);

$SQL = "INSERT INTO forum (name, reply) VALUES($uname, $answer)";
$result = mysql_query($SQL);
mysql_close($db_handle);
confirm("ALL DONE");
}
else
{
confirm ("Database NOT Found ");
mysql_close($db_handle);
}
?>

The confirm function is included in the common.php and all it does is pop out alert box with said message. Now whenever I run this script on my web I get the ALL DONE message every time, but upon checking the database table I see absolutely nothing added. I tried absolutely anything and nothing seems to work. Any help?
(I changed the username, password, database and server name just for security purpose so that's not the error).

Thanks a lot for the help in advance
__________________
Those who can: learn. Those who can't: teach.
Cinatas is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-22-2009, 11:17 PM Re: Adding data to SQL database
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
You error is in the insert query, as it requires for the insert values to be quoted:

$SQL = "INSERT INTO forum (name, reply) VALUES('$uname', '$answer')";
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 08-22-2009, 11:18 PM Re: Adding data to SQL database
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
By the way - Where is $answer coming from? Maybe you should use $com
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 08-23-2009, 12:58 AM Re: Adding data to SQL database
Average Talker

Posts: 27
Trades: 0
Thanks I did that but still seems not to work. Is there a tutorial you can suggest which explains how to add data to db.
__________________
Those who can: learn. Those who can't: teach.
Cinatas is offline
Reply With Quote
View Public Profile
 
Old 08-23-2009, 05:19 AM Re: Adding data to SQL database
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Are you getting any errors or warnings? Have you turned all warnings on? Also check for errors from mysql_error().

I also see that you're calling your quote_smart() function with two attributes, whereas the function only takes one.
__________________
34343639363436653237373432303635373837303635363337 34323037343638363137343263323036343639363432303739 366637353366
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Reply     « Reply to Adding data to SQL database
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.60275 seconds with 12 queries