Alby
12-13-2009, 08:45 PM
Hi,
I am trying to set up a page where people can register and it will be stored in mysql database and then another page that outputs the information and confirms that they had registered. Pretty simple right? Right now I am testing on my computer using XAMPP. I have one file "register.php" that has the forms for the user to register and another "handleinput.php" that should store the data and output. It is not working and it appears that
mysql_query($query)or die(mysql_error); is the line where I am running into issues. My website is accessable through my browser at http://puttforpresents.local, I want my database to be named pfp and my table to be named golfers. I need to store first name, last name, email, phone, and handicap. I am trying to have a unique identifier associated with each listing in the table. Please help me identify my issue.
register.php code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Putt for Presents</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php include('header.php'); ?>
<div id="registrationtitles">
<h2>First Name:</h2>
<h2>Last Name:</h2>
<h2>E-mail:</h2>
<h2>Phone:</h2>
<h2>Handicap:</h2>
<h2>Select your team:</h2>
</div>
<div id="registrationinputs">
<form id="register" name="register" method="post" action="handleinput.php">
<input type="hidden" name="id" value="NULL">
<input type="text" name="firstname" id="firstname" /><br />
<input type="text" name="lastname" id="lastname" /><br />
<input type="text" name="email" id="email" /><br />
<input type="text" name="phone" id="phone" /><br />
<select name="handicap" size="1" id="handicap">
<option>0</option>
<option>5</option>
<option>10</option>
<option>15</option>
<option>20</option>
<option>25</option>
</select>
<p><br />
<br>
<input name="submit" type="submit" value="Submit" />
</form>
</div>
</body>
</html>
handleinput.php code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Putt for Presents</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<p><img src="img/PuttforPresentsLogo.jpg" width="625" height="200" alt="PFP Logo" />
<p>
<?php include('dbconnect.php'); ?>
<?php
//set local variables
$dbhost = "puttforpresents.local";
$dbuser = "root";
$dbpass = "";
$dbname = "pfp";
$table = "golfers";
//connect
$con = mysql_connect($dbhost,$dbuser,$dbpass) or die( "Unable to connect to database");
@mysql_select_db($dbname, $con) or die( "Unable to select database");
//create table
$sql = "CREATE TABLE $table (
id INT NOT NULL AUTO_INCREMENT,
firstname VARCHAR (50),
lastname VARCHAR (50),
email VARCHAR (50),
phone VARCHAR (30),
PRIMARY KEY (id)
)";
//populate entry into table
$query = "INSERT INTO $table VALUES('$id','$firstname','$lastname','$email','$phone')";
mysql_query($query)or die(mysql_error);
mysql_close($con);
//export results
print "<HTML><TITLE> PHP and MySQL </TITLE><BODY
BGCOLOR=\"#FFFFFF\"><center><table border=\"0\"
width=\"500\"><tr><td>";
print "<p><font face=\"verdana\" size=\"+0\"> <center>You
Just Entered This Information Into the
Database<p><blockquote>";
print "Name : $firstname<p>Last Name :
$lastname<p>E-Mail : $email</blockquote></td></tr></table>
</center></BODY></HTML>";
?>
?>
</p>
</body>
</html>
I am trying to set up a page where people can register and it will be stored in mysql database and then another page that outputs the information and confirms that they had registered. Pretty simple right? Right now I am testing on my computer using XAMPP. I have one file "register.php" that has the forms for the user to register and another "handleinput.php" that should store the data and output. It is not working and it appears that
mysql_query($query)or die(mysql_error); is the line where I am running into issues. My website is accessable through my browser at http://puttforpresents.local, I want my database to be named pfp and my table to be named golfers. I need to store first name, last name, email, phone, and handicap. I am trying to have a unique identifier associated with each listing in the table. Please help me identify my issue.
register.php code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Putt for Presents</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php include('header.php'); ?>
<div id="registrationtitles">
<h2>First Name:</h2>
<h2>Last Name:</h2>
<h2>E-mail:</h2>
<h2>Phone:</h2>
<h2>Handicap:</h2>
<h2>Select your team:</h2>
</div>
<div id="registrationinputs">
<form id="register" name="register" method="post" action="handleinput.php">
<input type="hidden" name="id" value="NULL">
<input type="text" name="firstname" id="firstname" /><br />
<input type="text" name="lastname" id="lastname" /><br />
<input type="text" name="email" id="email" /><br />
<input type="text" name="phone" id="phone" /><br />
<select name="handicap" size="1" id="handicap">
<option>0</option>
<option>5</option>
<option>10</option>
<option>15</option>
<option>20</option>
<option>25</option>
</select>
<p><br />
<br>
<input name="submit" type="submit" value="Submit" />
</form>
</div>
</body>
</html>
handleinput.php code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Putt for Presents</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<p><img src="img/PuttforPresentsLogo.jpg" width="625" height="200" alt="PFP Logo" />
<p>
<?php include('dbconnect.php'); ?>
<?php
//set local variables
$dbhost = "puttforpresents.local";
$dbuser = "root";
$dbpass = "";
$dbname = "pfp";
$table = "golfers";
//connect
$con = mysql_connect($dbhost,$dbuser,$dbpass) or die( "Unable to connect to database");
@mysql_select_db($dbname, $con) or die( "Unable to select database");
//create table
$sql = "CREATE TABLE $table (
id INT NOT NULL AUTO_INCREMENT,
firstname VARCHAR (50),
lastname VARCHAR (50),
email VARCHAR (50),
phone VARCHAR (30),
PRIMARY KEY (id)
)";
//populate entry into table
$query = "INSERT INTO $table VALUES('$id','$firstname','$lastname','$email','$phone')";
mysql_query($query)or die(mysql_error);
mysql_close($con);
//export results
print "<HTML><TITLE> PHP and MySQL </TITLE><BODY
BGCOLOR=\"#FFFFFF\"><center><table border=\"0\"
width=\"500\"><tr><td>";
print "<p><font face=\"verdana\" size=\"+0\"> <center>You
Just Entered This Information Into the
Database<p><blockquote>";
print "Name : $firstname<p>Last Name :
$lastname<p>E-Mail : $email</blockquote></td></tr></table>
</center></BODY></HTML>";
?>
?>
</p>
</body>
</html>