Log in

View Full Version : MYSQL Set-up with PHP and Basic Ouput



Alby
12-13-2009, 07:18 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); [icode] 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:

[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>

Alby
12-13-2009, 08:49 PM
Can anyone provide any help?

MrRSMan
12-18-2009, 07:41 PM
Run the following code to create your table, and then discard:


<?php

$dbhost = "puttforpresents.local";
$dbuser = "root";
$dbpass = "";
$dbname = "pfp";

if (!mysql_connect($dbhost, $dbuser, $dbpass))
die("Can't connect to database");

if (!mysql_select_db($dbname))
die("Can't select database");

mysql_query("CREATE TABLE golfers(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
firstname VARCHAR (50),
lastname VARCHAR (50),
email VARCHAR (50),
phone VARCHAR (30),
handicap INT)")
or die(mysql_error());

mysql_close;

?>

register.php


<!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="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>
<br>
<input name="submit" type="submit" value="Submit" />
</form>
</div>

</body>
</html>

handleinput.php


<!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" />

<?php

$dbhost = "puttforpresents.local";
$dbuser = "root";
$dbpass = "";
$dbname = "pfp";
$table = "golfers";

if (!mysql_connect($dbhost, $dbuser, $dbpass))
die("Can't connect to database");

if (!mysql_select_db($dbname))
die("Can't select database");

mysql_query("INSERT INTO $table (
firstname,
lastname,
email,
phone,
handicap
)
VALUES (
$firstname,
$lastname,
$email,
$phone,
$handicap
)");

mysql_close;

echo'<head><title>PHP and MySQL</title></head><body bgcolour="#FFFFFF"><center><table border="0" width="500"><tr><td><font face="verdana" size="+0"><center><p>You just entered this information into the database</p><p>Name : $firstname</p><p>Last Name : $lastname</p><p>E-Mail : $email</p></center></td></tr></table></body>';

?>

</body>
</html>