Jump to content

I need help with this code. Can't figure out whats wrong.


john_wenhold

Recommended Posts

I'm getting an 'error querying database' saying when I hit submit with the entire form filled out.  Anyone know what the problem is?  Note: the 'xxx' in $dbc are my personal info that I just took out for security sake.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<html>
<head>

	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
	<title> TheTextNook Sign up - Results </title>
	<link type="text/css" rel="stylesheet" href="signup.css" />
</head>

<body>

	<div id="allcontent">

	<h1> <span id="title"> TextNook </span> <span id="home"> <a href="home.html"> Home </a> </span> </h1>

		<h2> TextNook Sign Up </h2>

		<?php


		$firstname = ($_POST['firstname']);

		$lastname = ($_POST['lastname']);		

		$username = ($_POST['username']); 

		$password1 = ($_POST['password1']);

		$password2 = ($_POST['password2']);

		$phonenumber = ($_POST['phonenumber']);

		$sex = ($_POST['sex']);

		$month = ($_POST['month']);

		$day = ($_POST['day']);

		$year = ($_POST['year']);

		$categories = ($_POST['categories']);

		$days = ($_POST['days']);

		$text = ($_POST['text']);

		$comments = ($_POST['comments']);

		$submit = ($_POST['signup']);		




		if (isset($submit)) {
		$output_form = false;

		if (isset($firstname) && !empty($firstname)
		&& isset($lastname) && !empty($lastname) 
		&& isset($username) && !empty($username)
		&& isset($password1) && !empty($password1)
		&& isset($password2) && !empty($password2)
		&& isset($phonenumber) && !empty($phonenumber)
		&& isset($month) && !empty($month)
		&& isset($day) && !empty($day)
		&& isset($year) && !empty($year)
		&& isset($categories) && !empty($categories)
		&& isset($days) && !empty($days)
		&& isset($text) && !empty($text)
		&& isset($sex) && !empty($sex)
		&& ($password1 == $password2)) {

		$dbc = mysql_connect ('server', 'xxxx', 'xxxx', 'xxxxxx')
		      or die ('Error connecting to MySQL server.');

		mysql_select_db ('thetextnook', $dbc);

		$query = "SELECT * FROM textnook WHERE user_name = '{$_POST['username']}'";

		$data = mysql_query ($query);			
		if (mysql_num_rows($data) == 0) {


		$query = "INSERT INTO textnook ( first_name, last_name, user_name, password, phonenumber, sex, month, day, year, category, days, text, comments)
			 VALUES ( '$firstname', '$lastname', '$username', '$password1', '$phonenumber', '$sex', '$month','$day', '$year', '$categories', '$days', '$text','$comments')";

		$result = mysql_query ($query, $dbc)
		      or die ('Error querying database.');


		echo 'Sign Up Confirmed' . '<br /> <br />';					

		echo 'Thanks for joining TextNook!' . '<br /> <br />'; 	

		echo 'You have signed up to receive text messages for the following categories:' .implode(", ",$_POST['categories']) . '<br /> <br />';

		echo 'You have signed up to receive text messages on the following days:'  .implode(", ",$_POST['days']) . '<br /> <br />';

		echo 'And you have signed up to receive the following amount of text message(s) per category per day:' . $_POST['text'] . '<br /> <br />';

		echo 'You can change these selections at anytime by logging into your account.' . '<br /> <br />';

		echo 'Coming Soon: You will be able to choose individual stores and restraunts instead of entire categories.</span>' . '<br /> <br /> <br /> <br /> <br /> <br /> <br /> <br />';

		mysql_close ($dbc);

well you likely have an error in your query.

 

change

$result = mysql_query ($query, $dbc)
		      or die ('Error querying database.');

 

to

$result = mysql_query ($query, $dbc)
		      or die ("MYSQL ERROR: $query - " . mysql_error());

 

and see what it says.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.