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:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old April 17th, 2003, 11:02 AM
mjulson mjulson is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 3 mjulson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
PHP and MySQL: The Basics -problem

I was reading the PHP and MySQL: The Basics article here at DevArticles located at URL

And I got to the point of inserting data into the database. I get the message back that the data was entered, but it's not in the database. I don't get any errors. Any thoughts what might be going on?

Here's the code from the article.

Code:
<html> 

<body> 

<?PHP

if ($submit) { 

// process form 

$db = mysql_connect("localhost", "root"); 

mysql_select_db("mydb",$db);

$sql = "INSERT INTO address (name,,address,hnum,wnum) VALUES ('$name','$address','$hnum','$wnum')";

$result = mysql_query($sql); 

echo "Thank you! Information entered.\n"; 

} else{

// display form 

?>

<form method="post" action="<?PHP echo $PHP_SELF?>"> 

Name:<input type="Text" name="name"><br> 

Address:<input type="Text" name="address"><br> 

Home Number:<input type="Text" name="hnum"><br> 

Work Number:<input type="Text" name="wnum"><br> 

<input type="Submit" name="submit" value="Enter information">

</form> 

<?PHP 

} // end if

?>

</body> 

</html>

Reply With Quote
  #2  
Old April 17th, 2003, 12:21 PM
ignitionMX ignitionMX is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 13 ignitionMX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 3 sec
Reputation Power: 0
Send a message via ICQ to ignitionMX
Did you leave out your mysql information purposely or is that the problem?

Reply With Quote
  #3  
Old April 17th, 2003, 01:39 PM
mjulson mjulson is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 3 mjulson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by ignitionMX
Did you leave out your mysql information purposely or is that the problem?


What information is that?

The only thing different in my code, is that I specified the password.

Reply With Quote
  #4  
Old April 17th, 2003, 03:21 PM
Vasarab69 Vasarab69 is offline
Goldmember
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 71 Vasarab69 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 25 sec
Reputation Power: 6
Send a message via AIM to Vasarab69
well, i'm not sure if this is the problem but...you have two comma's in your query, where there should be one

if it is, then change:

PHP Code:
 $sql "INSERT INTO address (name,,address,hnum,wnum) VALUES ('$name','$address','$hnum','$wnum')"


to

PHP Code:
 $sql "INSERT INTO address (name,address,hnum,wnum) VALUES ('$name','$address','$hnum','$wnum')"


Also...to make sure that there were no problems with the entering of data, you can change:

PHP Code:
 $result mysql_query($sql); 

echo 
"Thank you! Information entered.\n"


to

PHP Code:
 $result mysql_query($sql); 

if(
$result) {

echo 
"Thank you! Information entered.\n"

} else {

echo 
"We're sorry, there was a problem with the data you entered!";
echo 
"<br>";
echo 
"Please go <a href="javascript:history.go(-1)">back</a> and re-enter it, Thank you.";


__________________
-Alexander

Reply With Quote
  #5  
Old April 17th, 2003, 05:01 PM
torrent torrent is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 19 torrent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Change this:
PHP Code:
 $result mysql_query($sql); 
to this...
PHP Code:
 $result mysql_query($sql) or die(mysql_error()); 
This will show up any errors.

Reply With Quote
  #6  
Old April 17th, 2003, 06:16 PM
mjulson mjulson is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 3 mjulson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Ah, I didn't even notice that. It was cut and pasted from the article here. So if an admin is watching, you might want to change that.

I'll give it a try later tonight to see if that's the problem.

Thanks for catching it.

Mike

Reply With Quote
  #7  
Old April 17th, 2003, 10:19 PM
Vasarab69 Vasarab69 is offline
Goldmember
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 71 Vasarab69 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 25 sec
Reputation Power: 6
Send a message via AIM to Vasarab69
No problem! Glad to help...if you still are recieving errors, post back here and I'll do all i can

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > PHP and MySQL: The Basics -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 4 hosted by Hostway