Need help with scripting to store data on MySQL  | Member | | Join Date: Jun 2009 Location: Indiana
Posts: 65
| |
I have recently been working on a website for an honors association, and have a lot of difficulty but have found help from those on this site. I would like to see if I can get some more help on a different issue than what I was initially having.
I am working on storing data collected from a form on my website. I would like the information to be stored into MySQL once entered by users. I have googled this question and have tried multiple suggestions and have progressed slightly. The problem that I am having is that the page after I press the submit button (actually called Add Member) comes up blank. I would like the page to either read "Thank you, your information has been added" or "Error-incomplete information provided, please fill out the form" or something along those lines.
So my problem is getting the information to store to MySQL and then getting the filled out form page to move onto the next page.
Please see: http://mideasthonors.org/addmember.php to view the form.
This is the scripting I have for the form information to be added to MySQL: -
<?php
-
include ("admintasks-dbcon.php");
-
mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
-
mysql_select_db($dbname);
-
-
$query = 'SELECT * FROM $add_member';
-
$result = mysql_query($query);
-
-
if($result)
-
{
-
while($row = mysql_fetch_array($result))
-
{
-
$name = $row['$yourfield'];
-
echo 'Name: '.$name;
-
-
mysql_select_db("mideasthonors");
-
-
$sql="INSERT INTO $add_member (Name, Address 1, Address 2, City, State, Zip Code, Website, Contact Name, Position, Phone Number, Email Address)
-
VALUES {$_POST['name']},{$_POST['address 1']},{$_POST['address 2']},{$_POST['city']},{$_POST['state']},{$_POST['zip code']},{$_POST['website']},{$_POST['contact name']},{$_POST['position']},{$_POST['phone number']},{$_POST['email address']})";
-
-
if (!mysql_query($sql,$con))
-
{
-
die('Error: ' . mysql_error());
-
}
-
-
echo 'Thank You! Your information has been entered into the database!';
-
}
-
}
-
?>
-
This is the error page I have set up: -
<!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-Language" content="en-us" />
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-
<title>Error</title>
-
<style type="text/css">
-
.style1 {
-
font-family: Arial, Helvetica, sans-serif;
-
font-size: medium;
-
}
-
-
.style29 {
-
font-family: Arial, Helvetica, sans-serif;
-
}
-
h2 {
-
font-family: Verdana, Arial, Helvetica, sans-serif;
-
font-size: 17px;
-
font-weight: bold;
-
color: #2F77F1;
-
line-height: 20px;
-
}
-
.style30 {
-
font-family: geneva, arial;
-
font-size: 10pt;
-
}
-
-
.style31 {
-
font-family: Verdana, Arial, Helvetica, sans-serif;
-
font-size: 12px;
-
line-height: 11pt;
-
margin: 3px 0;
-
padding-bottom: 9px;
-
}
-
</style>
-
</head>
-
-
<body>
-
-
<p class="style1"><strong>Error: All fields have not been filled in, or information is inaccurate. Please complete form.</strong></p>
-
<form method="post" action="addmember.php" style="width: 169px">
-
*
-
-
<table>
-
-
<tr>
-
<td colspan=2><h2 class="style29">Institution Information</h2></td>
-
</tr>
-
-
<tr>
-
<td class='style30'><p class="style31"><label for='name'>Name*</label></p></td>
-
<td class="style30"><input type='text' name='name' size=45 maxlength=100 /></td>
-
</tr>
-
-
<tr>
-
<td class='style30'><p class="style31"><label for='address_1'>Address*</label></p></td>
-
<td class="style30"><input type='text' name='address_1' size=45 maxlength=100 /></td>
-
</tr>
-
-
<tr>
-
<td class="style30"> </td>
-
<td class="style30"><input type='text' name='address_2' size=45 maxlength=100 /></td>
-
</tr>
-
-
<tr>
-
<td class='style30'><p class="style31"><label for='city'>City*</label></p></td>
-
<td class="style30"><input type='text' name='city' size=45 maxlength=50 /></td>
-
</tr>
-
-
<tr>
-
<td class='style30'><p class="style31"><label for='state'>State*</label>
-
<td class="style30">
-
<select name='state'>
-
<?php
-
$states = array("Illinois", "Indiana", "Kentucky", "Michigan", "Ohio", "Pennsylvania", "Tennessee", "West Viriginia");
-
foreach($states as $a => $value){
-
echo "<option name='$value'>$value</option>";
-
}
-
?>
-
</select>
-
</td>
-
</tr>
-
-
<tr>
-
<td class='style30'><p class="style31"><label for='zip'>ZIP Code*</label></p></td>
-
<td class="style30"><input type='text' name='zip' size=10 maxlength=10 /></td>
-
</tr>
-
-
<tr>
-
<td class='style30'><p class="style31"><label for='website'>Website*</label></p></td>
-
<td class="style30"><input type='text' name='website' value='http://www.' size=45 maxlength=100 /></td>
-
</tr>
-
-
<tr>
-
<td colspan=2><h2 class="style29">Contact Information</h2></td>
-
</tr>
-
-
<tr>
-
<td class='style30'><p class="style31"><label for='contact_name'>Contact Name*</label></p></td>
-
<td class="style30"><input type='text' name='contact_name' size=45 maxlength=100 /></td>
-
</tr>
-
-
<tr>
-
<td class='style30'><p class="style31"><label for='contact_position'>Position</label></p></td>
-
<td class="style30"><input type='text' name='contact_position' size=45 maxlength=100 /></td>
-
</tr>
-
-
<tr>
-
<td class='style30'><p class="style31"><label for='contact_phone'>Phone Number*</label></p></td>
-
<td class="style30"><input type='text' name='contact_phone' size=14 maxlength=14 /></td>
-
</tr>
-
-
<tr>
-
<td class='style30'><p class="style31"><label for='contact_email'>Email Address*</label></p></td>
-
<td class="style30"><input type='text' name='contact_email' size=45 maxlength=100 /></td>
-
</tr>
-
-
<tr>
-
<td class="style30"> </td>
-
<td class="style30"><input type='submit' name ="Add Member" value='Add Member' /></td>
-
</tr>
-
-
</table>
-
-
If anyone could help me out I would really appreciate it!
|  | Member | | Join Date: Jun 2009 Location: Indiana
Posts: 65
| | | re: Need help with scripting to store data on MySQL
Everything is still the same that is on the page that you gave me except the error: error_reporting(E_ALL); at the top. Its just that they need to enter their information from mideasthonors.org/addmember.php instead of addmembererror.php. Does that make sense??? I mean the same form is on both pages, just at the top it states that information was not filled in accurately.
|  | Needs Regular Fix | | Join Date: Feb 2009 Location: UK
Posts: 356
| | | re: Need help with scripting to store data on MySQL
yes it makes sense and as i said you need to change the names within the $_POST so they match the addmember.php form. they need to look like these -
$_POST['name']
-
$_POST['address_1']
-
$_POST['address_2']
-
$_POST['city']
-
$_POST['state']
-
$_POST['zip']
-
$_POST['website']
-
$_POST['contact_name']
-
$_POST['contact_position']
-
$_POST['contact_phone']
-
$_POST['contact_email']
-
and the form on the error page should be the same as the other form then -
<form method="post" action="addmember.php" style="width: 169px">
-
*
-
<table>
-
-
<tr>
-
<td colspan=2><h2 class="style29">Institution Information</h2></td>
-
</tr>
-
-
<tr>
-
<td class='style30'><p class="style31"><label for='name'>Institution*</label></p></td>
-
<td class="style30"><input type="text" name="name" size=45 maxlength=100 value="" /></td>
-
</tr>
-
-
<tr>
-
<td class='style30'><p class="style31"><label for='address_1'>Address*</label></p></td>
-
<td class="style30"><input type="text" name="address_1" size=45 maxlength=100 value="" /></td>
-
</tr>
-
-
<tr>
-
<td class="style30"> </td>
-
<td class="style30"><input type="text" name="address_2" size=45 maxlength=100 value="" /></td>
-
</tr>
-
-
<tr>
-
<td class='style30'><p class="style31"><label for='city'>City*</label></p></td>
-
<td class="style30"><input type="text" name="city" size=45 maxlength=50 value="" /></td>
-
</tr>
-
-
<tr>
-
<td class='style30'><p class="style31"><label for='state'>State*</label>
-
<td class="style30">
-
<select name='state'>
-
<?php
-
$states = array("Illinois", "Indiana", "Kentucky", "Michigan", "Ohio", "Pennsylvania", "Tennessee", "West Viriginia");
-
foreach($states as $a => $value){
-
echo "<option name=".$value ." value=".$value .">$value</option>";
-
}
-
?>
-
</select>
-
</td>
-
</tr>
-
-
<tr>
-
<td class='style30'><p class="style31"><label for='zip'>ZIP Code*</label></p></td>
-
<td class="style30"><input type="text" name="zip" size=10 maxlength=10 value="" /></td>
-
</tr>
-
-
<tr>
-
<td class='style30'><p class="style31"><label for='website'>Website*</label></p></td>
-
<td class="style30"><input type="text" name="website" value="http://www." size=45 maxlength=100 value="" /></td>
-
</tr>
-
-
<tr>
-
<td colspan=2><h2 class="style29">Contact Information</h2></td>
-
</tr>
-
-
<tr>
-
<td class='style30'><p class="style31"><label for='contact_name'>Contact Name*</label></p></td>
-
<td class="style30"><input type="text" name="contact_name" size=45 maxlength=100 value="" /></td>
-
</tr>
-
-
<tr>
-
<td class='style30'><p class="style31"><label for='contact_position'>Position</label></p></td>
-
<td class="style30"><input type="text" name="contact_position" size=45 maxlength=100 value="" /></td>
-
</tr>
-
-
<tr>
-
<td class='style30'><p class="style31"><label for='contact_phone'>Phone Number*</label></p></td>
-
<td class="style30"><input type="text" name="contact_phone" size=14 maxlength=14 value="" /></td>
-
</tr>
-
-
<tr>
-
<td class='style30'><p class="style31"><label for='contact_email'>Email Address*</label></p></td>
-
<td class="style30"><input type="text" name="contact_email" size=45 maxlength=100 value="" /></td>
-
</tr>
-
-
<tr>
-
<td class="style30"> </td>
-
<td class="style30"><input type="submit" name ="Add Member" value="Add Member" /></td>
-
</tr>
-
-
</table>
-
</form>
-
|  | Member | | Join Date: Jun 2009 Location: Indiana
Posts: 65
| | | re: Need help with scripting to store data on MySQL
OK! So I changed the posts to match what I have on the form...and still no luck!
I am not sure if the for instance this would be part of the problem "phone_number" what is the underscored line for??? And do I need to do anything for the member ID number since it is a hidden number that should be assigned randomly???
Here is what I have for the addmember_db.php: -
<?php
-
include ("admintasks-dbcon.php");
-
mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
-
mysql_select_db($dbname);
-
$query = "SELECT * FROM add_member WHERE memberID = '{memberID}'";
-
$result = mysql_query( $sql ) or die( mysql_error );
-
-
if ( mysql_num_rows( $res ) > 0 )
-
{
-
-
$query="
-
SELECT add_member SET
-
name = $_POST ['name'];
-
address 1 = $_POST ['address_1'];
-
address 2 = $_POST ['address_2'];
-
City= $_POST ['city'];
-
State = $_POST ['state'];
-
Zip Code = $_POST ['zip'];
-
Website = $_POST ['website'];
-
Contact Name = $_POST ['contact_name'];
-
Position = $_POST ['position'];
-
Phone Number = $_POST ['phone_number'];
-
Email Address = $_POST ['email_address'];)
-
-
WHERE memberID ='{$memberID}'";
-
}
-
else{
-
-
$query="
-
-
INSERT INTO add_member (
-
-
'Member ID',
-
'Name',
-
'Address 1',
-
'Address 2',
-
'City',
-
'State',
-
'Zip Code',
-
'Website',
-
'Contact Name',
-
'Position',
-
'Phone Number',
-
'Email Address')
-
-
VALUES
-
-
'{$_POST['memberID']}',
-
'{$_POST['name']}',
-
'{$_POST['address_1']}',
-
'{$_POST['address_2']}',
-
'{$_POST['city']}',
-
'{$_POST['state']}',
-
'{$_POST['zip']}',
-
'{$_POST['website']}',
-
'{$_POST['contact_name']}',
-
'{$_POST['position']}',
-
'{$_POST['phone_number']}',
-
'{$_POST['email_address']}')";
-
-
$result=mysql_query($query) or die("Error in query:".mysql_error());
-
-
if ( mysql_num_rows( $result ) > 0 )
-
echo mysql_affected_rows()." row inserted into the database effectively.";
-
-
mysql_close();
-
}
-
-
session_start();
-
$_SESSION["Name"] = $_POST['name'];
-
header("location:thankyouforbecomingamember.php");
-
?>
-
and the result of filling in the form and clicking the add member button is: "mysql_error"
|  | Needs Regular Fix | | Join Date: Feb 2009 Location: UK
Posts: 356
| | | re: Need help with scripting to store data on MySQL
that whole piece of coding is incorrect.....you have gone back to your original model instead of using what i fixed for you and just changing the names in the $_POST vars.......
|  | Member | | Join Date: Jun 2009 Location: Indiana
Posts: 65
| | | re: Need help with scripting to store data on MySQL
OK I see what you are saying. I redid the coding and I am getting a header error now! -
<?
-
include ("admintasks-dbcon.php");
-
-
-
$memberID = $_POST['memberID'];
-
$institutionName = $_POST['institutionName'];
-
$address1 = $_POST['address_1'];
-
$address2 = $_POST['address_2'];
-
$city = $_POST['city'];
-
$state = $_POST['state'];
-
$zipCode = $_POST['zipCode'];
-
$website = $_POST['website'];
-
$contactName = $_POST['contactName'];
-
$position = $_POST['position'];
-
$phoneNumber = $_POST['phone'];
-
$email = $_POST['email'];
-
-
// OPEN CONNECTION --->
-
mysql_connect($hostname,$username,$password);
-
@mysql_select_db($dbname) or die( "Unable to select database");
-
-
-
$sql = "SELECT * FROM addMember WHERE email = '{$email}'";
-
$res = mysql_query( $sql ) or die( mysql_error );
-
-
if ( mysql_num_rows( $res ) > 0 )
-
{
-
-
session_start();
-
$_SESSION["contactName"] = $contactName;
-
header("location:alreadyMember.php");
-
-
}
-
else{
-
-
$query="INSERT addMember (
-
-
memberID,
-
institution,
-
address1,
-
address2,
-
city,
-
state,
-
zip,
-
website,
-
contactName,
-
position,
-
phoneNumber,
-
email)
-
-
VALUES ( '".$memberID."',
-
'".$institution."',
-
'".$address1."',
-
'".$address2."',
-
'".$city."',
-
'".$state."',
-
'".$zipCode."',
-
'".$website."',
-
'".$contactName."',
-
'".$position."',
-
'".$phoneNumber."',
-
'".$email."')";
-
-
$result=mysql_query($query) or die("Error in query:".mysql_error());
-
-
session_start();
-
$_SESSION["contactName"] = $contactName;
-
header("location:thankyouforbecomingamember.php");
-
}
-
-
mysql_close();
-
// CLOSE CONNECTION --->
-
?>
-
This is the error I am getting:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/m/i/d/mideasthonors/html/addmember_db.php:1) in /home/content/m/i/d/mideasthonors/html/addmember_db.php on line 29
Warning: Cannot modify header information - headers already sent by (output started at /home/content/m/i/d/mideasthonors/html/addmember_db.php:1) in /home/content/m/i/d/mideasthonors/html/addmember_db.php on line 31
__________________________________________________ ____________
I know this is frustrating, but I really do appreciate all your help. I am just confused on what the issues are. Like I initially said I am still very new to php and have come up with what I originally had on my own, so I am sorry if I do not understand everything to a "T"...I was a PSCI major for my BA and am now a Public Admin. major for my masters, php is NOT my thing. But I have to make this website work for my graduate assistantship, so once again I apologize for not understanding everything you guys are laying out for me. It may be very easy for you to understand but is quite difficult for me. I do not want to copy and paste what you gave me, I would like to figure it out on my own, but at the same time I feel like I am in a realm that I do not understand when I get responses from each of you....at any rate thank you all for your help.
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,635
| | | re: Need help with scripting to store data on MySQL
there seems an output to be sent. I suspect the UTF-8 BOM (Byte Order Mark). you need to open the file in an editor, which can show you hidden characters. it should be right at the beginning of the first line.
once the session error is fixed, the header error should disappear.
|  | Member | | Join Date: Jun 2009 Location: Indiana
Posts: 65
| | | re: Need help with scripting to store data on MySQL
I opened the file in Notepad++ and there was nothing before <? so I am not sure what else I am looking for. I have attached the file in notepad.
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,635
| | | re: Need help with scripting to store data on MySQL
what happens if you use this text file? (I have no other explanaition than the already given...)
|  | Member | | Join Date: Jun 2009 Location: Indiana
Posts: 65
| | | re: Need help with scripting to store data on MySQL
I get the header error. I changed the variables in the _POST and added the dollar signs prior to each variable so they are identified. That is exactly what the other person informed me to do!
|  | Needs Regular Fix | | Join Date: Feb 2009 Location: UK
Posts: 356
| | | re: Need help with scripting to store data on MySQL
i informed you to change the names in the post not to add dollar signs
$_POST['change_this']
|  | Member | | Join Date: May 2009 Location: Nepal
Posts: 62
| | | re: Need help with scripting to store data on MySQL
Dear mideastgirl the above bytes.zip file works very nicely which is given by Mr. anfetienne so follow him.
I have down load this above bytes.zip & copy to all byte on htdocs folder & create database which name is bytes. emport the table from above. & Change here with
mysql_connect($hostname,$username,$password);
@mysql_select_db($dbname) or die( "Unable to select database");
Replace with
mysql_connect("localhost","root"," ");
@mysql_select_db(''addMember) or die( "Unable to select database");
Then after test it. It work nicely.
Thank You
|  | Needs Regular Fix | | Join Date: Feb 2009 Location: UK
Posts: 356
| | | re: Need help with scripting to store data on MySQL
hi, the sample i gave is a complete working model with no errors....thank you luckysanj for testing it.
mideastgirl please note that he changed the sql connection to suit him but you don't have to as i used what you had in your previous code.
all that you needed to change on my code was the $_POST['changeMeHere'] to match the names you have in your table....you didn't have to change anything else, or add dollar signs because it was all written for you.
|  | Member | | Join Date: Jun 2009 Location: Indiana
Posts: 65
| | | re: Need help with scripting to store data on MySQL
I went back through and just copied and pasted the files, which I HATE doing but I am apparently too unintelligent to do otherwise. I am still getting these warnings:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/m/i/d/mideasthonors/html/addmember_db.php:1) in /home/content/m/i/d/mideasthonors/html/addmember_db.php on line 29
Warning: Cannot modify header information - headers already sent by (output started at /home/content/m/i/d/mideasthonors/html/addmember_db.php:1) in /home/content/m/i/d/mideasthonors/html/addmember_db.php on line 31
Here is the coding, which I am sure you already have since it is exactly what you gave me/ except without the error "error_reporting(E_ALL);" on it since it is not for the error page -
<?
-
include ("admintasks-dbcon.php");
-
-
-
$memberID = $_POST['memberID'];
-
$institution = $_POST['institution'];
-
$address1 = $_POST['address_1'];
-
$address2 = $_POST['address_2'];
-
$city = $_POST['city'];
-
$state = $_POST['state'];
-
$zipCode = $_POST['zip'];
-
$website = $_POST['website'];
-
$contactName = $_POST['contactName'];
-
$position = $_POST['position'];
-
$phoneNumber = $_POST['phone'];
-
$email = $_POST['email'];
-
-
// OPEN CONNECTION --->
-
mysql_connect($hostname,$username,$password);
-
@mysql_select_db($dbname) or die( "Unable to select database");
-
-
-
$sql = "SELECT * FROM addMember WHERE email = '{$email}'";
-
$res = mysql_query( $sql ) or die( mysql_error );
-
-
if ( mysql_num_rows( $res ) > 0 )
-
{
-
-
session_start();
-
$_SESSION["contactName"] = $contactName;
-
header("location:alreadyMember.php");
-
-
}
-
else{
-
-
$query="INSERT addMember (
-
-
memberID,
-
institution,
-
address1,
-
address2,
-
city,
-
state,
-
zip,
-
website,
-
contactName,
-
position,
-
phoneNumber,
-
email)
-
-
VALUES ( '".$memberID."',
-
'".$institution."',
-
'".$address1."',
-
'".$address2."',
-
'".$city."',
-
'".$state."',
-
'".$zipCode."',
-
'".$website."',
-
'".$contactName."',
-
'".$position."',
-
'".$phoneNumber."',
-
'".$email."')";
-
-
$result=mysql_query($query) or die("Error in query:".mysql_error());
-
-
session_start();
-
$_SESSION["contactName"] = $contactName;
-
header("location:thankyouforbecomingamember.php");
-
}
-
-
mysql_close();
-
// CLOSE CONNECTION --->
-
?>
-
The other files were literally copy and pasted with no changes made.
|  | Needs Regular Fix | | Join Date: Feb 2009 Location: UK
Posts: 356
| | | re: Need help with scripting to store data on MySQL
as i said before you are getting those warnings because the form you have uses different field names to what is in the $_POST vars on the php code. some of the $_POST vars aren't being filled with the data from the form, so it leaves them with no values and not set. now because the session looks for the value within the set var it gives you an error because there isn't any values within the var.......
thats why i have been stating for you to either change the names within the $_POST to match what you have on your forms or change all field names in your forms to match what you have in your $_POST vars
change the name of these below to match your form field names. -
$memberID = $_POST['memberID'];
-
$institution = $_POST['institution'];
-
$address1 = $_POST['address_1'];
-
$address2 = $_POST['address_2'];
-
$city = $_POST['city'];
-
$state = $_POST['state'];
-
$zipCode = $_POST['zip'];
-
$website = $_POST['website'];
-
$contactName = $_POST['contactName'];
-
$position = $_POST['position'];
-
$phoneNumber = $_POST['phone'];
-
$email = $_POST['email'];
-
|  | Member | | Join Date: Jun 2009 Location: Indiana
Posts: 65
| | | re: Need help with scripting to store data on MySQL
The form= the table in mysql? or the form= what is on the website on http://mideasthonors.org/addmember.php????? |  | Member | | Join Date: Jun 2009 Location: Indiana
Posts: 65
| | | re: Need help with scripting to store data on MySQL
OOOOOKKKKK! So I have redone the scripting, ALL of it! And I think I did it...but now I am getting an unexpected end!!!!
Here is my code: -
<?
-
// OPEN CONNECTION --->
-
include ("admintasks-dbcon.php");
-
mysql_connect($hostname,$username,$password);
-
mysql_select_db($dbname) or die( "Unable to select database");
-
$sql = "SELECT * FROM addMember WHERE email = '{$email}'";
-
$res = mysql_query( $sql ) or die( mysql_error );
-
-
function protect ($VALUE){
-
$VALUE = mysql_real_escape_string ($VALUE);
-
$VALUE = stripslashes (VALUE);
-
}
-
$institution_name = $_POST['institution_name'];
-
$address_1 = $_POST['address_1'];
-
$address_2 = $_POST['address_2'];
-
$city = $_POST['city'];
-
$state = $_POST['state'];
-
$zip_code = $_POST['zip_code'];
-
$website = $_POST['website'];
-
$contact_name = $_POST['contact_name'];
-
$position = $_POST['position'];
-
$phone_number = $_POST['phone_number'];
-
$email = $_POST['email'];
-
protect ($institution_name);
-
protect ($address_1);
-
protect ($address_2);
-
protect ($city);
-
protect ($state);
-
protect ($zip_code);
-
protect ($website);
-
protect ($contact_name);
-
protect ($position);
-
protect ($phone_number);
-
protect ($email);
-
-
if(Isset($institution_name) && Isset($address_1) && Isset($address_2)
-
&& Isset($city) && Isset($state) && Isset($zip_code) && Isset($website) && Isset($contact_name)
-
&& Isset($position) && Isset($phone_number) && Isset($email)){
-
-
-
$sql = "SELECT * FROM addMember WHERE institution_name = '$institution_name'";
-
$res = mysql_query( $sql ) or die( mysql_error());
-
if ( mysql_num_rows( $res ) > 0 ){
-
echo "This instituion is already a member!";
-
}else{
-
$sql = "SELECT * FROM addMember WHERE email= '$email'";
-
$res = mysql_query( $sql ) or die( mysql_error());
-
if ( mysql_num_rows( $res ) > 0 ){
-
}else{
-
$sql = "INSERT INTO addMember(
-
institution_name,
-
address_1,
-
address_2,
-
city, state,
-
zip_code,
-
website,
-
contact_name,
-
position,
-
phone_number,
-
email
-
)
-
VALUES (
-
'$instituion_name',
-
'$address_1',
-
'$address_2',
-
'$city',
-
'$state',
-
'$zip_code',
-
'$website',
-
'$contact_name',
-
'$position',
-
'$phone_number',
-
'$email'
-
);";
-
$res = mysql_query ($sql) or die(mysql_error());
-
-
-
-
session_start();
-
$_SESSION["contactName"] = $contactName;
-
header("location:alreadyMember.php");
-
-
-
-
-
session_start();
-
$_SESSION["contactName"] = $contactName;
-
header("location:thankyouforbecomingamember.php");
-
}
-
-
mysql_close();
-
// CLOSE CONNECTION --->
-
?>
-
Here is my table:
CREATE TABLE `addMember` (
`id` int(6) NOT NULL auto_increment,
`memberID` int(12) NOT NULL default '0',
`institution_name` varchar(45) NOT NULL default '',
`address_1` varchar(45) NOT NULL default '',
`address_2` varchar(45) NOT NULL default '',
`city` varchar(45) NOT NULL default '',
`state` char(2) NOT NULL default '',
`zip_code` int(10) NOT NULL default '0',
`website` text NOT NULL,
`contact_name` varchar(45) NOT NULL default '',
`position` varchar(25) NOT NULL default '',
`phone_number` int(12) NOT NULL default '0',
`email` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
--
-- Dumping data for table `addMember`
--
INSERT INTO `addMember` VALUES(1, 0, '', '', '', '', 'Il', 0, 'http://www.', '', '', 0, '');
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | re: Need help with scripting to store data on MySQL
You have neglected to complete one of your conditional statements, and I can see why - you format your code terribly, or should I say you don't format your code at all. Formatting maintains the readability of code, and thus the prevention and debugging of errors is greatly helped.
See for yourself: -
<?
-
// OPEN CONNECTION --->
-
include ("admintasks-dbcon.php");
-
mysql_connect($hostname, $username, $password);
-
mysql_select_db($dbname) or die("Unable to select database");
-
$sql = "SELECT * FROM addMember WHERE email = '{$email}'";
-
$res = mysql_query($sql) or die(mysql_error);
-
-
function protect($VALUE) {
-
$VALUE = mysql_real_escape_string($VALUE);
-
$VALUE = stripslashes(VALUE);
-
}
-
$institution_name = $_POST['institution_name'];
-
$address_1 = $_POST['address_1'];
-
$address_2 = $_POST['address_2'];
-
$city = $_POST['city'];
-
$state = $_POST['state'];
-
$zip_code = $_POST['zip_code'];
-
$website = $_POST['website'];
-
$contact_name = $_POST['contact_name'];
-
$position = $_POST['position'];
-
$phone_number = $_POST['phone_number'];
-
$email = $_POST['email'];
-
protect($institution_name);
-
protect($address_1);
-
protect($address_2);
-
protect($city);
-
protect($state);
-
protect($zip_code);
-
protect($website);
-
protect($contact_name);
-
protect($position);
-
protect($phone_number);
-
protect($email);
-
-
if (Isset($institution_name) && Isset($address_1) && Isset($address_2) && Isset($city) && Isset($state) && Isset($zip_code) && Isset($website) && Isset($contact_name) && Isset($position) && Isset($phone_number) && Isset($email)) {
-
-
-
$sql = "SELECT * FROM addMember WHERE institution_name = '$institution_name'";
-
$res = mysql_query($sql) or die(mysql_error());
-
if (mysql_num_rows($res) > 0) {
-
echo "This instituion is already a member!";
-
} else {
-
$sql = "SELECT * FROM addMember WHERE email= '$email'";
-
$res = mysql_query($sql) or die(mysql_error());
-
if (mysql_num_rows($res) > 0) {
-
} else {
-
$sql = "INSERT INTO addMember(
-
institution_name,
-
address_1,
-
address_2,
-
city, state,
-
zip_code,
-
website,
-
contact_name,
-
position,
-
phone_number,
-
email
-
)
-
VALUES (
-
'$instituion_name',
-
'$address_1',
-
'$address_2',
-
'$city',
-
'$state',
-
'$zip_code',
-
'$website',
-
'$contact_name',
-
'$position',
-
'$phone_number',
-
'$email'
-
);";
-
$res = mysql_query($sql) or die(mysql_error());
-
-
-
session_start();
-
$_SESSION["contactName"] = $contactName;
-
header("location:alreadyMember.php");
-
-
-
session_start();
-
$_SESSION["contactName"] = $contactName;
-
header("location:thankyouforbecomingamember.php");
-
}
-
-
// Just by the level of indentation, you can tell the closing '}'
-
// should be around this point.
-
-
mysql_close();
-
// CLOSE CONNECTION --->
-
-
?>
-
|  | Member | | Join Date: Jun 2009 Location: Indiana
Posts: 65
| | | re: Need help with scripting to store data on MySQL
my scripting looks nothing like what you posted, how the heck did it come out like that?!
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | re: Need help with scripting to store data on MySQL Quote:
Originally Posted by mideastgirl my scripting looks nothing like what you posted, how the heck did it come out like that?! I formatted it in my IDE (Aptana Studio with PHP plugin).
Formatting your code is a big part of writing it - it increases readability and thus maintainence is much easier.
|  | Member | | Join Date: Jun 2009 Location: Indiana
Posts: 65
| | | re: Need help with scripting to store data on MySQL
Gotcha! I added the extra } because you were right I was missing some. However now instead of the unexpected $end I am just getting a blank page:( It is not going on to the next page that says thank you for becoming a member?!
Any ideas on that?
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | re: Need help with scripting to store data on MySQL
Nothing jumps out at me - try some debugging.
When you're using conditional statements, it's always beneficial, in terms of debugging, to know which conditionals fail, and which don't. You can then determine where your script has been, and where it ended.
Try the following and see if you get any output (we're looking for either 'not going to thank you', or 'going to thank you'). From there, we can narrow down the causes of your problem. -
-
<?
-
// OPEN CONNECTION --->
-
include ("admintasks-dbcon.php");
-
mysql_connect($hostname, $username, $password);
-
mysql_select_db($dbname) or die("Unable to select database");
-
$sql = "SELECT * FROM addMember WHERE email = '{$email}'";
-
$res = mysql_query($sql) or die(mysql_error);
-
-
function protect($VALUE) {
-
$VALUE = mysql_real_escape_string($VALUE);
-
$VALUE = stripslashes(VALUE);
-
}
-
$institution_name = $_POST['institution_name'];
-
$address_1 = $_POST['address_1'];
-
$address_2 = $_POST['address_2'];
-
$city = $_POST['city'];
-
$state = $_POST['state'];
-
$zip_code = $_POST['zip_code'];
-
$website = $_POST['website'];
-
$contact_name = $_POST['contact_name'];
-
$position = $_POST['position'];
-
$phone_number = $_POST['phone_number'];
-
$email = $_POST['email'];
-
protect($institution_name);
-
protect($address_1);
-
protect($address_2);
-
protect($city);
-
protect($state);
-
protect($zip_code);
-
protect($website);
-
protect($contact_name);
-
protect($position);
-
protect($phone_number);
-
protect($email);
-
-
if (Isset($institution_name) && Isset($address_1) && Isset($address_2) && Isset($city) && Isset($state) && Isset($zip_code) && Isset($website) && Isset($contact_name) && Isset($position) && Isset($phone_number) && Isset($email)) {
-
-
-
$sql = "SELECT * FROM addMember WHERE institution_name = '$institution_name'";
-
$res = mysql_query($sql) or die(mysql_error());
-
if (mysql_num_rows($res) > 0) {
-
echo "This instituion is already a member!";
-
} else {
-
$sql = "SELECT * FROM addMember WHERE email= '$email'";
-
$res = mysql_query($sql) or die(mysql_error());
-
if (mysql_num_rows($res) > 0) {
-
echo "not going to thank you - institution name already exists';
-
} else {
-
echo 'going to thank you - institution name doesn\'t exist';
-
$sql = "INSERT INTO addMember(
-
institution_name,
-
address_1,
-
address_2,
-
city, state,
-
zip_code,
-
website,
-
contact_name,
-
position,
-
phone_number,
-
email
-
)
-
VALUES (
-
'$instituion_name',
-
'$address_1',
-
'$address_2',
-
'$city',
-
'$state',
-
'$zip_code',
-
'$website',
-
'$contact_name',
-
'$position',
-
'$phone_number',
-
'$email'
-
);";
-
$res = mysql_query($sql) or die(mysql_error());
-
-
-
session_start();
-
$_SESSION["contactName"] = $contactName;
-
header("location:alreadyMember.php");
-
-
-
session_start();
-
$_SESSION["contactName"] = $contactName;
-
header("location:thankyouforbecomingamember.php");
-
}
-
-
// Just by the level of indentation, you can tell the closing '}'
-
// should be around this point.
-
-
mysql_close();
-
// CLOSE CONNECTION --->
-
-
?>
|  | | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,327 network members.
|