searls03 Posted April 12, 2011 Share Posted April 12, 2011 so I have this code: <?php //Search 'events' table for the username //I don't know where you're storing username, but I've assumed It's defined as $username $sql = mysql_query("SELECT * FROM Events WHERE eventid=".$_GET['eventid']." LIMIT 1"); while($row = mysql_fetch_array($sql)){ $title11 = $row['title1']; $title21 = $row['title2']; $title31 = $row['title3']; $title41 = $row['title4']; $title51 = $row['title5']; $title61 = $row['title6']; $title71 = $row['title7']; $title81 = $row['title8']; } ?> <?php $sql = mysql_query("SELECT * FROM Registration WHERE eventid=".$_GET['eventid']." LIMIT 1"); while($row = mysql_fetch_array($sql)){ $eventid = $row["eventid"]; $event = $row["event"]; $startdate = $row["startdate"]; $enddate = $row["enddate"]; $description = $row["description"]; $location = $row["location"]; $title1 = $row['title1']; $title2 = $row['title2']; $title3 = $row['title3']; $title4 = $row['title4']; $title5 = $row['title5']; $title6 = $row['title6']; $title7 = $row['title7']; $title8 = $row['title8']; $price1 = $row['price1']; $price2 = $row['price2']; $price3 = $row['price3']; $price4 = $row['price4']; $price5 = $row['price5']; $price6 = $row['price6']; $price7 = $row['price7']; $price8 = $row['price8']; $date1 = $row['date1']; $date2 = $row['date2']; $date3 = $row['date3']; $date4 = $row['date4']; $date5 = $row['date5']; $date6 = $row['date6']; $date7 = $row['date7']; $date8 = $row['date8']; //this will echo the contents of each db row as they are iterated in the loop ############################# echo "<form action ='eventreg.php' method='post'>"; echo "<center><table border='1' width='600'>"; // Example of testing title1 for the userid (already registered) ... if (!empty($title11)){ echo "<tr><td width='300'> <strong><font color='red'> You have already registered for this event</font></strong></td><td width='500'><strong>$title1 </strong><br /> $date1 <br />$ $price1 </tr></td> "; } else{ if (!empty($title1)) { echo "<tr><td width='300'> <input type='checkbox' name='title1' value='$title1'/></td><td width='500'><strong>$title1 </strong><br /> $date1 <br />$ $price1 </tr></td> "; } } if (!empty($title21)){ echo "<tr><td width='100'> <strong><font color='red'> You have already registered for this event</font></strong></td><td width='500'><strong>$title1 </strong><br /> $date1 <br />$ $price1 </tr></td> ";} else if (!empty($title2)) { echo "<br/><tr><td> <input type='checkbox' name='title2' value='$title2' /></td><td><strong>$title2 </strong><br /> $date2 <br />$ $price2 </tr></td>" ; } if (!empty($title31)){echo "<tr><td width='100'> <strong><font color='red'> You have already registered for this event</font></strong></td><td width='500'><strong>$title1 </strong><br /> $date1 <br />$ $price1 </tr></td> ";} else if (!empty($title3)) { echo "<br/><tr><td><input type='checkbox' name='title3' value='$title3' /></td><td><strong>$title3</strong> <br /> $date3 <br />$ $price3</tr></td>"; } if (!empty($title41)){ echo "<tr><td width='100'><strong><font color='red'> You have already registered for this event</font></strong></td><td width='500'><strong>$title1 </strong><br /> $date1 <br />$ $price1 </tr></td> ";} else if (!empty($title4)) { echo "<br/><tr><td><input type='checkbox' name='title4' value='$title4' /></td><td><strong>$title4</strong> <br /> $date4 <br />$ $price4</tr></td>"; } if (!empty($title51)){ echo "<tr><td width='100'> <strong><font color='red'> You have already registered for this event</font></strong></td><td width='500'><strong>$title1 </strong><br /> $date1 <br />$ $price1 </tr></td> ";} else if (!empty($title5)) { echo "<br/><tr><td><input type='checkbox' name='title5' value='$title5' /></td><td><strong>$title5</strong> <br /> $date5 <br />$ $price5</tr>"; } if (!empty($title61)){ echo "<tr><td width='100'> <strong><font color='red'> You have already registered for this event</font></strong></td><td width='500'><strong>$title1 </strong><br /> $date1 <br />$ $price1 </tr></td> ";} else if (!empty($title6)) { echo "<br/><tr><td> <input type='checkbox' name='title6' value='$title6' /></td><td><strong>$title6 </strong><br /> $date6 <br />$ $price6</tr></td>"; } if (!empty($title71)){echo "<tr><td width='100'> <strong><font color='red'> You have already registered for this event</font></strong></td><td width='500'><strong>$title1 </strong><br /> $date1 <br />$ $price1 </tr></td> ";} else if (!empty($title7)) { echo "<br/><tr><td> <input type='checkbox' name='title7' value='$title7' /></td><td><strong>$title7</strong> <br /> $date7 <br />$ $price7</tr></td>"; } if (!empty($title81)){ echo "<tr><td width='100'> <strong><font color='red'> You have already registered for this event</font></strong></td><td width='500'><strong>$title1 </strong><br /> $date1 <br />$ $price1 </tr></td> ";} else if (!empty($title8)) { echo "<br/><tr><td> <input type='checkbox' name='title8' value='$title8' /></td><td><strong>$title8</strong> <br /> $date8 <br />$ $price8</tr></td>"; } echo "</table>"; echo "<input name='userid' type=\"hidden\" value=\"$userid\" />"; echo "<input name='eventid' type=\"hidden\" value=\"$eventid\" />"; echo "<input name='email' type=\"text\" value=\"$email\" />"; echo "<input name='event' type=\"hidden\" value=\"$event\" />"; echo "<input name='name' type=\"hidden\" value=\"$name\" />"; echo "<input name=\"save\" type=\"submit\" value=\"Register Now!\" />"; echo "<input name='price1' type=\"hidden\" value=\"$price1\" />"; echo "<input name='price2' type=\"hidden\" value=\"$price2\" />"; echo "<input name='price3' type=\"hidden\" value=\"$price3\" />"; echo "<input name='price4' type=\"hidden\" value=\"$price4\" />"; echo "<input name='price5' type=\"hidden\" value=\"$price5\" />"; echo "<input name='price6' type=\"hidden\" value=\"$price6\" />"; echo "<input name='price7' type=\"hidden\" value=\"$price7\" />"; echo "<input name='price8' type=\"hidden\" value=\"$price8\" />"; echo "</center></form>"; } //etc etc //If it finds a match, output an error message ?> I need to know how I can make $price1-8 only show up if the corresponding $title is checked when this happens..........It will add all the prices up to tell a total price. here is the code that has that in it: <?php session_start(); // Must start session first thing /* Created By Adam Khoury @ www.flashbuilding.com -----------------------June 20, 2008----------------------- */ // Here we run a login check if (!isset($_SESSION['id'])) { echo 'Please <a href="login.php">log in</a> to access your account'; exit(); } //Connect to the database through our include include_once "connect_to_mysql.php"; // Place Session variable 'id' into local variable $userid = $_SESSION['id']; // Query member data from the database and ready it // Process the form if it is submitted // Set error message as blank upon arrival to page $errorMsg = ""; // First we check to see if the form has been submitted if (isset($_POST['eventid'])){ $name = ereg_replace("[^A-Z a-z0-9]", "", $_POST['name']); // filter everything but numbers and letters $event = ereg_replace("[^A-Z a-z0-9]", "", $_POST['event']); // filter everything but spaces, numbers, and letters $eventid = ereg_replace("[^A-Z a-z0-9]", "", $_POST['eventid']); // filter everything but spaces, numbers, and letters $subevent1 = ereg_replace("[^A-Z a-z0-9]", "", $_POST['subevent1']); // filter everything but spaces, numbers, and letters $subevent2 = ereg_replace("[^A-Za-z0-9]", "", $_POST['subevent2']); // filter everything but lowercase letters $subevent3 = ereg_replace("[^A-Za-z0-9]", "", $_POST['subevent3']); // filter everything but lowercase letters $subevent4 = ereg_replace("[^A-Za-z0-9]", "", $_POST['subevent4']); // filter everything but lowercase letters $subevent5 = ereg_replace("[^A-Za-z0-9]", "", $_POST['subevent5']); // filter everything but lowercase letters $subevent6 = ereg_replace("[^A-Z a-z0-9]", "", $_POST['subevent6']); // filter everything but $subevent7 = ereg_replace("[^A-Z a-z0-9]", "", $_POST['subevent7']); // filter everything but $subevent8 = ereg_replace("[^A-Z a-z0-9]", "", $_POST['subevent8']); // filter everything but $title1 = ereg_replace("[^A-Z a-z0-9]", "", $_POST['title1']); // filter everything but spaces, numbers, and letters $title2 = ereg_replace("[^A-Za-z0-9]", "", $_POST['title2']); // filter everything but lowercase letters $title3 = ereg_replace("[^A-Za-z0-9]", "", $_POST['title3']); // filter everything but lowercase letters $title4 = ereg_replace("[^A-Za-z0-9]", "", $_POST['title4']); // filter everything but lowercase letters $title5 = ereg_replace("[^A-Za-z0-9]", "", $_POST['title5']); // filter everything but lowercase letters $title6 = ereg_replace("[^A-Z a-z0-9]", "", $_POST['title6']); // filter everything but $title7 = ereg_replace("[^A-Z a-z0-9]", "", $_POST['title7']); // filter everything but $title8 = ereg_replace("[^A-Z a-z0-9]", "", $_POST['title8']); // filter everything but $userid = ereg_replace("[^A-Z a-z0-9]", "", $_POST['userid']); // filter everything but $email = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['email']); // filter everything but $price1 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price1']); // filter everything but $price2 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price2']); // filter everything but $price3 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price3']); // filter everything but $price4 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price4']); // filter everything but $price5 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price5']); // filter everything but $price6 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price6']); // filter everything but $price7 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price7']); // filter everything but $price8 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price8']); // filter everything but $sql = "REPLACE INTO Events (name, event, eventid, userid, title1, title2, title3, title4, title5, title6, title7, title8, email) VALUES('$name','$event','$eventid','$userid','$title1','$title2','$title3','$title4','$title5','$title6','$title7','$title8', '$email')"; $rs = mysql_query($sql) or die ("Problem with the query: $sql<br>" . mysql_error()); $total = $price1 + $price2 + $price3 + $price4 + $price5 + $price6 + $price7 + $price8; $to = "$email"; // Change this to your site admin email $from = "events@final.net46.net"; $subject = "Thank You for Registering for $event. "; //Begin HTML Email Message where you need to change the activation URL inside $message = "<html> <head> <style type='text/css'> #apDiv1 { position:absolute; left:338px; top:278px; width:311px; height:129px; z-index:1; } #pic { position:relative; left:0px; top:0px; } #apDiv2 { position:absolute; left:50px; top:207px; width:181px; height:149px; z-index:2; } #apDiv2 { text-align: center; } </style> </head> <body><div id='apDiv1'> <table width='408' border='1' cellspacing='2' cellpadding='2'> <tr> <th width='90' scope='col'>Event(s):</th> <th width='298' scope='col'>"; $sql = ("SELECT * FROM Events WHERE eventid='$eventid'"); $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_array($result)){ $event = $row['event']; $startdate = $row['startdate']; $enddate = $row['enddate']; $description = $row['description']; $location = $row['location']; $subevent1 = $row['subevent1']; $subevent2 = $row['subevent2']; $subevent3 = $row['subevent3']; $subevent4 = $row['subevent4']; $subevent5 = $row['subevent5']; $subevent6 = $row['subevent6']; $subevent7 = $row['subevent7']; $subevent8 = $row['subevent8']; } if (!empty($title1)) { $message .= "<br/>$title1"; } if (!empty($title2)) { $message .= "<hr><br/>$title2" ; } if (!empty($title3)) { $message .= "<hr><br/>$title3"; } if (!empty($title4)) { $message .= "<hr><br/>$title4"; } if (!empty($title5)) { $message .= "<hr><br/>$title5"; } if (!empty($title6)) { $message .= "<hr> <br/>$title6"; } if (!empty($title7)) { $message .= "<hr><br/>$title7"; } if (!empty($title8)) { $message .= "<hr><br/>$title8"; } echo "</div>"; ?> <?php $message .=" </th> </tr> <tr> <th>Price:</th> <th> $ $total </th> </tr>"; ?> <?php $message .=" <tr> <th>Registrant:</th> <th> $name </th> </tr> </table>"; ?> <?php $message .=" <div id='pic'> <img src=\"http://final.net46.net/button/boyscout.jpg\"> <div id='apDiv2'>$name <p> </p> <p> </p> <p><a href='final.net46.net' target='_new'><strong>Troop 78 Home</strong></a></p> <p> </p> <p> </p> <p><strong><a href='http://www.cornhuskercouncil.org'>Cornhusker Council</a></strong></p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> </div> </div> </body> </html>"; ?> <?php // end of message $headers = "From: $from\r\n"; $headers .= "Content-Type: text/html\r\n"; $to = "$to"; // Finally send the activation email to the member mail($to, $subject, $message, $headers); // Then print a message to the browser for the joiner echo "<br /><br /><br /><h4>OK $firstname, one last step to verify your email identity:</h4><br /> We just sent an Activation link to: $email<br /><br /> <strong><font color=\"#990000\">Please check your email inbox in a moment</font></strong> to click on the Activation <br /> Link inside the message. After email activation you can log in."; $to = "searls03@gmail.com"; // Change this to your site admin email $from = "events@final.net46.net"; $subject = "New Registration for $event"; //Begin HTML Email Message where you need to change the activation URL inside $mailimg = ' <img src="http://final.net46.net/button/boyscout.jpg"</a> '; $message = "<html> <style type='text/css'> #apDiv1 { position:absolute; left:338px; top:278px; width:311px; height:129px; z-index:1; } #apDiv2 { position:absolute; left:50px; top:207px; width:181px; height:149px; z-index:2; } #apDiv2 { text-align: center; } body { background-image: url(final.net46.net/button/boyscout.jpg); background-repeat: no-repeat; } </style> </head> <body><div id='apDiv1'> <table width='408' border='1' cellspacing='2' cellpadding='2'> <tr> <th width='90' scope='col'>Event(s):</th> <th width='298' scope='col'>"; $sql = ("SELECT * FROM Events WHERE eventid='$eventid'"); $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_array($result)){ $event = $row['event']; $startdate = $row['startdate']; $enddate = $row['enddate']; $description = $row['description']; $location = $row['location']; $subevent1 = $row['subevent1']; $subevent2 = $row['subevent2']; $subevent3 = $row['subevent3']; $subevent4 = $row['subevent4']; $subevent5 = $row['subevent5']; $subevent6 = $row['subevent6']; $subevent7 = $row['subevent7']; $subevent8 = $row['subevent8']; } if (!empty($title1)) { $message .= "<br/>$title1"; } if (!empty($title2)) { $message .= "<hr><br/>$title2" ; } if (!empty($title3)) { $message .= "<hr><br/>$title3"; } if (!empty($title4)) { $message .= "<hr><br/>$title4"; } if (!empty($title5)) { $message .= "<hr><br/>$title5"; } if (!empty($title6)) { $message .= "<hr> <br/>$title6"; } if (!empty($title7)) { $message .= "<hr><br/>$title7"; } if (!empty($title8)) { $message .= "<hr><br/>$title8"; } ?> <?php $message .=" </th> </tr> <tr> <th>Price:</th> <th> $ $total </th> </tr>"; ?> <?php $message .=" <tr> <th>Registrant:</th> <th> $name </th> </tr> </table>"; ?> <?php $message .=" </div> <div id='apDiv2'>$name <p> </p> <p> </p> <p><a href='final.net46.net' target='_new'><strong>Troop 78 Home</strong></a></p> <p> </p> <p> </p> <p><strong><a href='http://www.cornhuskercouncil.org'>Cornhusker Council</a></strong></p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> </div> </body> </html>"; // end of message $headers = "From: $from\r\n"; $headers .= "Content-Type: text/html\r\n"; $to = "$to"; $message .= $mailimg . $message; // Finally send the activation email to the member mail($to, $subject, $message, $headers); // Then print a message to the browser for the joiner echo mysql_error(); // close if post exit(); // Exit so the form and page does not display, just this success message }// Close else after database duplicate field value checks // Close else after missing vars check //Close if $_POST ?> Does this make sense? as of right now, if there is a price present in database, they all will be added together, not just checked ones..........help!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/233535-associations/ Share on other sites More sharing options...
searls03 Posted April 13, 2011 Author Share Posted April 13, 2011 did that make sense? Quote Link to comment https://forums.phpfreaks.com/topic/233535-associations/#findComment-1200910 Share on other sites More sharing options...
KevinM1 Posted April 13, 2011 Share Posted April 13, 2011 You have a ton of code posted... can you simply show the relevant parts? Also, you don't need to use a while-loop if you're only retrieving one row from the db. Quote Link to comment https://forums.phpfreaks.com/topic/233535-associations/#findComment-1200917 Share on other sites More sharing options...
searls03 Posted April 13, 2011 Author Share Posted April 13, 2011 so I have this code: <?php if (!empty($title11)){ echo "<tr><td width='300'> <strong><font color='red'> You have already registered for this event</font></strong></td><td width='500'><strong>$title1 </strong><br /> $date1 <br />$ $price1 </tr></td> "; } else{ if (!empty($title1)) { echo "<tr><td width='300'> <input type='checkbox' name='title1' value='$title1'/></td><td width='500'><strong>$title1 </strong><br /> $date1 <br />$ $price1 </tr></td> "; } } if (!empty($title21)){ echo "<tr><td width='100'> <strong><font color='red'> You have already registered for this event</font></strong></td><td width='500'><strong>$title1 </strong><br /> $date1 <br />$ $price1 </tr></td> ";} else if (!empty($title2)) { echo "<br/><tr><td> <input type='checkbox' name='title2' value='$title2' /></td><td><strong>$title2 </strong><br /> $date2 <br />$ $price2 </tr></td>" ; } if (!empty($title31)){echo "<tr><td width='100'> <strong><font color='red'> You have already registered for this event</font></strong></td><td width='500'><strong>$title1 </strong><br /> $date1 <br />$ $price1 </tr></td> ";} else if (!empty($title3)) { echo "<br/><tr><td><input type='checkbox' name='title3' value='$title3' /></td><td><strong>$title3</strong> <br /> $date3 <br />$ $price3</tr></td>"; } if (!empty($title41)){ echo "<tr><td width='100'><strong><font color='red'> You have already registered for this event</font></strong></td><td width='500'><strong>$title1 </strong><br /> $date1 <br />$ $price1 </tr></td> ";} else if (!empty($title4)) { echo "<br/><tr><td><input type='checkbox' name='title4' value='$title4' /></td><td><strong>$title4</strong> <br /> $date4 <br />$ $price4</tr></td>"; } if (!empty($title51)){ echo "<tr><td width='100'> <strong><font color='red'> You have already registered for this event</font></strong></td><td width='500'><strong>$title1 </strong><br /> $date1 <br />$ $price1 </tr></td> ";} else if (!empty($title5)) { echo "<br/><tr><td><input type='checkbox' name='title5' value='$title5' /></td><td><strong>$title5</strong> <br /> $date5 <br />$ $price5</tr>"; } if (!empty($title61)){ echo "<tr><td width='100'> <strong><font color='red'> You have already registered for this event</font></strong></td><td width='500'><strong>$title1 </strong><br /> $date1 <br />$ $price1 </tr></td> ";} else if (!empty($title6)) { echo "<br/><tr><td> <input type='checkbox' name='title6' value='$title6' /></td><td><strong>$title6 </strong><br /> $date6 <br />$ $price6</tr></td>"; } if (!empty($title71)){echo "<tr><td width='100'> <strong><font color='red'> You have already registered for this event</font></strong></td><td width='500'><strong>$title1 </strong><br /> $date1 <br />$ $price1 </tr></td> ";} else if (!empty($title7)) { echo "<br/><tr><td> <input type='checkbox' name='title7' value='$title7' /></td><td><strong>$title7</strong> <br /> $date7 <br />$ $price7</tr></td>"; } if (!empty($title81)){ echo "<tr><td width='100'> <strong><font color='red'> You have already registered for this event</font></strong></td><td width='500'><strong>$title1 </strong><br /> $date1 <br />$ $price1 </tr></td> ";} else if (!empty($title8)) { echo "<br/><tr><td> <input type='checkbox' name='title8' value='$title8' /></td><td><strong>$title8</strong> <br /> $date8 <br />$ $price8</tr></td>"; } echo "</table>"; echo "<input name='userid' type=\"hidden\" value=\"$userid\" />"; echo "<input name='eventid' type=\"hidden\" value=\"$eventid\" />"; echo "<input name='email' type=\"text\" value=\"$email\" />"; echo "<input name='event' type=\"hidden\" value=\"$event\" />"; echo "<input name='name' type=\"hidden\" value=\"$name\" />"; echo "<input name=\"save\" type=\"submit\" value=\"Register Now!\" />"; echo "<input name='price1' type=\"hidden\" value=\"$price1\" />"; echo "<input name='price2' type=\"hidden\" value=\"$price2\" />"; echo "<input name='price3' type=\"hidden\" value=\"$price3\" />"; echo "<input name='price4' type=\"hidden\" value=\"$price4\" />"; echo "<input name='price5' type=\"hidden\" value=\"$price5\" />"; echo "<input name='price6' type=\"hidden\" value=\"$price6\" />"; echo "<input name='price7' type=\"hidden\" value=\"$price7\" />"; echo "<input name='price8' type=\"hidden\" value=\"$price8\" />"; echo "</center></form>"; } //etc etc //If it finds a match, output an error message ?> I need to know how I can make $price1-8 only show up if the corresponding $title is checked when this happens..........It will add all the prices up to tell a total price. here is the code that has that in it: <?php $price1 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price1']); // filter everything but $price2 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price2']); // filter everything but $price3 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price3']); // filter everything but $price4 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price4']); // filter everything but $price5 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price5']); // filter everything but $price6 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price6']); // filter everything but $price7 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price7']); // filter everything but $price8 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price8']); // filter everything but $total = $price1 + $price2 + $price3 + $price4 + $price5 + $price6 + $price7 + $price8; ?> Does this make sense? as of right now, if there is a price present in database, they all will be added together, not just checked ones..........help!!!!! OK I am pretty sure that is the relevant code........ Quote Link to comment https://forums.phpfreaks.com/topic/233535-associations/#findComment-1200918 Share on other sites More sharing options...
searls03 Posted April 13, 2011 Author Share Posted April 13, 2011 any help? Quote Link to comment https://forums.phpfreaks.com/topic/233535-associations/#findComment-1201270 Share on other sites More sharing options...
searls03 Posted April 15, 2011 Author Share Posted April 15, 2011 so basically like an if is checked type of statement? Quote Link to comment https://forums.phpfreaks.com/topic/233535-associations/#findComment-1202202 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.