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
Problem inserting to mysql with php
Old 01-15-2005, 08:27 PM Problem inserting to mysql with php
Experienced Talker

Posts: 36
Trades: 0
Hey, got myself a tiny bit of a problem it seems. Im trying to insert a value from a section chooser drop down, but instead of inserting only the section i choose from the drop down, it inserts all the sections (if i have 1 section it selects the right section and add the data, but if i create another section it adds the data twice, one for each section).

here is the form:
PHP Code:
<form name="news" method="post" action="add_news.php">
Title:<input type="text" name="ntitle" maxlength="255"><br>
Section:<select name="section" id="section">
<?php
$result 
$connector->query('SELECT sid, sname FROM nsection ORDER BY sname');
echo 
mysql_error();
while (
$row $connector->fetchArray($result)) {
    echo 
'<option value"'.$row['sid'].'">'.$row['sname'].'</option>';
    }
?>
</select><br>
News:<textarea name="nnews" cols="50" rows="6" id="nnews"></textarea><br>
<input type="submit" name="PostNews" value="Submit">
<input type="reset" name="reset" value="Clear"></form>
and here is the query inserting the values:
PHP Code:
$nip $_SERVER['REMOTE_ADDR'];
$ntitle $_POST['ntitle'];
$nnews $_POST['nnews'];
$section $_POST['section'];


$insertQuery = ("INSERT INTO news VALUES ( NULL , '$nip', '$ntitle', '$nnews', '$section', NOW() )");

if (
$result $connector->query($insertQuery)) {
    
    echo (
'News succesfully added');
    
    }else{
    
    echo 
mysql_error(); 
The Section db contains of 3 tables wich are " sid, sname, parentid ", section is the id column in the table im inserting to.

hope anyone can help me out, im loosing hair rapidly now after a few days pusling with this lol

Thanks in advance
Lazyleg

Last edited by Lazyleg; 01-15-2005 at 08:30 PM..
Lazyleg is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-16-2005, 12:58 PM
Experienced Talker

Posts: 40
Trades: 0
I dont see a class being loaded with an alias of $connector, where is this being loaded?

Dan
iFuse is offline
Reply With Quote
View Public Profile
 
Old 01-16-2005, 02:25 PM
Experienced Talker

Posts: 36
Trades: 0
the problem isnt with the instance of the class, or the class itself, cuz the values is beeing inserted, its only that it inserts all the available values from the dropdown menu, instead of the one i choose from the drop down menu. i have cut down the code here cuz i didnt want to bother you with going through code that works.

Also after i droped storing $_POST['section'] in $section and just added to the query

PHP Code:
$insertQuery = ("INSERT INTO news VALUES ( NULL , '$nip', '$ntitle', '$nnews', '".$_POST['section']."', NOW() )"); 
it wanted to store the name of the section rather then the id, so im not sure if the value past by $_POST is the right value at all, and while storing it into a variable it seems it also inserts the name of the section rather then the id, so i think the problem is with the form, but i cant find out where.

Last edited by Lazyleg; 01-16-2005 at 02:42 PM.. Reason: forgot a thing
Lazyleg is offline
Reply With Quote
View Public Profile
 
Old 01-18-2005, 06:53 AM
Experienced Talker

Posts: 36
Trades: 0
Problem solved
Lazyleg is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Problem inserting to mysql with php
 

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.17870 seconds with 12 queries