similar problen as rhinton6's inserting data...
07-03-2005, 05:23 PM
|
similar problen as rhinton6's inserting data...
|
Posts: 216
Location: Boston, Ma
|
I was trying to make a connection to a database and insert a bunch of records with a php file. I looked at the post rhinton6 made about inserting data and tried almost exactly what they had done but it didnt work. When you click submit on my form it loads to 38% then seems to die. I dont know if this would be a coding problem or a DB problem. Here's the source.
SQL
Code:
CREATE TABLE riverview(
custid int(6) not null primary key auto_increment,
fname CHAR(20),
lname CHAR(20),
phone INT(10),
email CHAR(40),
calltime CHAR (9),
street CHAR(100),
city CHAR(20),
state CHAR(2),
zip INT(5),
attendance CHAR(20),
type CHAR(20),
month INT(2),
day INT(2),
year INT(4),
hear CHAR(20)
);
HTML
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>
<script type "text/javascript">
function numCheck(x)
{
myInt = x.value;
if ((myInt + 1)>0)
{ }
else{ alert("That is not a valid number"); }
}
function yearCheck(x)
{
myInt = x.value;
if ((myInt + 1)>0)
{
if (myInt < 1000)
{
alert("Your number wasnt long enough");
}
}
else{ alert("That is not a valid number"); }
}
function checkEmail(){
var email = document.getElementById("email");
if(email.value.indexOf("@") != "-1" && email.value.indexOf(".") != "-1")
{
return true;
}
else
{
alert("You entered an incorrect e-mail address");
return false;
}
}
function phoneCheck(x)
{
myInt = x.value;
if ((myInt + 1)>0)
{
if (myInt < 1000000000)
{
alert("Your number wasnt long enough");
}
}
else{ alert("That is not a valid phone number"); }
}
function zipCheck(x)
{
myInt = x.value;
if ((myInt + 1)>0)
{
if (myInt < 10000)
{
alert("Your number wasnt long enough");
}
}
else{ alert("That is not a valid zip code"); }
}
</script>
<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
<LINK REL=stylesheet HREF="divs.css" TYPE="text/css">
<title>Reservation Form</title>
</head>
<body bgcolor="#000000">
<form name="Reservations" method="GET" action="http://127.0.0.1:8080/riverviewDBtesting.php">
<table class="main">
<tr>
<td>
</td>
<td bgcolor= "white" width="800">
<p class="riverview"><a href="index.html" >Riverview</a></p>
<hr>
<table>
<tr>
<td>
<br><h3>Personal Information (Required):</h3>
</td>
</tr>
<tr>
<td>
<b>First Name:</b>
</td>
<td>
<input type="text" size="12" maxlength="12" name="fname"><small> ex: John</small>
</td>
</tr>
<tr>
<td>
<b>Last Name:</b>
</td>
<td>
<input type="text" size="12" maxlength="36" name="lname"><small> ex: Doe</small>
</td>
</tr>
<tr>
<td>
<b> Phone Number:</b>
</td>
<td>
<input type="text" size="12" maxlength="10" name="phone" onblur=phoneCheck(this)><small> ex: 6174567890</small>
</td>
</tr>
<tr>
<td>
<b>E-Mail:</b>
</td>
<td>
<input type="text" size="12" maxlength="30" name="email" onblur=checkEmail(this)><small> ex: Example@example.com</small>
</td>
</tr>
<tr>
<td>
<b>Whats the best time <br>of day to contact you?</b>
</td>
<td>
<select name="calltime">
<option value="morning">Morning</option>
<option value="afternoon">Afternoon</option>
<option value="night">Night</option></select>
</td>
</tr>
</table>
<br>
<hr>
<table>
<tr>
<td>
<br><h3>Address information (Required):</h3>
</td>
</tr>
<tr>
<td>
<b>Street:</b>
</td>
<td>
<input type="text" size="50" maxlength="40" name="street"><small> ex: 13 Port Street</small>
</td>
</tr>
<tr>
<td>
<b>City: </b>
</td>
<td>
<input type="text" size="50" maxlength="40" name="city"><small> ex: Boston</small>
</td>
</tr>
<tr>
<td>
<b>State:</b>
</td>
<td>
<select name="state">
<option value="AL">AL</option>
<option value="AK">AK</option>
<option value="AZ">AZ</option>
<option value="AR">AR</option>
<option value="CA">CA</option>
<option value="CO">CO</option>
<option value="CT">CT</option>
<option value="DE">DE</option>
<option value="DC">DC</option>
<option value="FL">FL</option>
<option value="GA">GA</option>
<option value="GU">GU</option>
<option value="HI">HI</option>
<option value="ID">ID</option>
<option value="KS">KS</option>
<option value="KY">KY</option>
<option value="LA">LA</option>
<option value="ME">ME</option>
<option value="MD">MD</option>
<option value="MA">MA</option>
<option value="MI">MI</option>
<option value="MN">MN</option>
<option value="MS">MS</option>
<option value="MO">MO</option>
<option value="MT">MT</option>
<option value="NE">NE</option>
<option value="NV">NV</option>
<option value="NH">NH</option>
<option value="NJ">NJ</option>
<option value="NM">NM</option>
<option value="NY">NY</option>
<option value="OH">OH</option>
<option value="OK">OK</option>
<option value="OR">OR</option>
<option value="PA">PA</option>
<option value="PR">PR</option>
<option value="RI">RI</option>
<option value="SC">SC</option>
<option value="TN">TN</option>
<option value="TX">TX</option>
<option value="UT">UT</option>
<option value="VT">VT</option>
<option value="VA">VA</option>
<option value="VI">VI</option>
<option value="WA">WA</option>
<option value="WV">WV</option>
<option value="WI">WI</option>
<option value="WY">WY</option>
</select>
</td>
</tr>
<tr>
<td>
<b>Zip:</b>
</td>
<td>
<input type="text" size="9" maxlength="9" name="zip" onblur=zipCheck(this)><small> ex: 01234</small>
</td>
</tr>
</table>
<br>
<hr>
<table width=100%>
<tr>
<td>
<br><h3>Reservation information (Required):</h3>
</td>
</tr>
<tr>
<td>
<b>How many people do you plan to have in attendance?</b>
</td>
</tr>
</table>
<table width=100%>
<tr>
<td>
Less than 50<input type="radio" value="less than 50" name="attendance">
</td>
<td>
51-150<input type="radio" value="51-150" name="attendance">
</td>
<td>
151-250<input type="radio" value="151-250" name="attendance">
</td>
<td>
251-350<input type="radio" value="251-350" name="attendance">
</td>
<td>
351-450<input type="radio" value="351-450" name="attendance">
</td>
<td>
451-550<input type="radio" value="451-550" name="attendance">
</td>
<td>
More than 500<input type="radio" value="more than 500" name="attendance">
</td>
</tr>
</table>
<br>
<table>
<tr>
<td>
<b>What type of occasion are you interested in?</b>
</td>
</tr>
</table>
<table width=100%>
<tr>
<td>
Wedding Reception<input type="radio" value="wedding reception" name="type">
</td>
<td>
Birthday<input type="radio" value="birthday" name="type"><br />
</td>
<td>
Anniversary<input type="radio" value="anniversary" name="type"><br />
</td>
<td>
Family Reunion<input type="radio" value="family reunion" name="type"><br />
</td>
<td>
Fundraiser<input type="radio" value="funraiser" name="type"><br />
</td>
<td>
Other<input type="radio" value="other" name="type"><br />
</td>
<td>
</td>
</tr>
</table>
<br>
<table>
<tr>
<td>
<b>What day are you interested in?</b>
</td>
<td>
<input type="text" size="1" maxlength="2" name="month" onBlur="numCheck(this);">
<input type="text" size="1" maxlength="2" name="day"onBlur="numCheck(this);">
<input type="text" size="2" maxlength="4" name="year"onBlur="yearCheck(this);"><small> ex: 01/02/2005</small>
</td>
</tr>
</table>
<br>
<hr>
<table>
<tr>
<td>
<h3>Other Information</h3><br>
</td>
</tr>
</table>
<table>
<tr>
<td>
<b>How did you hear about us?</b>
</td>
</tr>
</table>
<table width=100%>
<tr>
<td>
Radio<input type="radio" value="radio" name="hear">
</td>
<td>
Magazine<input type="radio" value="magazine" name="hear">
</td>
<td>
TV<input type="radio" value="tv" name="hear">
</td>
<td>
Friend/Colleague<input type="radio" value="friend" name="hear">
</td>
<td>
Newspaper/Flier<input type="radio" value="newspaper" name="hear">
</td>
<td>
Search Engine<input type="radio" value="search" name="hear">
</td>
<td>
Yellow Pages<input type="radio" value="yellow" name="hear">
</td>
</tr>
</table>
<hr>
<table width=100%>
<tr>
<td>
<p align="center"><input type='submit' value='Submit'><BR>
</td>
</tr>
</table>
<hr>
</td>
<td>
</td>
</tr>
</table>
</form>
</body>
</html>
I know there is a slight problem withj putting in a zip code and having the form say its not long enough if you zip code starts with a zero.
PHP
Code:
<html>
<head>
<title>Riverview</title>
</head>
<body bgcolor="#3399CC">
<?php
/* set's the variables for MySQL connection */
$dbhost = "localhost:8080"; // this is the server address and port
$dbuname = "mrinput";// username
$dbpass = "q0kml9"; // password
$dbname = "riverviewdb";
/* Connects to the MySQL server */
$$dbase = mysql_connect($dbhost, $dbuname, $dbpass);
/* Defines the Active Database for the Connection */
mysql_select_db($dbname, $dbase);
$fname=$_GET['fname'];
$lname=$_GET['lname'];
$phone=$_GET['phone'];
$email=$_GET['email'];
$calltime=$_GET['calltime'];
$street=$_GET['street'];
$city=$_GET['city'];
$state=$_GET['state'];
$zip=$_GET['zip'];
$attendance=$_GET['attendance'];
$type=$_GET['type'];
$month=$_GET['month'];
$day=$_GET['day'];
$year=$_GET['year'];
$hear=$_GET['hear'];
$sql = "INSERT INTO riverview VALUES('''','$fname','$lname','$phone','$email','$calltime','$street','$city','$state','$zip','$attendance','$type','$month','$day','$year','$hear')";
$result = mysql_query($sql, $dbase) or die (mysql_error());
if(!$result) {
echo("Query Failed!");
}
else
{
echo("Successful Entry");
}
mysql_close($dbase);
?>
<br>
<b><i><a href="index.html">Click here</a></i></b> to return to Riverview's site.
</body>
</html>
|
|
|
|
07-03-2005, 05:56 PM
|
|
Posts: 481
Location: Gold Coast - Brisbane QLD, Australia
|
Change your form method to 'POST'. GET is limited to 255 chars by memory, so this limits the length and number of name/value pairs that you can submit.
Your $result statement includes a die message if the sql fails, so that means if(!result) will never run. The script will exit before getting to that conditional.
Try this method of exiting the script.
1. delete the html link
2. add to the end of your script;
PHP Code:
$redirect = 'redirectURL.php?query=ok'';
header('Location; '.$redirect);
exit();
You also may want to check out this thread to see how I directed another forum member on how to take a secure, object orientated approach to making db connections in a site's scripts.
|
|
|
|
07-04-2005, 04:35 AM
|
|
Posts: 216
Location: Boston, Ma
|
I'm confused what your saying to get rid of. Should i get rid of the IF-ELSE statement and just put the redirect? if i did that how would the browser know when the querey wasnt succesful? And that thread to check out was to me from about a week ago, i still havnt gotton anything working 
Last edited by The_Anomaly; 07-04-2005 at 04:47 AM..
|
|
|
|
07-04-2005, 05:08 AM
|
|
Posts: 216
Location: Boston, Ma
|
Ok i changed the form type to POST and all of the PHP file to POST. Then i deleted the link in the body of the PHP file and the if-else statement. Its still times out at 38%, here's the PHP i have now.
Code:
<html>
<head>
<title>Riverview</title>
</head>
<body bgcolor="#3399CC">
<?php
/* set's the variables for MySQL connection */
$dbhost = "localhost:8080"; // this is the server address and port
$dbuname = "mrinput";// username
$dbpass = "q0kml9"; // password
$dbname = "riverviewdb";
/* Connects to the MySQL server */
$dbase = mysql_connect($dbhost, $dbuname, $dbpass);
/* Defines the Active Database for the Connection */
mysql_select_db($dbname, $dbase);
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$calltime=$_POST['calltime'];
$street=$_POST['street'];
$city=$_POST['city'];
$state=$_POST['state'];
$zip=$_POST['zip'];
$attendance=$_POST['attendance'];
$type=$_POST['type'];
$month=$_POST['month'];
$day=$_POST['day'];
$year=$_POST['year'];
$hear=$_POST['hear'];
$sql = "INSERT INTO riverview VALUES('''','$fname','$lname','$phone','$email','$calltime','$street','$city','$state','$zip','$attendance','$type','$month','$day','$year','$hear')";
$result = mysql_query($sql, $dbase) or die (mysql_error());
$redirect = 'success.php?query=ok';
header("Location: $redirect");
exit();
mysql_close($dbase);
?>
</html>
here's the error i'm getting:
Warning: mysql_connect(): Lost connection to MySQL server during query in c:\program files\easyphp1-8\www\riverviewdbtesting.php on line 15
Fatal error: Maximum execution time of 30 seconds exceeded in c:\program files\easyphp1-8\www\riverviewdbtesting.php on line 15
line 15 is: $dbase = mysql_connect($dbhost, $dbuname, $dbpass);
so confused 
|
|
|
|
07-04-2005, 05:17 AM
|
|
Posts: 216
Location: Boston, Ma
|
OK i want to slap myself. I took the localhost:8080 and just did localhost and it seems to be trying to execute. I took out the header line and added the old line back in and i get a succeful entry output. I checked the DB and found that there is data in it. I'm a little confused about the data because i have 7 entries of data from attempts in the past that i didnt think were working but i guess they did. One problem is the entries for all of my phone numbers that do not start with a 1 is 2147483647, thats not the number i'm putting in the form. When i change the type in the database from INT to CHAR it works fine. This isnt changing anything else in my DB that an INT
i am getting the error with the header() or i would just have the page redirect someone after succesful entry.
Warning: Cannot modify header information - headers already sent by (output started at c:\program files\easyphp1-8\www\riverviewdbtesting.php:6) in c:\program files\easyphp1-8\www\riverviewdbtesting.php on line 43
Last edited by The_Anomaly; 07-04-2005 at 05:40 AM..
|
|
|
|
|
« Reply to similar problen as rhinton6's inserting data...
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|