" INSERT () " uses PHP and MySQL
Moderator: General Moderators
" INSERT () " uses PHP and MySQL
i have been testing this code for 3 days now and havtn been able to find anything wrong with it, now that ive said that i hope i dotn embaras myself. Well in any case here it is
<?php
$linkID = mysql_connect("localhost","","");
if ($linkID != false)
{
print "connection successfull<br>";
}
else
{
print "connection failed";
}
mysql_select_db("ymca", $linkID);
$result = mysql_query("INSERT INTO ymca (lastname, homenum, 1adultname, 1worknum, 2adultname, 2worknum,
1childname, 1childage, 1childbd, 2childname, 2childage,
2childbd, 3childname, 3childage, 3childbd, 4childname,
4childage, 4childbd, 5childname, 5childage, 5childbd,
appname, appsig, appdate, address, cardnum, guestnum,
checknum, datepaid) VALUES ('$lastname', '$homenum', '$1adultname', '$1worknum',
'$2adultname', '$2worknum', '$1childname', '$1childage',
'$1childbd', '$2childname', '$2childage', '$2childbd',
'$3childname', '$3childage', '$3childbd', '$4childname',
'$4childage', '$4childbd', '$5childname', '$5childage',
'$5childbd', '$appname', '$appsig', '$appdate', '$address',
'$cardnum', '$guestnum', '$checknum', '$datepaid')", $linkID);
if ($result == true)
{
print "record successfull";
}
else
{
print "record failed";
}
mysql_close($linkID);
?>
<?php
$linkID = mysql_connect("localhost","","");
if ($linkID != false)
{
print "connection successfull<br>";
}
else
{
print "connection failed";
}
mysql_select_db("ymca", $linkID);
$result = mysql_query("INSERT INTO ymca (lastname, homenum, 1adultname, 1worknum, 2adultname, 2worknum,
1childname, 1childage, 1childbd, 2childname, 2childage,
2childbd, 3childname, 3childage, 3childbd, 4childname,
4childage, 4childbd, 5childname, 5childage, 5childbd,
appname, appsig, appdate, address, cardnum, guestnum,
checknum, datepaid) VALUES ('$lastname', '$homenum', '$1adultname', '$1worknum',
'$2adultname', '$2worknum', '$1childname', '$1childage',
'$1childbd', '$2childname', '$2childage', '$2childbd',
'$3childname', '$3childage', '$3childbd', '$4childname',
'$4childage', '$4childbd', '$5childname', '$5childage',
'$5childbd', '$appname', '$appsig', '$appdate', '$address',
'$cardnum', '$guestnum', '$checknum', '$datepaid')", $linkID);
if ($result == true)
{
print "record successfull";
}
else
{
print "record failed";
}
mysql_close($linkID);
?>
- evilmonkey
- Forum Regular
- Posts: 823
- Joined: Sun Oct 06, 2002 1:24 pm
- Location: Toronto, Canada
Cheers mate.
I've noticed a few things right off the bat. Number one, you are making this more compilicated than you need to. Instead of:
Why not just do:
Next. Instead of $result right away, I prefer to do it this way:
A good thing to do is put an "or die..." line after eveery possible command, to see if you have any errors. A good thig to do is:
This also eliminates the need for this statement:
Also (I think) you are using the print() function incrrectly. I use it like this:
I hope something here helps. I'll look over your code once more and add any other correctiong.
Cheers,
EvilMonkey Admin.
I've noticed a few things right off the bat. Number one, you are making this more compilicated than you need to. Instead of:
Code: Select all
$linkID = mysql_connect("localhost","","");
if ($linkID != false)
{
print "connection successfull<br>";
}
else
{
print "connection failed";
}Code: Select all
$linkID = mysql_connect("localhost","","") or die("Connection error");Code: Select all
$query="INSERT INTO ymca (lastname,homenum,1adultname,1worknum,2adultname,2worknum,
1childname,1childage,1childbd,2childname,2childage,2childbd,
3childname,3childage ,3childbd,4childname,4childage,4childbd,
5childname,5childage,5childbd,appname,appsig,appdate,address,
cardnum,guestnum,checknum,datepaid) VALUES ('$lastname','$homenum','$1adultname','$1worknum','$2adultname',
'$2worknum','$1childname','$1childage','$1childbd','$2childname',
'$2childage','$2childbd','$3childname','$3childage','$3childbd',
'$4childname','$4childage','$4childbd','$5childname','$5childage',
'$5childbd','$appname','$appsig','$appdate','$address','$cardnum',
'$guestnum','$checknum','$datepaid')";
//then you do:
$result=mysql_query=($query, $linkID) or die(mysql_error());Code: Select all
...or die(mysql_error());Code: Select all
if ($result == true)
{
print "record successfull";
}
else
{
print "record failed";
}Code: Select all
print("Hello world");
//or
print("$variable");
//or
echo Hello World;
//or
echo $variable;Cheers,
EvilMonkey Admin.
You say it is not working.
What is not working?
How are you expecting it to work?
What is it doing, and more importantly, what is it NOT doing?
Are there any error messages?
Is this your first sql insert attempt, or has other attempts worked?
The more details that you provide of the problem, the more details of the solution you will be provided with.
What is not working?
How are you expecting it to work?
What is it doing, and more importantly, what is it NOT doing?
Are there any error messages?
Is this your first sql insert attempt, or has other attempts worked?
The more details that you provide of the problem, the more details of the solution you will be provided with.
Problems
yes this is my first attemp at this, i am trying to set it up to insert values from a form into a mysql d-base. I have tested the values and the connection to the d-base works, but it wont insert the data into the table. there arnt any erors except the "print (record failed);" line that keeps comming up stating just that. I have even checked the table itself and the feilds are nto being added.
form code
by the way if you would like the form code here it is:
(Beware pretty leangthy)
(Beware pretty leangthy)
Code: Select all
<html>
<head>
<title>YMCA/JCP Pool Members Database</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.text {
font-family: "Times New Roman", Times, serif;
font-size: 10px;
color: #000000;
}
-->
</style>
</head>
<body>
<div align="center">
<form name="form1" method="post" action="form1.php">
<table width="0" border="1" cellpadding="00" cellspacing="0" bordercolor="#000000">
<tr>
<td width="500" height="722">
<table width="500" height="129" border="1" cellpadding="0" cellspacing="10" bordercolor="#FFFFFF">
<tr bordercolor="#FFFFFF">
<td nowrap bgcolor="#EBEBEB">
<div align="left"><font size="2">Search Members<font face="Times New Roman, Times, serif">
</font></font> </div>
</td>
<td height="12" rowspan="3" nowrap bordercolor="#000000">
<div align="center"><img src="images/mysql.jpg" width="167" height="87"></div></td>
</tr>
<tr bordercolor="#FFFFFF">
<td width="204" height="53" nowrap><font size="2"><font face="Times New Roman, Times, serif">
<input name="search" type="text" id="search" size="29">
<input name="membersearch" type="submit" id="membersearch" value="Search">
</font></font></td>
</tr>
<tr bordercolor="#FFFFFF">
<td height="17" nowrap bgcolor="#EBEBEB"><font size="2"><a href="mailto:sdiver1500@aol.com">Contact
Administrator</a></font></td>
</tr>
</table>
<table width="500" height="1" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="1" bgcolor="#000000"></td>
</tr>
</table>
<table width="500" border="1" cellpadding="0" cellspacing="10" bordercolor="#FFFFFF">
<tr>
<td bgcolor="#EBEBEB" class="text"><font color="#FF0000" size="2">*</font><font size="2">
Notes Required Feilds</font></td>
</tr>
</table>
<table width="501" border="1" cellpadding="0" cellspacing="10" bordercolor="#FFFFFF">
<tr align="left" valign="top" class="text">
<td width="225" height="0" nowrap bgcolor="#EBEBEB" class="text">
<div align="left" class="text"><font size="2"></font><font size="2" face="Times New Roman, Times, serif">Last
Name:</font></div></td>
<td width="68" height="0" nowrap bgcolor="#FFFFFF"> </td>
<td width="160" height="0" nowrap bgcolor="#EBEBEB"><div align="left" class="text"><font size="2" face="Times New Roman, Times, serif">Home
Phone Number:</font></div></td>
</tr>
<tr align="left" valign="top" class="text">
<td width="225" height="0" nowrap><div align="left"><font size="2" face="Times New Roman, Times, serif">
</font><font size="2" face="Times New Roman, Times, serif">
<input name="lastname" type="text" id="lastname" size="30" maxlength="30">
</font><font color="#FF0000" size="2">*</font><font size="2" face="Times New Roman, Times, serif">
</font></div></td>
<td width="68" height="0" nowrap bgcolor="#FFFFFF"> </td>
<td width="160" height="0" nowrap><div align="left"><font size="2" face="Times New Roman, Times, serif">
<input name="homenum" type="text" id="homenum" size="12" maxlength="12">
<br>
</font><font color="#FF0000" size="2">*</font><font size="1" face="Times New Roman, Times, serif">ect:
904-287-5555</font></div></td>
</tr>
<tr align="left" valign="top" class="text">
<td width="225" height="0" nowrap bgcolor="#EBEBEB"><div align="left" class="text"><font size="2"></font><font size="2" face="Times New Roman, Times, serif">Adults'
Names</font></div></td>
<td width="68" height="0" nowrap bgcolor="#FFFFFF"> </td>
<td width="160" height="0" nowrap bgcolor="#EBEBEB"><div align="left"><font size="2"></font><font size="2" face="Times New Roman, Times, serif">Work
Phone Number</font></div></td>
</tr>
<tr align="left" valign="top" class="text">
<td width="225" height="0" nowrap><div align="left"><font size="2" face="Times New Roman, Times, serif">
<input name="1adultname" type="text" id="1adultname" size="30" maxlength="30">
</font><br>
<font color="#FF0000" size="2">*</font> </div></td>
<td width="68" height="0" nowrap bgcolor="#FFFFFF"> </td>
<td width="160" height="0" nowrap><div align="left"><font size="2" face="Times New Roman, Times, serif">
<input name="1worknum" type="text" id="1worknum" size="12" maxlength="12">
<br>
</font><font color="#FF0000" size="2">*</font><font size="1" face="Times New Roman, Times, serif">ect:
904-287-5555</font></div></td>
</tr>
<tr align="left" valign="top" class="text">
<td width="225" height="0" nowrap><div align="left"><font size="2" face="Times New Roman, Times, serif">
<input name="2adultname" type="text" id="2adultname" size="30" maxlength="30">
</font></div></td>
<td width="68" height="0" nowrap bgcolor="#FFFFFF"> </td>
<td width="160" height="0" nowrap><div align="left"><font size="2" face="Times New Roman, Times, serif">
<input name="2worknum" type="text" id="2worknum" size="12" maxlength="12">
<br>
<font size="1">ect: 904-287-5555 </font></font></div></td>
</tr>
<tr align="left" valign="top" class="text">
<td width="225" height="0" nowrap bgcolor="#EBEBEB"><div align="left"><font size="2" face="Times New Roman, Times, serif">First
Name(s) of Children Living at Home</font></div></td>
<td width="68" height="0" nowrap bgcolor="#EBEBEB"><div align="left"><font size="2" face="Times New Roman, Times, serif">Age</font></div></td>
<td width="160" height="0" nowrap bgcolor="#EBEBEB"><div align="left"><font size="2" face="Times New Roman, Times, serif">Birthdate</font></div></td>
</tr>
<tr align="left" valign="top" class="text">
<td width="225" height="0" nowrap><div align="left"><font size="2" face="Times New Roman, Times, serif">
<input name="1childname" type="text" id="1childname" size="30" maxlength="30">
</font></div></td>
<td width="68" height="0" nowrap><div align="left"><font size="2" face="Times New Roman, Times, serif">
<select name="1childage" size="1" id="1childage">
<option value=" " selected> </option>
<option value="01">0-1 Year</option>
<option value="02">2 Years</option>
<option value="03">3 Years</option>
<option value="04">4 Years</option>
<option value="05">5 Years</option>
<option value="06">6 Years</option>
<option value="07">7 Years</option>
<option value="08">8 years</option>
<option value="09">9 Years</option>
<option value="10">10 Years</option>
<option value="11">11 Years</option>
<option value="12">12 Years</option>
<option value="13">13 Years</option>
<option value="14">14 Years</option>
<option value="15">15 Years</option>
<option value="16">16 Years</option>
<option value="17">17 Years</option>
</select>
</font></div></td>
<td width="160" height="0" nowrap><div align="left"><font size="1" face="Times New Roman, Times, serif">
<font size="2">
<input name="1childbd" type="text" id="1childbd" size="8" maxlength="8">
</font><br>
ect: MMDDYYYY </font></div></td>
</tr>
<tr align="left" valign="top" class="text">
<td width="225" height="0" nowrap><div align="left"><font size="2" face="Times New Roman, Times, serif">
<input name="2childname" type="text" id="2childname" size="30" maxlength="30">
</font></div></td>
<td width="68" height="0" nowrap><div align="left"><font size="2" face="Times New Roman, Times, serif">
<select name="2childage" size="1" id="2childage">
<option value=" " selected> </option>
<option value="01">0-1 Year</option>
<option value="02">2 Years</option>
<option value="03">3 Years</option>
<option value="04">4 Years</option>
<option value="05">5 Years</option>
<option value="06">6 Years</option>
<option value="07">7 Years</option>
<option value="08">8 years</option>
<option value="09">9 Years</option>
<option value="10">10 Years</option>
<option value="11">11 Years</option>
<option value="12">12 Years</option>
<option value="13">13 Years</option>
<option value="14">14 Years</option>
<option value="15">15 Years</option>
<option value="16">16 Years</option>
<option value="17">17 Years</option>
</select>
</font></div></td>
<td width="160" height="0" nowrap><div align="left"><font size="1" face="Times New Roman, Times, serif">
<font size="2">
<input name="2childbd" type="text" id="2childbd" size="8" maxlength="8">
</font><br>
ect: MMDDYYYY </font></div></td>
</tr>
<tr align="left" valign="top" class="text">
<td width="225" height="0" nowrap><div align="left"><font size="2" face="Times New Roman, Times, serif">
<input name="3childname" type="text" id="3childname" size="30" maxlength="30">
</font></div></td>
<td width="68" height="0" nowrap><div align="left"><font size="2" face="Times New Roman, Times, serif">
<select name="3childage" size="1" id="3childage">
<option value=" " selected> </option>
<option value="01">0-1 Year</option>
<option value="02">2 Years</option>
<option value="03">3 Years</option>
<option value="04">4 Years</option>
<option value="05">5 Years</option>
<option value="06">6 Years</option>
<option value="07">7 Years</option>
<option value="08">8 years</option>
<option value="09">9 Years</option>
<option value="10">10 Years</option>
<option value="11">11 Years</option>
<option value="12">12 Years</option>
<option value="13">13 Years</option>
<option value="14">14 Years</option>
<option value="15">15 Years</option>
<option value="16">16 Years</option>
<option value="17">17 Years</option>
</select>
</font></div></td>
<td width="160" height="0" nowrap><div align="left"><font size="1" face="Times New Roman, Times, serif">
<font size="2">
<input name="3childbd" type="text" id="3childbd" size="8" maxlength="8">
</font><br>
ect: MMDDYYYY </font></div></td>
</tr>
<tr align="left" valign="top" class="text">
<td width="225" height="0" nowrap><div align="left"><font size="2" face="Times New Roman, Times, serif">
<input name="4childname" type="text" id="4childname" size="30" maxlength="30">
</font></div></td>
<td width="68" height="0" nowrap><div align="left"><font size="2" face="Times New Roman, Times, serif">
<select name="4childage" size="1" id="4childage">
<option value=" " selected> </option>
<option value="01">0-1 Year</option>
<option value="02">2 Years</option>
<option value="03">3 Years</option>
<option value="04">4 Years</option>
<option value="05">5 Years</option>
<option value="06">6 Years</option>
<option value="07">7 Years</option>
<option value="08">8 years</option>
<option value="09">9 Years</option>
<option value="10">10 Years</option>
<option value="11">11 Years</option>
<option value="12">12 Years</option>
<option value="13">13 Years</option>
<option value="14">14 Years</option>
<option value="15">15 Years</option>
<option value="16">16 Years</option>
<option value="17">17 Years</option>
</select>
</font></div></td>
<td width="160" height="0" nowrap><div align="left"><font size="1" face="Times New Roman, Times, serif">
<font size="2">
<input name="4childbd" type="text" id="4childbd" size="8" maxlength="8">
</font><br>
ect: MMDDYYYY </font></div></td>
</tr>
<tr align="left" valign="top" class="text">
<td width="225" height="0" nowrap><div align="left"><font size="2" face="Times New Roman, Times, serif">
<input name="5childname" type="text" id="5childname" size="30" maxlength="30">
</font></div></td>
<td width="68" height="0" nowrap><div align="left"><font size="2" face="Times New Roman, Times, serif">
<select name="5childage" size="1" id="5childage">
<option value=" " selected> </option>
<option value="01">0-1 Year</option>
<option value="02">2 Years</option>
<option value="03">3 Years</option>
<option value="04">4 Years</option>
<option value="05">5 Years</option>
<option value="06">6 Years</option>
<option value="07">7 Years</option>
<option value="08">8 years</option>
<option value="09">9 Years</option>
<option value="10">10 Years</option>
<option value="11">11 Years</option>
<option value="12">12 Years</option>
<option value="13">13 Years</option>
<option value="14">14 Years</option>
<option value="15">15 Years</option>
<option value="16">16 Years</option>
<option value="17">17 Years</option>
</select>
</font></div></td>
<td width="160" height="0" nowrap><div align="left"><font size="1" face="Times New Roman, Times, serif">
<font size="2">
<input name="5childbd" type="text" id="5childbd" size="8" maxlength="8">
</font><br>
ect: MMDDYYYY </font></div></td>
</tr>
</table>
<table width="500" border="1" cellpadding="0" cellspacing="10" bordercolor="#FFFFFF">
<tr>
<td class="text"><font size="2" face="Times New Roman, Times, serif"> <font size="4">T</font>he
undersigned agrees and acknowledges that the above information is
true and correct. It is understood that User and Guest cards are
the property of the Julington Creek Plantation Community Development
District (JCPCDD) and are non-transferable except in accordance
with the District's rules, policies and/or regulations. in consideration
for the admittance of the above listed persons and their guests
into the Plantation Club facility owned and operated by the JCPCDD
the undersigned agrees to hold harmless and release the JCPCDD,
its agents, officers and employees, from any and all liability for
any injuries that might occur in conjunction with usage of the Plantation
Club. Nothing herein shall be construed as a waiver of the District's
sovereign immunity or limits of liability beyond any statutory limited
waiver of immunity or limits of liability which may have been adopted
by the Florida Legislature in Section 768.28, Florida Statutes or
other statute.</font></td>
</tr>
</table>
<table width="500" height="302" border="1" cellpadding="00" cellspacing="10" bordercolor="#FFFFFF">
<tr align="left" valign="top">
<td height="17" nowrap bgcolor="#EBEBEB" class="text" span="1"> <div align="left"><font size="2"></font><font size="2" face="Times New Roman, Times, serif">Name
of Applicant</font></div></td>
<td width="67%" colspan="2" rowspan="8" align="center" valign="middle" nowrap bordercolor="#000000" bgcolor="#FFFFFF" class="text"> <img src="images/ymcalogo.gif" width="100" height="175"></td>
</tr>
<tr align="left" valign="top">
<td width="33%" height="0" nowrap class="text" span="1"> <div align="left"><font size="2" face="Times New Roman, Times, serif">
<input name="appname" type="text" id="appname" size="30" maxlength="30">
</font><font color="#FF0000" size="2"><br>
*</font><font size="2" face="Times New Roman, Times, serif">
</font></div></td>
</tr>
<tr align="left" valign="top">
<td width="33%" height="0" nowrap bgcolor="#EBEBEB" class="text"span="1">
<div align="left"><font size="2"></font><font size="2" face="Times New Roman, Times, serif">Signature</font></div></td>
</tr>
<tr align="left" valign="top">
<td width="33%" height="-5" class="text" span="1"> <div align="left"><font size="2" face="Times New Roman, Times, serif"> </font><font color="#FF0000" size="2">*</font><font size="2" face="Times New Roman, Times, serif">
<input name="appsig" type="checkbox" id="appsig" value="yes">
By checking this box you acknowlage that it has the same binding
power as your signature and is equal to your signature in every
other way.</font></div></td>
</tr>
<tr align="left" valign="top">
<td height="-5" bgcolor="#EBEBEB" class="text" span="1"><font size="2"> </font><font size="2">Date</font></td>
</tr>
<tr align="left" valign="top">
<td height="0" class="text" span="1"><font size="2" face="Times New Roman, Times, serif">
<input name="appdate" type="text" id="appdate" size="8" maxlength="8">
<br>
</font><font color="#FF0000" size="2">*</font><font size="1" face="Times New Roman, Times, serif">ect:
MMDDYYYY</font></td>
</tr>
<tr align="left" valign="top">
<td height="0" nowrap bgcolor="#EBEBEB" class="text" span="1"> <div align="left" class="text"><font color="#FF0000" size="2"><font color="#000000">Street</font>
</font><font size="2" face="Times New Roman, Times, serif">Address
</font></div></td>
</tr>
<tr align="left" valign="top">
<td height="0" nowrap class="text"> <div align="left"><font size="2" face="Times New Roman, Times, serif">
<input name="address" type="text" id="address" size="30" maxlength="50">
</font><font color="#FF0000" size="2"><br>
*</font><font size="2" face="Times New Roman, Times, serif">
</font></div></td>
</tr>
</table>
<table width="500" border="1" cellpadding="0" cellspacing="10" bordercolor="#FFFFFF">
<tr bordercolor="#FFFFFF" bgcolor="#EBEBEB" class="text">
<td width="108" bgcolor="#EBEBEB"><font size="2"> </font><font size="2">Card
Numbers</font></td>
<td width="107"><font size="2"> </font><font size="2">Guest
Card </font></td>
<td width="109"><font size="2">Check Number</font></td>
<td width="98"><font size="2"> </font><font size="2">Date Paid</font></td>
</tr>
<tr align="left" valign="top" bordercolor="#FFFFFF">
<td width="108" height="37"><font size="2" face="Times New Roman, Times, serif">
<input name="cardnum" type="text" id="cardnum" size="9" maxlength="9">
<br>
</font><font color="#FF0000" size="2">*</font><font size="1" face="Times New Roman, Times, serif">ect:
0000001-2</font></td>
<td width="107"><font size="2" face="Times New Roman, Times, serif">
<input name="guestnum" type="text" id="guestnum" size="7" maxlength="7">
</font><font color="#FF0000" size="2"><br>
*</font><font size="2" face="Times New Roman, Times, serif">
</font></td>
<td width="109"><font size="2" face="Times New Roman, Times, serif">
<input name="checknum" type="text" id="checknum" size="10" maxlength="10">
<br>
</font><font color="#FF0000" size="2">*</font><font size="2" face="Times New Roman, Times, serif">
</font></td>
<td width="98"><font size="2" face="Times New Roman, Times, serif">
<input name="datepaid" type="text" id="datepaid" size="8" maxlength="8">
<br>
</font><font color="#FF0000" size="2">*</font><font size="1" face="Times New Roman, Times, serif">ect:
MMDDYYYY</font></td>
</tr>
</table>
<table width="500" height="0" border="1" cellpadding="0" cellspacing="10" bordercolor="#FFFFFF">
<tr bordercolor="#FFFFFF">
<td width="0" height="0">
<input name="formreset" type="reset" id="formreset" value="Reset">
<div align="right"> </div></td>
<td><div align="center"></div></td>
<td width="0">
<div align="right">
<input name="formsubmit" type="submit" id="formsubmit" value="Submit">
</div></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>EURIKA!!!
HEY i got it to work no thanks to yall, jk, yall were both right, but that wasnt the problem, the problem was that i called the the table "ymca" and not "members" which it should have been, it turns out i did embarass myself afterall.
thanks a million
thanks a million
-
Darren Griffin
- Forum Newbie
- Posts: 4
- Joined: Mon Nov 11, 2002 2:41 am
Just one more thing ...
brianw84,
You spelt the word acknowledge incorrectly on your form. You spelt it acknowlage.
Good luck.
Griff.
You spelt the word acknowledge incorrectly on your form. You spelt it acknowlage.
Good luck.
Griff.