...

View Full Version : Trouble submitting to a DB



zoidbergmd
04-25-2012, 09:17 PM
I have been staring at my code for hours trying to figure out what is wrong with it. This is for a student project. When I fill out the form and click submit it just goes to a blank screen with the php's url. Nothing goes to the DB.

Here is the code:

register.html


<!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" />
<script language="javascript" src="Tooltip.js"><?php
include('connect-db.php');
$result = mysql_query("SELECT * FROM products ORDER BY artist")
or die(mysql_error());
?></script>
<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
<SCRIPT type="text/javascript">
<!--
pic1 = new Image(16, 16);
pic1.src="loader.gif";

pic2 = new Image(16, 16);
pic2.src="tick.gif";

$(document).ready(function(){

$("#username").change(function() {

var usr = $("#username").val();

if(usr.length >= 6)
{
$("#status").html('<img src="loader.gif" align="absmiddle">&nbsp;Checking availability...');

$.ajax({
type: "POST",
url: "check.php",
data: "username="+ usr,
success: function(msg){

$("#status").ajaxComplete(function(event, request, settings){

if(msg == 'OK')
{
/*$("#username").removeClass('object_error');*/ // if necessary
$("#username").addClass("object_ok");
$(this).html('&nbsp;<img src="tick.gif" align="absmiddle">');
}
else
{
/*$("#username").removeClass('object_ok');*/ // if necessary
$("#username").addClass("object_error");
$(this).html(msg);
}

});

}

});

}
else
{
$("#status").html('<font color="red">The username should have at least <strong>6</strong> characters.</font>');
/*$("#username").removeClass('object_ok');*/ // if necessary
$("#username").addClass("object_error");
}

});

});

//-->
<!--
pic1 = new Image(16, 16);
pic1.src="loader.gif";

pic2 = new Image(16, 16);
pic2.src="tick.gif";

$(document).ready(function(){

$("#email").change(function() {

var eml = $("#email").val();

if(echeck(eml))
{
$("#status").html('<img src="loader.gif" align="absbottom">&nbsp;Checking availability...');

$.ajax({
type: "POST",
url: "check1.php",
data: "email="+ eml,
success: function(msg){

$("#status").ajaxComplete(function(event, request, settings){

if(msg == 'OK')
{
/*$("#email").removeClass('object_error');*/ // if necessary
$("#email").addClass("object_ok");
$(this).html('&nbsp;<img src="tick.gif" align="absmiddle">');
}
else
{
/*$("#email").removeClass('object_ok');*/ // if necessary
$("#email").addClass("object_error");
$(this).html(msg);
}

});

}

});

}
else
{
$("#status").html('<font color="red">The e-mail should contain <strong>@ and . </strong> characters.</font>');
/*$("#email").removeClass('object_ok');*/ // if necessary
$("#email").addClass("object_error");
}

});

});

//-->
</SCRIPT>
<title>Welcome - Music Mania</title>
<!-- Loads css file for page -->
<link href = "style.css" rel = "stylesheet" type = "text/css">
</head>
<body onload=init()>

<table align = "center" border = "0" width = "400px">
<tr>
<td>
<div class = "titleColor">
<table align = "center" width = "100%" border = "1">
<tr height = "163px">
<td colspan = "7">
<strong><span class = "title">Music Mania</span></strong>
</td>
</tr>
<tr>
<td width = "70px"><div id = "nav"><a href = "index.html">home</a></div></td>
<td width = "70px"><div id = "nav"><a href = "music.html">store</a></div></td>
<td width = "70px"><div id = "nav"><a href = "about.html">about</a></div></td>
<td width = "70px"><div id = "nav"><a href = "contactUs.html">contact</a></div></td>
<td width = "320px"></td>
<td><div id = "signIn"><a href = "login.html">Sign In</a></div></td>
<td><div id = "signIn"><a href = "register.html">Register</a></div></td>
</tr>
</table>
</div>
<div class = "bodyColor">
<table align = "center" width = "100%" border = "1">
<tr>
<td>
<form method="post" action="newuser2.php">
<fieldset><legend>About You</legend>
<table align = "center" width = "80%" border = "0">
<tr>

<td><label><span class="ttip" onmouseover=if(t1)t1.Show(event,l1) onmouseout=if(t1)t1.Hide(event)>
First Name:
</span><br></td>
<td><input type = "text" name = "firstname" id = "fname"/></label></td>
<td width = "60px"></td>
<td><span class="ttip" onmouseover=if(t1)t1.Show(event,l2) onmouseout=if(t1)t1.Hide(event)>
Username:&nbsp;
</span><br><td width="100"><input id="username" size="20" type="text" name="username"></td>
<td width="400" align="left"><div id="status"></div></td>
</tr>
<tr>
<td><label><span class="ttip" onmouseover=if(t1)t1.Show(event,l3) onmouseout=if(t1)t1.Hide(event)>
Last Name:
</span><br></td>
<td><input type = "text" name = "lastname" id = "lname"/></label></td>
<td width = "60px"></td>
<td><span class="ttip" onmouseover=if(t1)t1.Show(event,l4) onmouseout=if(t1)t1.Hide(event)>
E-mail:&nbsp;
</span><br><td width="100"><input id="email" size="20" type="text" name="email"></td>
<td width="400" align="left"><div id="status"></div></td>
</tr>
<tr>
<td><label><span class="ttip" onmouseover=if(t1)t1.Show(event,l5) onmouseout=if(t1)t1.Hide(event)>
Birthday:
</span><br></td>
<td><input type = "text" name = "dob" id = "dob"/></label></td>
<td width = "60px"></td><td></td><td></td>
</tr>
</table>
</fieldset>
<fieldset><legend>Billing Info</legend>
<table align = "center" width = "80%">
<tr>
<td><label><span class="ttip" onmouseover=if(t1)t1.Show(event,l6) onmouseout=if(t1)t1.Hide(event)>
City:
</span><br></td>
<td><input type = "text" name = "city" id = "city"/></label></td>
<td width = "60px"></td>
<td><label><span class="ttip" onmouseover=if(t1)t1.Show(event,l7) onmouseout=if(t1)t1.Hide(event)>
Address 1:
</span><br></td>
<td><input type = "text" name = "address1" id = "addy2"/></label></td>
</tr>
<tr>
<td><label><span class="ttip" onmouseover=if(t1)t1.Show(event,l8) onmouseout=if(t1)t1.Hide(event)>
State:
</span><br></td>
<td><input type = "text" name = "state" id = "state"/></label></td>
<td width = "60px"></td>
<td><label><span class="ttip" onmouseover=if(t1)t1.Show(event,l9) onmouseout=if(t1)t1.Hide(event)>
Address 2:
</span><br></td>
<td><input type = "text" name = "address2" id = "addy2"/></label></td>
</tr>
<tr>
<td><label><span class="ttip" onmouseover=if(t1)t1.Show(event,l10) onmouseout=if(t1)t1.Hide(event)>
Zip Code:
</span><br></td>
<td><input type = "text" name = "zip" id = "zip"/></label></td>
<td width = "60px"></td>
<td><label><span class="ttip" onmouseover=if(t1)t1.Show(event,l11) onmouseout=if(t1)t1.Hide(event)>
Phone:
</span><br></td>
<td><input type = "text" name = "phone" id = "phone"/></label></td>
</tr>
</table>
</fieldset>
<fieldset><legend>Password</legend>
<table align = "center" width = "80%">
<tr>
<td><label><span class="ttip" onmouseover=if(t1)t1.Show(event,l12) onmouseout=if(t1)t1.Hide(event)>
Password:
</span><br> </td>
<td><input type = "password" name = "password"/></label></td>
<td width = "60px"></td>
<td><label><span class="ttip" onmouseover=if(t1)t1.Show(event,l13) onmouseout=if(t1)t1.Hide(event)>
Confirm Password:
</span><br></td>
<td><input type = "password" name = "password2"/></label></td>
</tr>
</table>
</fieldset>
<table align = "center">
<tr>
<td><input type = "submit" value = "Register"/></td>
<td><input type = "reset" value = "Clear"/></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>

<div id="a" style="background-color:ivory;width: 300px;
height: 49px;border: solid 1px gray; text-align: center;">
</div>
</body>

<script>
var t1=null;
var l1="Please enter your full first name.";
var l2="Please enter a username between 6-16 characters.";
var l3="Please enter your full last name.";
var l4="Please enter a valid e-mail address (example@example.com)";
var l5="Please enter your birthday as mmddyyyy (12151989)";
var l6="Please enter the city in which you reside.";
var l7="Please enter the first line of your address.";
var l8="Please abbreviate the State in which you reside (IN, FL, KY)";
var l9="Please enter the second line of your address if necessary.";
var l10="Please enter your 6 digit zip code.";
var l11="Please enter your 10 digit phone number with no dashes (1112223333).";
var l12="Please enter a password consisting of at least 1 letter and number between 6-32 characters.";
var l13="Please confirm your password.";

function init()
{
t1 = new ToolTip("a",false);
}
function check()
{
get
}

function echeck(str) {

var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){
alert("Invalid E-mail ID")
return false
}

if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
alert("Invalid E-mail ID")
return false
}

if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
alert("Invalid E-mail ID")
return false
}

if (str.indexOf(at,(lat+1))!=-1){
alert("Invalid E-mail ID")
return false
}

if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
alert("Invalid E-mail ID")
return false
}

if (str.indexOf(dot,(lat+2))==-1){
alert("Invalid E-mail ID")
return false
}

if (str.indexOf(" ")!=-1){
alert("Invalid E-mail ID")
return false
}

return true
}
</script>
</html>


newuser2.php


<?php
$username=$_POST['username'];
$password = crypt($_POST['password']);
$email =$_POST['email'];
$firstname = $_POST['firstname'];
$fname=strtoupper($firstname);
$lastname = $_POST['lastname'];
lname=strtoupper($lastname);
$dob = $_POST['dob'];
$address1 = $_POST['address1'];
$ad1=strtoupper($address1);
$address2 = $_POST['address2'];
$ad2=strtoupper($address2);
$city = $_POST['city'];
$cit=strtoupper($city);
$state= $_POST['state'];
$zip= $_POST['zip'];
$phone = $_POST['phone'];
include('connect-db.php');
$sql = "INSERT INTO users values(UUID() ,'". $username. "','". $password ."','". $email ."','". $fname ."','". $lname . "','". $dob . "','". $ad1 ."','". $ad2 ."','". $cit ."','". $state ."','". $zip ."','". $phone ."')";
$result= mysql_query($sql) or die(msql_error());
header("Location: administration.html");
mysql_close($conn);
?>

mlseim
04-25-2012, 11:58 PM
The blank screen means you're getting a PHP script error and you have error reporting turned off.

Ask your webhost to turn it on, or try adding this line to the top of your script(s):

<?php
error_reporting(E_ALL ^ E_NOTICE);



Then let us know what it says.



.

zoidbergmd
04-26-2012, 06:37 AM
I added it, and nothing happened, I am still getting a blank screen.

zoidbergmd
04-26-2012, 04:58 PM
Got an error returned!

Fatal error: Call to undefined function msql_error() in /home/acbeyer/public_html/team/newuser2.php on line 23

zoidbergmd
04-26-2012, 05:09 PM
Solved the problem with the error reporting! Thanks for that!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum