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 May 13th, 2004, 12:00 PM
stany stany is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 1 stany User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cant display text box in Php form connecting to mySQL

hi everyone..im a new member from Ireland..I have a problem with my php code. Everything works fine and im getting infromation back from the mySQL database but now I have written code to insert into the database. This code is correct and im not gettin any errors. The problem is a simple one in that i cant get my text box to display itself when I load the page. I have the simle code for a textbox but it wont appear.
I cant find the reason why. Everthing else is okay..any suggestions and i would be delighted..i posted the code below so please have a look and let me know..thank you
Code:
<HTML>
<BODY>
<?php
//If the user wants to add a contact 
 
if (isset($addcontact)):
?>
 
<FORM ACTION="?php echo($PHP_SELF); ?" METHOD=POST>
  Type your contact here:<BR>
    <input type="text" name="contacttext">
    <BR>
    <INPUT TYPE=SUBMIT NAME="submitcontact" VALUE="SUBMIT">
</FORM>
 
<?php  
else:
    // Connect to the database server  
  
 $dbcnx = @mysql_connect("localhost",             
    "","");   

if (!$dbcnx) {      
 echo( "<P>Unable to connect to the " .            
  "database server at this time.</P>" );   

 exit();    
}
    // Select the contacts database

 if (! @mysql_select_db("contacts") ) { 
     
 echo( "<P>Unable to locate the joke " .            
  "database at this time.</P>" ); 
     
 exit();    
}
    // If acontact has been submitted,    
    // add it to the database.    
 
if ("SUBMIT" == $submitcontact) {      
 $sql = "INSERT INTO contacts SET " .             
  "ConSurname='$contacttext'";  

if (mysql_query($sql)) {        
 echo("<P>Your contact has been added.</P>"); 
     
} else 
{ 
       
 echo("<P>Error adding submitted contact: " .             
  mysql_error() . "</P>");      
 }    
}      
echo("<P> Here are all the contacts " .         
 "in our database: </P>");      
 
// Request the text of all the jokes   
  $result = mysql_query(              
   "SELECT ConSurname FROM contacts");    
 if (!$result) {      
 echo("<P>Error performing query: " .           
 mysql_error() . "</P>");      

 exit();    
 }      
 
// Display the text of each contacts in a paragraph    
while ( $row = mysql_fetch_array($result) ) {      
echo("<P>" . $row["ConSurname"] . "</P>");    
}   

// When clicked, this link will load this page    
// with the contact submission form displayed.    

echo("<P><A HREF='$PHP_SELF?addcontact=1'>" .         
 "Add a Contact!</A></P>");

endif;
?>
</BODY>
</HTML>

Last edited by stumpy : May 13th, 2004 at 08:59 PM. Reason: Moved to the PHP, err, Open Source forum. Please place all code in CODE tags

Reply With Quote
  #2  
Old May 13th, 2004, 02:08 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Works ok for me. I dropped all the db stuff so I wouldn't get those errors. When I click the "Add contact" link, the text box displays with no problem.

Reply With Quote
  #3  
Old May 14th, 2004, 06:34 AM
Spongy's Avatar
Spongy Spongy is offline
Alternately High
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Hilversum, Netherlands
Posts: 223 Spongy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 56 m 41 sec
Reputation Power: 5
Send a message via MSN to Spongy
Quote:
Originally Posted by stany
Code:
<FORM ACTION="?php echo($PHP_SELF); ?" METHOD=POST>

Is it me, or is this just not possible...
I suggest to change it to:
Code:
<form action="<?php echo($PHP_SELF); ?>" method="post">
__________________
Work to live, don't live to work

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Cant display text box in Php form connecting to mySQL


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