Jump to content

Recommended Posts

I have MySQL client version: 5.0.37, running with PHPmyAdmin.

 

I created a database, and a table inside of it, which I want data from an HTML form to be sent to and saved. On submit the data from the form goes to "insert.php" which looks like this:

<?
$username="myuser";
$password="mypass";
$database="dbname";

$first=$_POST['first'];
$last=$_POST['last'];
$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state'];
$zipcode=$_POST['zipcode'];
$phone=$_POST['phone'];
$cell=$_POST['cell'];
$email=$_POST['email'];
$age=$_POST['age'];
$weight1=$_POST['weight1'];
$height1=$_POST['height1'];
$grade=$_POST['grade'];
$position=$_POST['position'];
$school=$_POST['school'];
$coach=$_POST['coach'];

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO registration VALUES ('','$first','$last','$address','$city','$state','$zipcode','$phone','$cell','$email','$age','$weight1','$height1','$grade','$position','$school','$coach')";
mysql_query($query);

mysql_close();
?>
<html>
<body>
<p>Submit Successful</p>
</body>
</html>

The file works somewhat because I get the "Submit Successful" message back but when I check the Database, nothing is there.

 

The table is called Registration and looks like:

 

registration
Field Type Null Default 
id  int(4) No      
first  varchar(20) No      
last  varchar(20) No      
address  varchar(30) No      
city  varchar(20) No      
state  varchar(15) No      
zipcode  varchar(10) No      
phone  varchar(15) No      
cell  varchar(15) No      
email  varchar(25) No      
age  varchar(10) No      
weight1  varchar(15) No      
height1  varchar(20) No      
grade  varchar(10) No      
position  varchar(20) No      
school  varchar(25) No      
level  varchar(20) No      
coach  varchar(30) No    

 

I am confident the problem lies in the "insert.php" file but I haven't a clue what that problem is, any help? Thank you.

Link to comment
https://forums.phpfreaks.com/topic/90598-html-form-data-wont-save-on-database/
Share on other sites

// create query

$query = "INSERT INTO registrations (id, first, last, ) VALUES ('', '$first', $last', '$address', '$city', '$state', '$zipcode', '$phone', '$cell', '$email', '$age', '$weight1', '$height1', '$grade', '$position', '$school', '$coach')";

 

You forgot to put the field names from the table in after the registrations.

 

I started, you should be able to finish it, just keep adding you fields with commas separating.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.