Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to php - getting php to work with mysql

Status
Not open for further replies.

mrasad

Technical User
Nov 16, 2003
53
GB
Hi guys,

I''m having a problem. I have created a very simple test database (one table, four fields), problem is i can't get php to write stuff to the database when completing details in a browser.

Below is my code.

Code - a user would need to complete when registering with a school;
------------------------------------------------------------
<?
include('header.inc');
include("mysql_connect");
?>

<h2>Enter a New userinfo1</h2>

<form name=formone method=post action="insertuserinfo1.php">
<table>

<tr height=30 valign=top>
<td align=right><b>Username :</b></td>
<td>
<input type="text" name="usernameField">
</td>
</tr>


<tr height=30 valign=top>
<td align=right><b>Firstname :</b></td>
<td>
<input type="text" name="firstnameField">
</td>
</tr>


<tr height=30 valign=top>
<td align=right><b>Lastname :</b></td>
<td>
<input type="text" name="lastnameField">
</td>
</tr>


<tr height=30 valign=top>
<td align=right><b>Email :</b></td>
<td>
<input type="text" name="emailField">
</td>
</tr>

</table>

<input type=submit name=Submit value="Submit">
<input type=reset name=Submit2 value="Reset">
</form>


<?
include('footer.inc');
?>

----------------------------------------------------------
This form is then sent to insertuserinfo1.php - code below;
----------------------------------------------------------
<?
include('header.inc');
include("mysql_connect");
?>

<?

$query="insert into userinfo1 (username,firstname,lastname,email) VALUES ('$usernameField','$firstnameField','$lastnameField','$emailField')";

$result = MYSQL_QUERY($query);



?>

<H2>New User Created , well done!!</H2>

<table>
<tr height=30>
<td align=right><b>Username :</b></td>
<td><font color=blue><b><? echo $usernameField; ?></font></b></td>
</tr>
<tr height=30>
<td align=right><b>Firstname :</b></td>
<td><font color=blue><b><? echo $firstnameField; ?></font></b></td>
</tr>
<tr height=30>
<td align=right><b>Lastname :</b></td>
<td><font color=blue><b><? echo $lastnameField; ?></font></b></td>
</tr>
<tr height=30>
<td align=right><b>Email :</b></td>
<td><font color=blue><b><? echo $emailField; ?></font></b></td>
</tr>
</table><br><br>
Click <a href="user.php">here</a> to go back to Main Menu

<?
include('footer.inc');
?>
---------------------------------------------------------

Why can I not get it to work? Can anyone help?
 
Hello mrasad,

When you want to save information via a php file you must use:

<form action="gastbook.php" method="get">
or
<form action="gastbook.php" method="post">

In "gastbook.php" you can fill the table with information.

Michelle.
 
I have a FAQ in this forum, faq434-2999. That FAQ has a section on register_globals (which might be part of your issue) as well as a section on debugging database code.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top