Jump to content

phpMyAdmin/MySQL problems (NEWBIE)


ninedoors

Recommended Posts

I have written a script to insert data I get from a form on my website that users fill out.  The script works fine the first time and then when I go to submit a second form I get an error.  Is there some kind of function that I have turned on that limits the space in each database?  I have created a couple databases under the same user name and the work fine.  This database has 10 fields and checks to make 2 of them are unique.  I am lost as I have been killing myself over this for two days.  Can anyone please help me?

 

Nick

Link to comment
Share on other sites

Wildbug,

 

I get an error message that I created in the script.  This tells me that it connected to the database but was unable to load in the data.  Here is the code:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php

$host="localhost"; // Host name 
$username="*********";MySQL username
$password="*********"; MySQL password
$db_name="********info"; // Database name 
$tbl_name="reg"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// Get values from form 
$name=$_POST['fullname'];
$email=$_POST['email'];
$address=$_POST['address'];
$city=$_POST['city'];
$postalcode=$_POST['postalcode'];
$phone=$_POST['phonenum'];
$signup=$_POST['signup'];
$position=$_POST['position'];
$hockeylevel=$_POST['hockeylevel'];

//Check to see if values already exist in the database
$check= mysql_query("SELECT FullName FROM $tbl_name WHERE FullName = '$name'");
$returned = mysql_fetch_array($check);
if(!empty($returned))	{
					header("Location: error-nameexists.php");
					mysql_close();
					Die();
					}
					else 	{
							//Check to see if email exists in the database
							$check = mysql_query("SELECT Email FROM $tbl_name WHERE Email = '$email'");
							$returned = mysql_fetch_array($check);
							if(!empty($returned))	{
													header("Location: error-emailexists.php");
													mysql_close();
													Die();
													}
													else 	{
															// Insert data into mysql 
															$sql="INSERT INTO $tbl_name(FullName, Email, Address, City, PhoneNum, PostalCode, SignUp, Position, HockeyLevel)VALUES('$name', '$email', '$address', '$city', '$phone', '$postalcode', '$signup', '$position', '$hockeylevel')";
															$result=mysql_query($sql);

															// if successfully insert data into database, displays message. 
															if($result)	{

																		header("Location: reg-submit.php");
																		mysql_close();
																		Die();

																		}

																		else 	{
																				echo "ERROR";
																				}
															}
							}

// close connection 
mysql_close();
?>
</body>
</html>

 

The error I get is the one you see at the bottom (echo "ERROR";)

 

Like I said it works perfect this first time.  I am using phpmyAdmin for the DB management and am new to that as well.  Anything you can think of why it does this.  I have also tested it to see if it is connecting to the DB and it does because if I enter a name or email that is already in the DB(the only there) then I am sent to my error-nameexists.php page.  Hope this gives you a little more info.

 

Nick

Link to comment
Share on other sites

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.