Insert into db problem

This is a discussion on "Insert into db problem" within the PHP Forum section. This forum, and the thread "Insert into db problem are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Nov 13th, 2005, 16:17
Junior Member
Join Date: Aug 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Insert into db problem

I have 3 tables and i want to insert some values to one where $iid in 3rd table needs to be the same as $id in first table.
I have a form which visitors can post their comments. The default value is 0 so i can submit them to be displayed.
Here is the code and the form
HTML: Select all
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());
$sorgu= 'select * from icerik WHERE id='.$_GET["id"];
$gelen = mysql_query($sorgu); 
$sonuc = mysql_fetch_array($gelen);
$kategorisi = $uc['id'];
if(!$_POST["gonder"]) 
{ 
$yorum= "insert into yorumlar VALUES('$id','$iid','$isim','$email','$sehir','$yas','$yorum','$tarih','$durum') where iid=".$kategorisi;
$veri_gir = mysql_query ($veri);
} 
echo '<form method="POST">';
echo '<table width="500" class="yorumgonder"><tr>';
echo '<td width="211">Adınız Soyadınız / Rumuzunuz</td><td width="28">:</td><td width="261">';
echo '<input type="text" name="isim" size="40" class="input"></td></tr><tr>'; 
echo '<td width="211">E-mail adresiniz</td><td width="28">:</td><td width="261">'; 
echo '<input type="text" name="email" size="40" class="input"></td></tr><tr>'; 
echo '<td width="211">Şehir</td><td width="28">:</td><td width="261">'; 
echo '<input type="text" name="sehir" size="40" class="input"></td></tr><tr>'; 
echo '<td width="211">Yaşınız</td><td width="28">:</td><td width="261">'; 
echo '<input type="text" name="yas" size="40" class="input"></td></tr><tr>'; 
echo '<td width="211">Yorumunuz</td><td width="28">:</td><td width="261">'; 
echo '<textarea name="yorum" cols="40" rows="10" class="input"></textarea></td></tr><tr>';
echo '<td width="211">&nbsp;</td><td width="28">&nbsp;</td><td width="261">';
echo '<input type="submit" name="Submit" value="Gönder" class="submit"></td></tr></table>'; 
echo '</form>'; 
I can print the id and get it no problem with it. But i can't insert the comment into db. Help pls. Tnx.

Last edited by Rob; Nov 13th, 2005 at 18:04.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Nov 13th, 2005, 18:58
Most Reputable Member
Join Date: Aug 2005
Location: North Wales, United Kingdom
Age: 21
Posts: 1,093
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Insert into db problem

I dont understand your code, you have not declared any of your values to insert in the db :S
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Nov 13th, 2005, 19:27
Junior Member
Join Date: Aug 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Insert into db problem

How can i? Please write it's code.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Nov 13th, 2005, 19:59
Most Reputable Member
Join Date: Aug 2005
Location: North Wales, United Kingdom
Age: 21
Posts: 1,093
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Insert into db problem

You have said to the script. insert the following values $id $iid etc. into the table but you have not declared what those values are.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Nov 13th, 2005, 21:10
Junior Member
Join Date: Aug 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Insert into db problem

id is in table1 and iid is in table 2. The problem is iid needs to be the same as the id. With the form i am getting the values and trying to insert them but i couldnt find a way to write this : insert all the data you get from the form and insert this comment's iid as id.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Nov 13th, 2005, 23:41
Junior Member
Join Date: Aug 2005
Location: Colchester
Age: 28
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Insert into db problem

You have no action on your form either. you need to post the data somewhere.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Nov 14th, 2005, 00:49
Most Reputable Member
Join Date: Aug 2005
Location: North Wales, United Kingdom
Age: 21
Posts: 1,093
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Insert into db problem

If your using the same id why dont u just use the same variable? :O

Ill post an example of inputting info into a database tomorrow.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Nov 15th, 2005, 01:51
Most Reputable Member
Join Date: Aug 2005
Location: North Wales, United Kingdom
Age: 21
Posts: 1,093
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Insert into db problem

Say i had a database with a table named test and had 3 fields name, email and url and i wanted to enter some information into this table.

The following is the php code with discussion on how it works below it.
PHP: Select all

<?php
// This is my database connection in order to connect to my server.
include ("db-connection.php");

// Here i define the variables i want to entr into the table. The variables can be generated dynamically or manually as long as the variables are defined how you generate them doesn't matter in this exercise
$name='sypher';
$email='testing.@testing.com';
$url='www.sypher-design.co.uk';

// My db function. Inserting the above variables above into the requied fields by stating the fields then the values.
$query "INSERT INTO test (name, email, url) VALUES ('$name','$email','$url')";

// This activates the above function.
mysql_query($query);

// Closing the mysql connection to reduce security and sessions.
mysql_close();

// Shows success message
echo "Entry Added"
?>

Last edited by sypher; Nov 15th, 2005 at 01:55.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
insert, problem

« Geekmas | .htaccess »
Thread Tools

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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Code insert into database problem longstand PHP Forum 7 Oct 13th, 2007 22:03
Asp.net insert to mysql problem boyindie ASP.NET Forum 1 Aug 24th, 2007 02:00
Problem with insert into the database kool77 PHP Forum 3 Jun 4th, 2007 19:21
SQL Insert help air duster Classic ASP 13 Jan 12th, 2006 08:38
Insert Record redkyna Classic ASP 11 Aug 25th, 2004 22:46


All times are GMT. The time now is 16:28.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42