
May 13th, 2004, 12:00 PM
|
|
Registered User
|
|
Join Date: May 2004
Posts: 1
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
|