problem with inserting data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
smileboy
Forum Newbie
Posts: 20
Joined: Wed Mar 11, 2009 6:58 am
Location: Tashkent, Uzbekistan

problem with inserting data

Post by smileboy »

hi, i was creating website which has database and having problem on adding
my php code for adding is not working [don't know why]
when i press add button, it is showing white screen. nothing else

here is some info about my database

two tables: title and words
in title, fields: id and word
in words, fields :id, title, descr, example, synonim, user

here is the code for add.php

Code: Select all

 
<?php
 
mysql_connect("*********", "*****", "**************") or die(mysql_error());
mysql_select_db("*************") or die(mysql_error());
 
if (isset($_POST['add']))
{
 
    $sql = "INSERT INTO words (title, descr, example, synonim, user) VALUES ('$_POST[title]', '$_POST[descr]', '$_POST[example]', '$_POST[related]', '$_POST[user]')";
        $result = mysql_query($sql);
        $check_title = mysql_query("select*from title where word='$_POST['title']");
        $rows = mysql_num_rows($check_title);
        echo $rows;
    if ($rows==0)
    {
        $sql = "INSERT INTO title (word) VALUES ('$_POST[title]')";
        $result = mysql_query($sql);
    } else {}
}
 
?>  
<html>
<head><title>Added</title></head>
<link href="css/graffiti.css" rel="stylesheet" type="text/css">
<body>
<div id="wrapper">
<div id="header">
    <p id="home">
    <a href="index.php">Jargon.uz</a>
    </p>
</div>
        
<div id="navigation">
    <p id="menu">
        
    <?php
    foreach (range('A', 'Z') as $letter)
    {
            echo '<a href="az.php?category='.$letter.'">'.$letter.'</a> ';
        }
    ?>
 
    ::&nbsp;&nbsp;<a href="all.php">xamma so`zlar</a> &nbsp;<a href="random.php">tasodifiy</a> :: <a href="add.html">kirit</a> &nbsp;<a href="chat.php">chat</a> &nbsp;<a href="themes.html">temalar</a>
    </p>
</div>
 
<div id="leftcolumn">leftcol</div>
<div id="content">
<center>Your data has been added successfully!</center>
</div>
<div id="footer">footer</div>
 
<div id="about">
    <center>
        <p id="copyright">
        Jargon.uz &copy; 2009 [project of Akmal] :: <a href="aboutus.html">sayt haqida</a>&nbsp; <a href="fq.html">foydalanish qoidalari</a> &nbsp;<a href="svt.php">savol va takliflar</a> &nbsp;<a href="ads.html">reklama</a>
            
        </p>
    </center>
</div>
 
</div>
</body>
</html>
 
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: problem with inserting data

Post by requinix »

Code: Select all

$sql = "INSERT INTO words (title, descr, example, synonim, user) VALUES ('$_POST[title]', '$_POST[descr]', '$_POST[example]', '$_POST[related]', '$_POST[user]')";

Code: Select all

$check_title = mysql_query("select*from title where word='$_POST['title']");
You did it right in the first one but not in the second. Take a look.
smileboy
Forum Newbie
Posts: 20
Joined: Wed Mar 11, 2009 6:58 am
Location: Tashkent, Uzbekistan

Re: problem with inserting data

Post by smileboy »

oh, think i got it.
is it should be dis way?

Code: Select all

 
$check_title = mysql_query("select*from title where word=[color=#4000FF]'$_POST[title]' [/color]");
 
i've just checked that. it's working all fine

thanks a lot.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: problem with inserting data

Post by requinix »

smileboy wrote:oh, think i got it.
is it should be dis way?
There are three ways.

Code: Select all

// concatenation
$variable = "First half " . $variable["key"] . " second half";
 
// embedding with {}s - keep the quotes, just like above
$variable = "First half {$variable["key"]} second half";
// (the highlighting is a little weird but the code is correct)
 
// embedding without {}s - no quotes
$variable = "First half $variable[key] second half";
Post Reply