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!
70 5074
the script seems somewhat strange... - is $add_member really the MySQL field name? (single quotes ain't parsed)
- same goes for $row['$yourfield'].
- why do you need to insert the form values for every already existing member?
- you need protection against SQL injection (at least use mysql_real_escape_string($_POST[$key])!)
you can forward to another page by - header('Location: _url_comes_here_');
-
exit;
note: there must not be any output before that.
No add_member is the table name. I thought that was supposed to go there. Also, the table is not for existing members it is for new members.
Maybe I am confused about what needs to go where.
Thanks.
Atli 5,058
Expert 4TB
Hi.
The problem there is just with the basic syntax.
First, as Dormilich pointed out, while variables are parse within double-quoted strings, they are not parsed within single-quoted strings. (See PHP: Strings - Manual)
Which means your query on line #6 is literally being sent as: SELECT * FROM $add_member, whereas you probably meant for it to insert the value of $add_member.
If you want that to happen, you need to use double-quotes, rather than single-quotes.
And second:
The if statement on line #9, which checks the result of the SQL query, does not provide any code in case the check fails. Which means that every time the query fails, you are shown a blank page.
You should add an else clause, and print an error message or something, just so you don't get a useless blank page.
the 1st sql query is relevant if you want to check for duplicate entries. but i dont see why you have a while loop in the when you can check if using
if ( mysql_num_rows( $res ) > 0 )
{
UPDATE table
}
else{
INSERT INTO table
}
look at this example that i have of a form and the php to add it to sql (please excuse the length of the form there is alot of javascript for tinyMCE included in my form)
FORM CODE -
<form id="form1" name="form1" method="POST" action="save.php">
-
<tr>
-
<td>
-
<input type="hidden" name="rtrnURL" id="rtrnURL" value='<?php print $rtrnURL;?>'/>
-
<input type="hidden" name="tempID" id="tempID" value='<?php print $random_digit;?>'/>
-
<input type="hidden" name="htmlcss" id="htmlcss" value='<?php print $htmlcss;?>'/>
-
<input type="hidden" name="header" id="header" value='<?php print $header;?>'/>
-
<input type="hidden" name="nav" id="nav" value='<?php print $nav;?>'/>
-
<input type="hidden" name="titleWrap01" id="titleWrap01" value='<?php print $titleWrap01;?>'/>
-
<input type="hidden" name="titleWrap02" id="titleWrap02" value='<?php print $titleWrap02;?>'/>
-
<input type="hidden" name="subheadWrap01" id="subheadWrap01" value='<?php print $subheadWrap01;?>'/>
-
<input type="hidden" name="subheadWrap02" id="subheadWrap02" value='<?php print $subheadWrap02;?>'/>
-
<input type="hidden" name="flashWrap01" id="flashWrap01" value='<?php print $flashWrap01;?>'/>
-
<input type="hidden" name="flashWrap02" id="flashWrap02" value='<?php print $flashWrap02;?>'/>
-
<input type="hidden" name="flash01" id="flash01" value='var so = new SWFObject("<?php print $flashURL;?>", "gallery", "518", "536", "8", "#FFFFFF");'/>
-
<input type="hidden" name="flashVar" id="flashVar" value='<?php print $flashVar;?>'/>
-
<input type="hidden" name="flash02" id="flash02" value='<?php print $flash02;?>'/>
-
<input type="hidden" name="flashWrap03" id="flashWrap03" value='<?php print $flashWrap03;?>'/>
-
<input type="hidden" name="descriptionWrap01" id="descriptionWrap01" value='<?php print $descriptionWrap01;?>'/>
-
<input type="hidden" name="descriptionWrap02" id="descriptionWrap02" value='<?php print $descriptionWrap02;?>'/>
-
<input type="hidden" name="generalWrap01" id="generalWrap01" value='<?php print $generalWrap01;?>'/>
-
<input type="hidden" name="generalWrap02" id="generalWrap02" value='<?php print $generalWrap02;?>'/>
-
<input type="hidden" name="aboutWrap01" id="aboutWrap01" value='<?php print $aboutWrap01;?>'/>
-
<input type="hidden" name="aboutWrap02" id="aboutWrap02" value='<?php print $aboutWrap02;?>'/>
-
<input type="hidden" name="paymentWrap01" id="paymentWrap01" value='<?php print $paymentWrap01;?>'/>
-
<input type="hidden" name="paymentWrap02" id="paymentWrap02" value='<?php print $paymentWrap02;?>'/>
-
<input type="hidden" name="termsWrap01" id="termsWrap01" value='<?php print $termsWrap01;?>'/>
-
<input type="hidden" name="termsWrap02" id="termsWrap02" value='<?php print $termsWrap02;?>'/>
-
<input type="hidden" name="footer" id="footer" value='<?php print $footer;?>'/>
-
</td>
-
</tr>
-
-
<table width="700" border="0" align="center" cellpadding="2" cellspacing="2">
-
<tr>
-
<p>
-
<center><input name="Submit2" type="submit" value="Save Template" />
-
<br />
-
</center>
-
</p>
-
</tr>
-
<tr>
-
<td>Title</td>
-
<td><input name="title" type="text" value="<? print $row['title'];?>" size="75" maxlength="60" /></td>
-
</tr>
-
<tr>
-
<td>Subtitle</td>
-
<td><input name="subheading" type="text" value="<? print $row['subheading'];?>" size="75" /></td>
-
</tr>
-
<tr>
-
<td>Description</td>
-
<script type="text/javascript">
-
tinyMCE.init({
-
mode : "exact"
-
,elements : "id_description"
-
,theme : "advanced"
-
,theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,formatselect,fontselect,fontsizeselect"
-
,theme_advanced_buttons2 : "cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,|,image,charmap,emotions,iespell,media,advhr,|,ltr,rtl,|,code,fullscreen"
-
,theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,"
-
,theme_advanced_buttons4 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,|,forecolor,backcolor"
-
,theme_advanced_toolbar_location : "top"
-
,theme_advanced_toolbar_align : "left"
-
,theme_advanced_statusbar_location : "bottom"
-
,theme_advanced_resizing : true
-
,theme_advanced_resize_horizontal : false
-
,plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups"
-
});
-
</script>
-
<td><textarea name="description" cols="75" id="id_description" style="width:450px; height:350px;"><? echo $row['description'];?></textarea></td>
-
</tr>
-
<tr>
-
<td>General Information</td>
-
<script type="text/javascript">
-
tinyMCE.init({
-
mode : "exact"
-
,elements : "id_general"
-
,theme : "advanced"
-
,theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,formatselect,fontselect,fontsizeselect"
-
,theme_advanced_buttons2 : "cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,|,image,charmap,emotions,iespell,media,advhr,|,ltr,rtl,|,code,fullscreen"
-
,theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,"
-
,theme_advanced_buttons4 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,|,forecolor,backcolor"
-
,theme_advanced_toolbar_location : "top"
-
,theme_advanced_toolbar_align : "left"
-
,theme_advanced_statusbar_location : "bottom"
-
,theme_advanced_resizing : true
-
,theme_advanced_resize_horizontal : false
-
,plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups"
-
});
-
</script>
-
<td><textarea style="width:450px; height:350px;" id="id_general" name="general"><? echo $row['general'];?></textarea></td>
-
</tr>
-
<tr>
-
<td>Terms & Conditions</td>
-
<script type="text/javascript">
-
tinyMCE.init({
-
mode : "exact"
-
,elements : "id_terms"
-
,theme : "advanced"
-
,theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,formatselect,fontselect,fontsizeselect"
-
,theme_advanced_buttons2 : "cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,|,image,charmap,emotions,iespell,media,advhr,|,ltr,rtl,|,code,fullscreen"
-
,theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,"
-
,theme_advanced_buttons4 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,|,forecolor,backcolor"
-
,theme_advanced_toolbar_location : "top"
-
,theme_advanced_toolbar_align : "left"
-
,theme_advanced_statusbar_location : "bottom"
-
,theme_advanced_resizing : true
-
,theme_advanced_resize_horizontal : false
-
,plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups"
-
});
-
-
</script>
-
<td><textarea style="width:450px; height:350px;" id="id_terms" name="terms"><? echo $row['terms'];?></textarea></td>
-
</tr>
-
<tr>
-
<td>About Us</td>
-
<script type="text/javascript">
-
tinyMCE.init({
-
mode : "exact"
-
,elements : "id_about"
-
,theme : "advanced"
-
,theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,formatselect,fontselect,fontsizeselect"
-
,theme_advanced_buttons2 : "cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,|,image,charmap,emotions,iespell,media,advhr,|,ltr,rtl,|,code,fullscreen"
-
,theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,"
-
,theme_advanced_buttons4 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,|,forecolor,backcolor"
-
,theme_advanced_toolbar_location : "top"
-
,theme_advanced_toolbar_align : "left"
-
,theme_advanced_statusbar_location : "bottom"
-
,theme_advanced_resizing : true
-
,theme_advanced_resize_horizontal : false
-
,plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups"
-
});
-
</script>
-
<td><textarea style="width:450px; height:350px;" id="id_about" name="about"><? echo $row['about'];?></textarea></td>
-
</tr>
-
<tr>
-
<td>Payment Methods</td>
-
<td><table width="192" border="0" cellspacing="0" cellpadding="0">
-
<tr>
-
<td width="134"> </td>
-
<td width="58"> </td>
-
</tr>
-
<tr>
-
<td>PayPal </td>
-
<td><input type="checkbox" name="payment01" id="payment01" value="<img src=http://theauctionwinners.com/resources/temp/paypal.gif>"/></td>
-
</tr>
-
<tr>
-
<td>Personal Cheques </td>
-
<td><input type="checkbox" name="payment02" id="payment02" value="<img src=http://theauctionwinners.com/resources/temp/cheque.gif>"/></td>
-
</tr>
-
</table></td>
-
</tr>
-
<tr>
-
<td colspan="2"><div align="center">
-
<p>
-
<center> <input name="Submit" type="submit" value="Save Template" />
-
</form>
-
DATABASE PAGE -
<?php
-
$username="username";
-
$password="password";
-
$database="database";
-
-
$rtrnURL = $_POST['rtrnURL'];
-
$tempID = $_POST['tempID'];
-
$htmlcss = $_POST['htmlcss'];
-
$header = $_POST['header'];
-
$nav = $_POST['nav'];
-
$titleWrap01 = $_POST['titleWrap01'];
-
$title = $_POST['title'];
-
$titleWrap02 = $_POST['titleWrap02'];
-
$subheadWrap01 = $_POST['subheadWrap01'];
-
$subheading = $_POST['subheading'];
-
$subheadWrap02 = $_POST['subheadWrap02'];
-
$flashWrap01 = $_POST['flashWrap01'];
-
$flashWrap02 = $_POST['flashWrap02'];
-
$flash01 = $_POST['flash01'];
-
$flashVar = $_POST['flashVar'];
-
$flash02 = $_POST['flash02'];
-
$flashWrap03 = $_POST['flashWrap03'];
-
$descriptionWrap01 = $_POST['descriptionWrap01'];
-
$description = $_POST['description'];
-
$descriptionWrap02 = $_POST['descriptionWrap02'];
-
$generalWrap01 = $_POST['generalWrap01'];
-
$general = $_POST['general'];
-
$generalWrap02 = $_POST['generalWrap02'];
-
$aboutWrap01 = $_POST['aboutWrap01'];
-
$about = $_POST['about'];
-
$aboutWrap02 = $_POST['aboutWrap02'];
-
$paymentWrap01 = $_POST['paymentWrap01'];
-
$payment01 = $_POST['payment01'];
-
$payment02 = $_POST['payment02'];
-
$paymentWrap02 = $_POST['paymentWrap02'];
-
$termsWrap01 = $_POST['termsWrap01'];
-
$terms = $_POST['terms'];
-
$termsWrap02 = $_POST['termsWrap02'];
-
$footer = $_POST['footer'];
-
-
// OPEN CONNECTION --->
-
$connection=mysql_connect("localhost" ,"$username", "$password") or die("Unable to connect!");
-
-
mysql_select_db("$database") or die("Unable to select database!");
-
-
// Select column 1 from table name where column name = $your_var.
-
$sql = "SELECT * FROM savedTemps WHERE tempID = '{$tempID}'";
-
// If mysql_query returns false, we'll die with the error.
-
$res = mysql_query( $sql ) or die( mysql_error );
-
-
// If a there is a match
-
if ( mysql_num_rows( $res ) > 0 )
-
{
-
-
$query="
-
-
UPDATE savedTemps SET
-
-
htmlcss='{$htmlcss}',
-
header='{$header}',
-
nav='{$nav}',
-
titleWrap01='{$titleWrap01}',
-
title='{$title}',
-
titleWrap02='{$titleWrap02}',
-
subheadWrap01='{$subheadWrap01}',
-
subheading='{$subheading}',
-
subheadWrap02='{$subheadWrap02}',
-
flashWrap01='{$flashWrap01}',
-
flashWrap02='{$flashWrap02}',
-
flash01='{$flash01}',
-
flashVar='{$flashVar}',
-
flash02='{$flash02}',
-
flashWrap03='{$flashWrap03}',
-
descriptionWrap01='{$descriptionWrap01}',
-
description='{$description}',
-
descriptionWrap02='{$descriptionWrap02}',
-
generalWrap01='{$generalWrap01}',
-
general='{$general}',
-
generalWrap02='{$generalWrap02}',
-
aboutWrap01='{$aboutWrap01}',
-
about='{$about}',
-
aboutWrap02='{$aboutWrap02}',
-
paymentWrap01='{$paymentWrap01}',
-
payment01='{$payment01}',
-
payment02='{$payment02}',
-
paymentWrap02='{$paymentWrap02}',
-
termsWrap01='{$termsWrap01}',
-
terms='{$terms}',
-
termsWrap02='{$termsWrap02}',
-
footer='{$footer}'
-
-
WHERE tempID='{$tempID}'";
-
}
-
else
-
{
-
// EXECUTE QUERY --->
-
$query="INSERT savedTemps (
-
-
tempID,
-
htmlcss,
-
header,
-
nav,
-
titleWrap01,
-
title,
-
titleWrap02,
-
subheadWrap01,
-
subheading,
-
subheadWrap02,
-
flashWrap01,
-
flashWrap02,
-
flash01,
-
flashVar,
-
flash02,
-
flashWrap03,
-
descriptionWrap01,
-
description,
-
descriptionWrap02,
-
generalWrap01,
-
general,
-
generalWrap02,
-
aboutWrap01,
-
about,
-
aboutWrap02,
-
paymentWrap01,
-
payment01,
-
payment02,
-
paymentWrap02,
-
termsWrap01,
-
terms,
-
termsWrap02,
-
footer)
-
-
VALUES(
-
'".$tempID."',
-
'".$htmlcss."',
-
'".$header."',
-
'".$nav."',
-
'".$titleWrap01."',
-
'".$title."',
-
'".$titleWrap02."',
-
'".$subheadWrap01."',
-
'".$subheading."',
-
'".$subheadWrap02."',
-
'".$flashWrap01."',
-
'".$flashWrap02."',
-
'".$flash01."',
-
'".$flashVar."',
-
'".$flash02."',
-
'".$flashWrap03."',
-
'".$descriptionWrap01."',
-
'".$description."',
-
'".$descriptionWrap02."',
-
'".$generalWrap01."',
-
'".$general."',
-
'".$generalWrap02."',
-
'".$aboutWrap01."',
-
'".$about."',
-
'".$aboutWrap02."',
-
'".$paymentWrap01."',
-
'".$payment01."',
-
'".$payment02."',
-
'".$paymentWrap02."',
-
'".$termsWrap01."',
-
'".$terms."',
-
'".$termsWrap02."',
-
'".$footer."')";
-
}
-
-
-
//////----->
-
$result=mysql_query($query) or die("Error in query:".mysql_error());
-
//if ($result)
-
//echo mysql_affected_rows()." row inserted into the database effectively.";
-
-
// CLOSE CONNECTION --->
-
mysql_close($connection);
-
-
///////////////////////////////////////////////////////////////////////////////////
-
-
?>
-
Thank you both for your help!
I think I was able to progress! But there still seems to be a glitch somewhere, because I keep getting the mysql error message now??? -
<?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( $sql ) or die( mysql_error );
-
if ( mysql_num_rows( $res ) > 0 )
-
{
-
$query="
-
UPDATE $add_member
-
{
-
else{
-
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']})";
-
-
$result=mysql_query($query) or die("Error in query:".mysql_error());
-
if ($result)
-
echo mysql_affected_rows()." row inserted into the database effectively.";
-
-
mysql_close($connection);
-
}
-
?>
-
I also need the page to go onto a thank you page or an error page if all of the information has not been entered. I know that I would use header("Location: page name");
but where would I put this???
ok....well for starters you haven't set anything to the UPDATE i.e. -
UPDATE savedTemps SET
-
-
htmlcss='{$htmlcss}',
-
header='{$header}',
-
nav='{$nav}',
-
titleWrap01='{$titleWrap01}',
-
title='{$title}',
-
titleWrap02='{$titleWrap02}',
-
subheadWrap01='{$subheadWrap01}',
-
subheading='{$subheading}',
-
subheadWrap02='{$subheadWrap02}',
-
flashWrap01='{$flashWrap01}',
-
flashWrap02='{$flashWrap02}',
-
flash01='{$flash01}',
-
flashVar='{$flashVar}',
-
flash02='{$flash02}',
-
flashWrap03='{$flashWrap03}',
-
descriptionWrap01='{$descriptionWrap01}',
-
description='{$description}',
-
descriptionWrap02='{$descriptionWrap02}',
-
generalWrap01='{$generalWrap01}',
-
general='{$general}',
-
generalWrap02='{$generalWrap02}',
-
aboutWrap01='{$aboutWrap01}',
-
about='{$about}',
-
aboutWrap02='{$aboutWrap02}',
-
paymentWrap01='{$paymentWrap01}',
-
payment01='{$payment01}',
-
payment02='{$payment02}',
-
paymentWrap02='{$paymentWrap02}',
-
termsWrap01='{$termsWrap01}',
-
terms='{$terms}',
-
termsWrap02='{$termsWrap02}',
-
footer='{$footer}'
-
-
WHERE tempID='{$tempID}'";
-
and you have sql coding in the wrong place.....bare with me a sec
try this....i've seperated it all so you can see clearer what i've done.
also maybe you should think about giving people a member ID it would be easier to update table fields using it since it's the only item that doesn't and maybe won't change....or a username???
a random digit is good for memberID, put it on the page where the form is and include it in a hidden field in your form like this:
MEMBER ID -
<?php
-
$memberID=rand(0000000,9999999);
-
?>
-
-
<input type="hidden" name="memberID" id="memberID" value="<?php print $memberID;?>" />
-
FULL CODE -
<?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 )
-
{
-
//and here you had no data specified or fields specified
-
-
$query="
-
UPDATE $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 code']}',
-
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{
-
//in this section you had the following...your sql wasn't inside the loop and also there was no $query=""
-
-
# 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']})";
-
#
-
$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 code']},
-
{$_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:thankYou.php");
-
?>
-
and on your following page if you wanted to say
"Thank You (Member's Name),"
use this code to include it in -
<?
-
session_start();
-
$Name = $_SESSION["Name"];
-
?>
-
-
//example
-
"Thank You <?php print $Name;?>, for registering!"
-
also 1 question.....
in your config file is $add_member = add_member???
I am not sure what you mean by config, file unless you mean the file that connects to mysql and in that case no it is just add_member for the table name.
Is that what you are asking?
I have not tried your scripting yet, but I will and thank you. I will let you know if that is successful.
yeah....if thats the case you need to take the dollar sign off your sql code so its
INSERT INTO add_member and SELECT * FROM add_member
Well thank you for all that help! I have made the changes you suggested and am now getting this error:
Parse error: syntax error, unexpected T_ELSE in /home/content/m/i/d/mideasthonors/html/addmember_db.php on line 27
Here is the code I am using: -
<?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="
-
UPDATE 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 code']}',
-
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 code']},
-
{$_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");
-
?>
-
on line 26 you haven't closed the previous loop
change { to } and it should work
those errors are easily fixed if you keep an eye on your syntax (and a good editor helps a lot here, because it can show you which parentheses/brackets belong together)
Now it is just saying mysql_error
Does this mean it could not connect to mysql or that the information could not be added for some reason???
im wondering if its because of these on your sql insert
{$_POST['email address']}
try put it within quotes like below and see if that helps? (note it is a single quote then double quote)
'"{$_POST['email address']}"'
or assign them to vars like i have done in this code below -
<?
-
session_start();
-
if(!$_SESSION['myusername']){
-
header("location:index.php");
-
}
-
-
include ("admin-dbcon.php");
-
-
$rtrnURL = $_POST['rtrnURL'];
-
$tempID = $_POST['tempID'];
-
$htmlcss = $_POST['htmlcss'];
-
$header = $_POST['header'];
-
$nav = $_POST['nav'];
-
$titleWrap01 = $_POST['titleWrap01'];
-
$title = $_POST['title'];
-
$titleWrap02 = $_POST['titleWrap02'];
-
$subheadWrap01 = $_POST['subheadWrap01'];
-
$subheading = $_POST['subheading'];
-
$subheadWrap02 = $_POST['subheadWrap02'];
-
$flashWrap01 = $_POST['flashWrap01'];
-
$flashWrap02 = $_POST['flashWrap02'];
-
$flash01 = $_POST['flash01'];
-
$flashVar = $_POST['flashVar'];
-
$flash02 = $_POST['flash02'];
-
$flashWrap03 = $_POST['flashWrap03'];
-
$descriptionWrap01 = $_POST['descriptionWrap01'];
-
$description = $_POST['description'];
-
$descriptionWrap02 = $_POST['descriptionWrap02'];
-
$generalWrap01 = $_POST['generalWrap01'];
-
$general = $_POST['general'];
-
$generalWrap02 = $_POST['generalWrap02'];
-
$aboutWrap01 = $_POST['aboutWrap01'];
-
$about = $_POST['about'];
-
$aboutWrap02 = $_POST['aboutWrap02'];
-
$paymentWrap01 = $_POST['paymentWrap01'];
-
$payment01 = $_POST['payment01'];
-
$payment02 = $_POST['payment02'];
-
$paymentWrap02 = $_POST['paymentWrap02'];
-
$termsWrap01 = $_POST['termsWrap01'];
-
$terms = $_POST['terms'];
-
$termsWrap02 = $_POST['termsWrap02'];
-
$footer = $_POST['footer'];
-
-
// OPEN CONNECTION --->
-
mysql_connect($hostname,$username,$password);
-
@mysql_select_db($database) or die( "Unable to select database");
-
-
// Select column 1 from table name where column name = $your_var.
-
$sql = "SELECT * FROM savedTemps WHERE tempID = '{$tempID}'";
-
// If mysql_query returns false, we'll die with the error.
-
$res = mysql_query( $sql ) or die( mysql_error );
-
-
// If a there is a match
-
if ( mysql_num_rows( $res ) > 0 )
-
{
-
-
$query="
-
-
UPDATE savedTemps SET
-
-
htmlcss='{$htmlcss}',
-
header='{$header}',
-
nav='{$nav}',
-
titleWrap01='{$titleWrap01}',
-
title='{$title}',
-
titleWrap02='{$titleWrap02}',
-
subheadWrap01='{$subheadWrap01}',
-
subheading='{$subheading}',
-
subheadWrap02='{$subheadWrap02}',
-
flashWrap01='{$flashWrap01}',
-
flashWrap02='{$flashWrap02}',
-
flash01='{$flash01}',
-
flashVar='{$flashVar}',
-
flash02='{$flash02}',
-
flashWrap03='{$flashWrap03}',
-
descriptionWrap01='{$descriptionWrap01}',
-
description='{$description}',
-
descriptionWrap02='{$descriptionWrap02}',
-
generalWrap01='{$generalWrap01}',
-
general='{$general}',
-
generalWrap02='{$generalWrap02}',
-
aboutWrap01='{$aboutWrap01}',
-
about='{$about}',
-
aboutWrap02='{$aboutWrap02}',
-
paymentWrap01='{$paymentWrap01}',
-
payment01='{$payment01}',
-
payment02='{$payment02}',
-
paymentWrap02='{$paymentWrap02}',
-
termsWrap01='{$termsWrap01}',
-
terms='{$terms}',
-
termsWrap02='{$termsWrap02}',
-
footer='{$footer}'
-
-
WHERE tempID='{$tempID}'";
-
}
-
else
-
{
-
// EXECUTE QUERY --->
-
$query="INSERT savedTemps (
-
-
tempID,
-
htmlcss,
-
header,
-
nav,
-
titleWrap01,
-
title,
-
titleWrap02,
-
subheadWrap01,
-
subheading,
-
subheadWrap02,
-
flashWrap01,
-
flashWrap02,
-
flash01,
-
flashVar,
-
flash02,
-
flashWrap03,
-
descriptionWrap01,
-
description,
-
descriptionWrap02,
-
generalWrap01,
-
general,
-
generalWrap02,
-
aboutWrap01,
-
about,
-
aboutWrap02,
-
paymentWrap01,
-
payment01,
-
payment02,
-
paymentWrap02,
-
termsWrap01,
-
terms,
-
termsWrap02,
-
footer)
-
-
VALUES(
-
'".$tempID."',
-
'".$htmlcss."',
-
'".$header."',
-
'".$nav."',
-
'".$titleWrap01."',
-
'".$title."',
-
'".$titleWrap02."',
-
'".$subheadWrap01."',
-
'".$subheading."',
-
'".$subheadWrap02."',
-
'".$flashWrap01."',
-
'".$flashWrap02."',
-
'".$flash01."',
-
'".$flashVar."',
-
'".$flash02."',
-
'".$flashWrap03."',
-
'".$descriptionWrap01."',
-
'".$description."',
-
'".$descriptionWrap02."',
-
'".$generalWrap01."',
-
'".$general."',
-
'".$generalWrap02."',
-
'".$aboutWrap01."',
-
'".$about."',
-
'".$aboutWrap02."',
-
'".$paymentWrap01."',
-
'".$payment01."',
-
'".$payment02."',
-
'".$paymentWrap02."',
-
'".$termsWrap01."',
-
'".$terms."',
-
'".$termsWrap02."',
-
'".$footer."')";
-
}
-
-
-
//////----->
-
$result=mysql_query($query) or die("Error in query:".mysql_error());
-
//if ($result)
-
//echo mysql_affected_rows()." row inserted into the database effectively.";
-
-
// CLOSE CONNECTION --->
-
mysql_close();
-
?>
-
<script language="JavaScript">
-
<!--
-
window.location="<? print $rtrnURL?>";
-
//-->
-
</SCRIPT>
-
can you export you sql table to a text file and attach it to a post so i can test and see where you code is going wrong?
Database mideasthonors
Table structure for table add_member
Field Type Null Default
Institution varchar(45) No
Address 1 varchar(45) No
Address 2 varchar(45) No
City varchar(45) No
State varchar(2) No
Zip Code int(5) No 0
Website text No
Contact Name varchar(45) No
Position varchar(25) No
Phone Number int(12) No 0
Email text No
Dumping data for table add_member
Institution Address 1 Address 2 City State Zip Code Website Contact Name Position Phone Number Email
@anfetienne
this would be a good place to apply mysql_real_escape_string() to prevent SQL injection
that is a good idea dorm....as always
im going to test this on mine
Well I tried both of your suggestions and I keep getting the same result:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/m/i/d/mideasthonors/html/addmember_db.php on line 13
This is my script: -
<?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="
-
UPDATE 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 code'],
-
$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 code']},
-
{$_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");
-
?>
-
Dormilich,
Would I place it before each item that will be entered by the person becoming a member?
For example:
mysql_real_escape_string (name = $_POST['name']),
Would that we right?
@mideastgirl
of course, look again at anfetienne's sample code and try to figure out the differences you made (despite the variable names)
@mideastgirl
nope, this way you'd not use mysql_real_escape_string() at all (beside getting a warning for undefined constants). refer to the manual for the correct syntax.
sorry for the rather inconvenient way of my answer, but you need to learn those basic syntax stuff.
@anfetienne
I'll stick to Prepared Statements--much safer than only escaping the data.
although PHP Filters are quite useful too.
Noticed the difference between the two was the semi-colons at the end instead of the commas I used. I have replaced the commas with semi-colons but the problem is still happening!:(
one more hint.
check where anfetienne defined his variables.
one thing that has been bugging my brains on this is......is this a 1st process sign up?
i.e. is this page used to sign members up? if so there may not be a need for the UPDATE....you just do a straight INSERT
if its a sign up page then there is no need for the UPDATE query, it should be SELECT to check if the member exists
ok one problem of yours lies here, you have variables where the names of you table cloumns should be. take the dollar sign off and that may work. -
UPDATE 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 code'],
-
$Website = $_POST['website'],
-
$Contact Name = $_POST['contact name'],
-
$Position = $_POST['position'],
-
$Phone Number = $_POST['phone number'],
-
$Email Address = $_POST['email address'])
-
-
WHERE memberID ='{$memberID}'";
-
secondly when inserting you really should use quotes where the values are....i.e. where you have {$_POST['email address']} is should be within quotes -
INSERT INTO add_member (
-
-
memberID,
-
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 code']},
-
{$_POST['website']},
-
{$_POST['contact name']},
-
{$_POST['position']},
-
{$_POST['phone number']},
-
{$_POST['email address']})";
-
thirdly the sql you gave did not have a memerID column, you are running a SQL UPDATE to a specified column that doesn't exist. also on the UPDATE you have $memberID but no values assigned to the variable.
there are also errors on your form and error in sql connection....
e.g.
zip code on your form is named zip and in your php zip code
Ok I have updated the php document I am still returning a mysql error. I added member ID as a column in my table, I have updated zip to zip code within the table as well. I have added quotes around the values. I am not sure what I should do next! -
<?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 code'];
-
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 code']}',
-
'{$_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");
-
?>
-
Here is the table:
Institution MemberID Address 1 Address 2 City State Zip Code Website Contact Name Position Phone Number Email
ok i have corrected everything from your form down to the database. here is the coding of each page. they are saved as the name states as php files (i have attached a zip with all files).....
to see it in action go to database test
index.php (form page) -
<!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>
-
<?php $memberID = rand(0000000000,9999999999);?>
-
<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">
-
*<input type="hidden" name="memberID" id="memberID" value="<?php print $memberID;?>" />
-
-
<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="institution" 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="address1" size=45 maxlength=100 value="" /></td>
-
</tr>
-
-
<tr>
-
<td class="style30"> </td>
-
<td class="style30"><input type="text" name="address2" 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="contactName" 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="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="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="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>
-
addmember.php (please note how i assigned variables to each $_POST and used lower case on all first words the capitals on second words with no spaces this helps it be read easier with no confusion. The UPDATE query has been removed as its for signups and take note of how i put the variables in single and double quotes for the values in the INSERT query. this is how it should have been and this is what you were missing before along with all other mistakes and naming mistakes) -
<? error_reporting(E_ALL);
-
-
include ("admintasks-dbcon.php");
-
-
$memberID = $_POST['memberID'];
-
$institution = $_POST['institution'];
-
$address1 = $_POST['address1'];
-
$address2 = $_POST['address2'];
-
$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($database) 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:thankYou.php");
-
}
-
-
mysql_close();
-
-
?>
-
thankYou.php (please note the session start at the top and how their name is including on the page) -
<?
-
session_start();
-
$contactName = $_SESSION["contactName"];
-
?>
-
-
<!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" />
-
<title>Untitled Document</title>
-
</head>
-
-
<body>
-
Thank You <?php echo $contactName;?>... You have signed up SUCCESSFULLY!
-
</body>
-
</html>
-
alreadyMember.php (note the same as above) -
<?
-
session_start();
-
$contactName = $_SESSION["contactName"];
-
?>
-
-
<!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" />
-
<title>Untitled Document</title>
-
</head>
-
-
<body>
-
We're Sorry <?php echo $contactName;?>... But it seems that you are already a member!
-
</body>
-
</html>
-
MySql Table Structure (please take note of the columns ive included and as above how i have named them lower case first words wit Capital second words for ease....please delete the add_member table you already have and import the addMember.sql file included within the attached zip file) -
-- phpMyAdmin SQL Dump
-
-- version 2.11.9.5
-
-- http://www.phpmyadmin.net
-
--
-
-- Host: localhost
-
-- Generation Time: Jul 27, 2009 at 10:47 AM
-
-- Server version: 5.0.77
-
-- PHP Version: 5.2.6
-
-
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
-
-
--
-
-- Database: `theau10_resources`
-
--
-
-
-- --------------------------------------------------------
-
-
--
-
-- Table structure for table `addMember`
-
--
-
-
CREATE TABLE IF NOT EXISTS `addMember` (
-
`id` int(6) NOT NULL auto_increment,
-
`memberID` int(12) NOT NULL,
-
`institution` varchar(45) NOT NULL,
-
`address1` varchar(45) NOT NULL,
-
`address2` varchar(45) NOT NULL,
-
`city` varchar(45) NOT NULL,
-
`state` varchar(2) NOT NULL,
-
`zip` int(10) NOT NULL,
-
`website` text NOT NULL,
-
`contactName` varchar(45) NOT NULL,
-
`position` varchar(25) NOT NULL,
-
`phoneNumber` int(12) NOT NULL,
-
`email` text NOT NULL,
-
PRIMARY KEY (`id`)
-
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
-
-
--
-
-- Dumping data for table `addMember`
-
--
-
-
-
admintasks-dbcon.php (update this to your details) -
<?
-
$hostname="localhost";
-
$username="";
-
$password="";
-
$dbname="";
-
?>
-
As much as I would love to tell you that worked....it didn't! Sorry!
This is the error I got:
Notice: Undefined index: memberID in /home/content/m/i/d/mideasthonors/html/addmember_db.php on line 6
Notice: Undefined index: institution in /home/content/m/i/d/mideasthonors/html/addmember_db.php on line 7
Notice: Undefined index: address1 in /home/content/m/i/d/mideasthonors/html/addmember_db.php on line 8
Notice: Undefined index: address2 in /home/content/m/i/d/mideasthonors/html/addmember_db.php on line 9
Notice: Undefined index: contactName in /home/content/m/i/d/mideasthonors/html/addmember_db.php on line 14
Notice: Undefined index: position in /home/content/m/i/d/mideasthonors/html/addmember_db.php on line 15
Notice: Undefined index: phone in /home/content/m/i/d/mideasthonors/html/addmember_db.php on line 16
Notice: Undefined index: email in /home/content/m/i/d/mideasthonors/html/addmember_db.php on line 17
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 30
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 32
This is what is in that file: -
<? error_reporting(E_ALL);
-
-
include ("admintasks-dbcon.php");
-
-
-
$memberID = $_POST['memberID'];
-
$institution = $_POST['institution'];
-
$address1 = $_POST['address1'];
-
$address2 = $_POST['address2'];
-
$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 --->
-
?>
-
if there's no post (aka $_POST is empty) there will be no indexes to access giving you these errors.
the header error is a direct result of the previous error messages, no need to worry now.
so something is wrong with my header is what you are telling me???
@mideastgirl
nope, just the opposite. the error messages about "undefined index" (which counts as output) cause your header function to throw out these header errors.
oh. What can I do to fix that???
oh you are so vague! Ok so I would go about fixing the undefined indexes HOW!!!!!
you might be getting the errors because you haven't changed the names in your form therefore its not populating the $_POST.
i gave you complete files from the form to sql....and i also gave a link to show exactly how it works. everything starts with the form so check to make sure the field names corresponding to the errored $_POST are correctly named the same as the $_POST. http://theauctionwinners.com/test/
download the attachment from my post and just copy all files.....rename them as you wish but there is no need to change the coding. but the must do is import the sql.
let me know and send a test link when you have done that
@mideastgirl
am I? I'd consider my answers rather clear, though I try to point you in the direction of the solution rather than posting code.
btw, programming does require thinking* (though a logical mind helps a lot). copy & paste won't get you too far.
* - compare it to games (say, chess). you don't become a master without effort. you have to play over and over again.
i wouldn't go as far as calling dorm vague....he is right and he has a big point.....i posted my test codes which work 100% which you can see at the link i've given twice but you changed parts of the coding and have got errors again.
i don't know exactly why you got the errors but its because the $_POST weren't being populated and that logically means its a form error....the same as you had before by not using the correct names in your php that you had on your form. i corrected this and gave you everything but you haven't followed it and changed it.
so to advise you go back to the form and double check the names. post a link to your test so we can see it please
I am not sure how to post a link to my test, and I did not change anything from your code. The only portion I changed was the thank you name of the php.
did you use the form i changed and did you import the sql file to your database?
Yes I did both of those things! The actual form that it needs to work off of is at http://mideasthonors.org/addmember.php so I cannot change that form! But the php coding is in the addMember.php page you instructed me to use. I also uploaded the table into SQL.
if thats the form that is being used and not the one i gave you then you need to change the names within the $_POST to correspond with the field names from the form i.e.
name
address_1
address_2
city
state
zip
website
contact_name
contact_position
contact_phone
contact_email
there is no need so change any variable names you just change what is in the postvar i.e.
$_POST['changeMe']
Do I also need to change everything in the sql as well?? 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.
hi all, I've got a problem with a script...
I need, through a vbscript, to move a 3parth win32 application to 0,0 (x,y) coordination of my desktop.
I know there is the "SetWindowPos" function in user32.dll API, maybe that what I need, but:
BOOL SetWindowPos(
HWND hWnd,
HWND hWndInsertAfter,
int X,
int Y,
int cx,
int cy,
UINT uFlags
);
I don't have the parameters to pass, I do not have the handle to that window and I don't know how to get the others...
I can call it by:
"run32.exe user32dll,SetWindowPos hwnd,hWndInsertAfter,x,y,cx,cy,wFlags"
I found my window by this trick but is not useful to me:
set wsh=wscript.createobject("wscript.shell")
do
w = wsh.appactivate ("Found New Hardware Wizard")
if w then 'FOUND IT
loop while t<10000
And...
after that I have to add a vertical and an horizontal scroll bar...
Too much for me...
Could you please help me?
Is that the right way to do it?
Any comment will be appreciate.
Thanks,
no....as the sql i made for you works with the variables that were set from each $_POST all that needs to be changed is the names within the $_POST vars as they still append to those variables set to use in the sql query
Sign in to post your reply or Sign up for a free account.
Similar topics
by: danaf |
last post by:
Dear all,
(1)Is it possible to host PHP-based Web Portal + MySQL Database (e.g.
PHPNuke) on MS Windows System? If yes which server software I...
|
by: jacob nikom |
last post by:
Hi,
I would like to store XML files in MySQL. What is the best solution:
1. Convert it to string and store it as CLOB/text
2. Serialize it and...
|
by: news |
last post by:
I need some concise, easy to grok examples of what .Net (preferably
C#.Net) has over just using old ASP or PHP with JavaScript.
See, I'm a PHP...
|
by: John Paul |
last post by:
I'm thinking of building an e-commerce site in php.
Anyone got any advice in building one?
What is the best way to implement a payment system?...
|
by: Paul |
last post by:
I have a process that I want to speed up. It first was written in
Microsoft Access then converted to VB.NET. I would like to hear some...
|
by: sunbeam |
last post by:
Short Description of the Project:
we developed a e-learning system for our students. each student has a unique username/password to view the...
|
by: Chuck36963 |
last post by:
Hi all,
I've been working on a listing problem and I can't figure out how to work it out. I have looked far and wide on the web to find answers,...
|
by: mike |
last post by:
I help manage a large web site, one that has over
600 html pages... It's a reference site for ham radio
folks and as an example, one page indexes...
|
by: hott5hotj |
last post by:
I am trying to create an authentication using flash and AS3 as the underlying code using PHP as the server side scripting and mySQL to store the...
|
by: better678 |
last post by:
Question:
Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct?
Answer:
Java is an object-oriented...
|
by: teenabhardwaj |
last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
|
by: CD Tom |
last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
| |