MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 15th, 2005, 07:27 PM
anti2 anti2 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 13 anti2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 17 m 14 sec
Reputation Power: 0
insert problem

i am using suse 9.2, php 4.4.8-8.3, mySQL 4-0.21-4.2, apache 2.0.50-7.2. when i run the code below and i press the button no data added in the database. i don't know what the problem because if i run select command it can display the data in the database. that's mean that my connection is OK. can anyone help me please? thanks.
PHP Code:
<html>
<
body>
<?
php
if ($submit) { 
// process form $db = mysql_connect("localhost", "root"); 
mysql_select_db("mydb",$db); 
$sql "INSERT INTO employees (first,last,address,position) VALUES ('$first','$last','$address','$position')"
$result mysql_query($sql); 
echo 
"Thank you! Information entered.\n";
} else{ 
// display form 
?> 
<form method="post" action="<?php echo $PHP_SELF?>"> 
First name:<input type="Text" name="first"><br> 
Last name:<input type="Text" name="last"><br> 
Address:<input type="Text" name="address"><br> 
Position:<input type="Text" name="position"><br> 
<input type="Submit" name="submit" value="Enter information"> 
</form> 
<?php
// end if
?>
</body>
</html> 

Reply With Quote
  #2  
Old March 16th, 2005, 09:19 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
I suspect it's a problem with your query.

Try modifying the following line as indicated:
PHP Code:
 $result mysql_query($sql) or die("There was an error inserting into MySQL! ".mysql_error()."<br>\nThe SQL was: ".$sql); 
Comments on this post
Madpawn agrees!

Reply With Quote
  #3  
Old March 16th, 2005, 07:25 PM
anti2 anti2 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 13 anti2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 17 m 14 sec
Reputation Power: 0
still problem, i think it's the loop

Quote:
Originally Posted by MadCowDzz
I suspect it's a problem with your query.

Try modifying the following line as indicated:
PHP Code:
 $result mysql_query($sql) or die("There was an error inserting into MySQL! ".mysql_error()."<br>\nThe SQL was: ".$sql); 


thanks madcowdzz but when i change it nothing happen. the thing with my code is it don't go to the if loop, that's why it don't process my query. is it because of my php, mySQL or apache problem? is there anything i can do to make sure that my setting for those 3 things is correct? i really stumped by this problem, i can't go further to explore this knowledge. please anyone help me with this.

Reply With Quote
  #4  
Old March 29th, 2005, 03:34 AM
boots boots is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 1 boots User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 14 sec
Reputation Power: 0
I normally trouble shoot "IF" statements like this wth two easy ways:

1. before the if put a
PHP Code:
print $submit


2. inside the loop
PHP Code:
print "now inside loop"


after this you will see what is going on with your if loop and if it is executing.

Reply With Quote
  #5  
Old March 29th, 2005, 08:44 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
If you aren't entering the IF loop then $submit isn't being set.
boots' suggestions are great, and try them first.

I suspect the $submit variable is being passed to your PHP from a form?
Do you know if you have super globals turned on or off?
[usually turned on by default]

Try this:
$submit = $_GET['submit'];

(or use $_POST if your form's method is post)

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > insert problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT