PHP - Small Peice Of Php Code With Big Problems
I was wondering if someone can tell me what I have done wrong with this code:
<?php foreach ($row['received'] as $data) { $data += $received; } echo $received; ?> It should be adding the number 2 three times, so it should be echoing 6 but its not. Problem 1 I have is that nothing is being added to the variable $received, and problem 2 is that I suspect $received will not become 6, but rather 222. Am I correct? Similar TutorialsCode: Code: [Select] <table border='0' style="height:100%;width:570px;border:solid 1px #BBB"> Error: Code: [Select] Parse error: parse error, expecting `','' or `';'' in C:\xampp\htdocs\sources\admin\manage-user.php on line 26 Sorry, im a noob when it comes to coding. please help! My Error Output is this: Warning: Cannot modify header information - headers already sent by (output started at city-search.php:1) in city-search.php on line 65 What I'm I missing in the code, I can't seem to get these. It works excellent in Localhost, but in production. Error above. Code: [Select] <?php // MG CREATED THIS SIMPLE REGISTRATION PHP FOR THAT GOES TO ONE SPECIFIC USER. // WILL TEST FORM REGSITRATION NG 07-2011 //If the form is submitted if(isset($_POST['submit'])) { //Check to make sure that the name field is not empty if(trim($_POST['name']) == '') { $hasError = true; } else { $name = trim($_POST['name']); } //Check to make sure that the subject field is not empty if(trim($_POST['subject']) == '') { $hasError = true; } else { $subject = trim($_POST['subject']); } //Check to make sure sure that a valid email address is submitted if(trim($_POST['email']) == '') { $hasError = true; } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) { $hasError = true; } else { $email = trim($_POST['email']); } //Check to make sure comments were entered if(trim($_POST['message']) == '') { //$hasError = true; $comments == 'Have No Friends'; } else { if(function_exists('stripslashes')) { $comments = stripslashes(trim($_POST['message'])); } else { $comments = trim($_POST['message']); } } //If there is no error, send the email if(!isset($hasError)) { //$emailTo = 'regina@shushmedeals.com'; //$emailTo = 'reginabyrd32@yahoo.com'; $emailTo = 'mp3@danjaproduction.com'; //$emailBcc = 'ganja99@netzero.net'; //$emailBcc = 'info@danjaproduction.com'; //$emailBcc = 'ganja99@netzero.net'; //Put your own email address here $body = "Location: $name \n\nEmail: $email \n\nShushMeDeals Sign-up Info:\n $comments"; // To send HTML mail, the Content-type header must be set $headers = 'From: ShushMeDeals.com City Location sign-up - '.$name.'' . "\r\n" . 'Reply-To: ' . $email . "\r\n" .'Bcc: print@extremeatlanta.com'; //$headers .= 'Cc: birthdayarchive@example.com' . "\r\n"; //$headers .= 'Bcc: info@danjaproduction.com' . "\r\n"; mail($emailTo, $subject, $body, $headers); $emailSent = true; if($emailSent = true) { setcookie("location", $name); //echo '<script type="text/javascript"> // window.location = "index.php?option=com_enmasse&controller=deal&task=today&locationName='.$name.'" // </script>'; } } } ?> I have a problem with the below code: Code: [Select] <?php $sql_ranks = ("SELECT vtp_members.id, vtp_members.name, vtp_members.teamleader, teams.team_name, count(vtp_tracking.id) surfs FROM vtp_members, vtp_tracking, teams WHERE vtp_members.team_id=".$_GET['t']." AND vtp_tracking.credit_members_id=vtp_members.id AND vtp_tracking.action_date > '$last_sunday' AND vtp_tracking.action_date < '$next_sunday' GROUP BY teams.team_name ORDER BY surfs DESC"); $rsranks = mysql_query($sql_ranks); echo "<br><table align='center' valign='top' border='0' width='300px'> <tr><td colspan='2' align='center'><font size='2px'><b>Team Rankings (Current Week)</b></font></td></tr> <tr><td><font size='2px'><b>Team</font></td><td align='right'><font size='2px'>Total Surfs</font></td></tr>"; while ($row = mysql_fetch_array($rsranks)) { echo "<tr><td><font size='2px'><b>".$row[team_name]."</font></td><td align='right'><font size='2px'>".$row[surfs]."</font></td></tr>";} echo "</table>"; ?> Problem is that the last output (".$row[surfs].") is the same for all teams. It seems it is not making a total of all id's and not per team_name. anyone can see what I am doing wrong. I need to sort by team_name and the surfs should display the total of the members with team_id is ".$_GET['t']." Okay, I have no idea how this works out but this is really getting on my nerves. Here is my logic for the following code. I manually register a user, It goes into the database and dispatches an email notification explaining that a user must activate their account and change their user name (OPTIONAL) and password. In the email, There is an automatically generated password with the username, And a link to activate the account. This leads to stage 1 of the activation process, In this stage the user is accepted, Registered as a verified user and then is sent to another page to change the details like login and password. As far as I know this page works except through trial and error I found that this little snippet of code is causing browsers to show an error 500 page, If I remove this the page works: <?php if($messages){ displayErrors($messages); } else { echo("<p align=\"center\" class=\"standard\">Your account has been activated.</p><p align=\"center\" class=\"standard\">You now need to change your password. If you like you can also change your username, Remember that you only have 3 days to do so and this change will be permanent.</p>"); } ?> and this is the displayErrors function: <?php function displayErrors($messages) { print("<p align=\"center\" class=\"standard\">"."<b>There were problems with the previous action:</b>\n<ul>\n"); foreach($messages as $msg){ print("<li>$msg</li>\n"); } print("</ul>\n"."</p>"); } ?> The displayErrors function is in a file called functions.php, Which is included in config.php, Which is included in every page including this one. The entire "Change password and login page thingie" is he <?php include("config.php"); global $link, $messages; require_once('recaptchalib.php'); if($_GET['error']){ $id=$_GET['id']; $messages[]="There is more than one or no accounts with the verification code you are using. <a href=\"mailto:rentals@nivso.co.uk?subject=Two or no accounts with activation ID of $id\">Click here to email us about this and have the problem sorted.</a>"; doIndex(); exit; } if(isset($_POST['submit'])){ if(!isset($_POST['activationid'])){ die("Doesn't exist -.- might as well quit this is *STUFF* -.-"); } $privatekey = "YOUR NOT HAVING THIS"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { $messages[]="The code you entered is incorrect. Please go back and try again!"; doIndex(); exit; // exit or the below lines will be processed. } else { //This is where the fun starts! $login=$_POST['login']; $passw=$_POST['password']; $passc=$_POST['passwordc']; $id2=$_POST['activationid']; $changinglogin=false; $get1=excDB("SELECT * FROM `users` WHERE `activeID`='$id2'"); if($get1[0]){ $get1=$get1[1]; } else { die($get1[2]); } $pro1=mysql_fetch_array($get1); if($pro1['login']!=$login){ $changinglogin=true; field_validator("Login", $login, "alphanumeric", 4, 15); } field_validator("Password", $passw, "string", 6, 20); if($passw!=$passc){ $messages[]="The passwords do not match, Please make sure that the passwords are the same!"; } if($messages){ doIndex(); exit; } $passcl=mysql_escape_string($passw); $passen=md5($passcl); if($changinglogin){ $wri1=excDB("UPDATE `users` SET `login`='$login', `password`='$passen', `passchange`='1', `loginchange`='1' WHERE `activeID`='$id2';"); if($wri1[0]){ $wri1=$wri1[1]; } else { die($wri1[2]); } header("Location: login.php?created"); } else { $wri1=excDB("UPDATE `users` SET `password`='$passen', `passchange`='1', `loginchange`='0' WHERE `activeID`='$id2';"); if($wri1[0]){ $wri1=$wri1[1]; } else { die($wri1[2]); } header("Location: login.php?created2"); } } } else { doIndex(); } function doIndex(){ ?> <!DOCTYPE html> <head> <title>Family Rental System! - Rent your DVDs here - Design by Alex, Coding by Gergy008</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link type="text/css" href="css/main.css" rel="stylesheet"> <style type="text/css"> <!-- body { background-color: #333333; } --> </style></head> <body style="text-align:center;"> <div class="first"> <div class="backgrounder1"></div> <div class="headerbar1"></div> <div class="headerbar2"></div> </div> <div align="center"> <table border="0" cellpadding="0" cellspacing="0" width="900"> <tr> <td><img src="images/spacer.gif" width="52" height="1" border="0" alt="" /></td> <td><img src="images/spacer.gif" width="123" height="1" border="0" alt="" /></td> <td><img src="images/spacer.gif" width="352" height="1" border="0" alt="" /></td> <td><img src="images/spacer.gif" width="33" height="1" border="0" alt="" /></td> <td><img src="images/spacer.gif" width="55" height="1" border="0" alt="" /></td> <td><img src="images/spacer.gif" width="110" height="1" border="0" alt="" /></td> <td><img src="images/spacer.gif" width="110" height="1" border="0" alt="" /></td> <td><img src="images/spacer.gif" width="50" height="1" border="0" alt="" /></td> <td><img src="images/spacer.gif" width="15" height="1" border="0" alt="" /></td> <td><img src="images/spacer.gif" width="1" height="1" border="0" alt="" /></td> </tr> <tr> <td colspan="9" background="images/template.slice.1.png"> </td> <td><img src="images/spacer.gif" width="1" height="20" border="0" alt="" /></td> </tr> <tr> <td colspan="5" background="images/template.slice.2.png"> </td> <td colspan="2" rowspan="2" background="images/template.slice.3.png"><span class="login"><?php echo(loginHandler()); ?></span></td> <td colspan="2" rowspan="3" background="images/template.slice.4.png"> </td> <td><img src="images/spacer.gif" width="1" height="30" border="0" alt="" /></td> </tr> <tr> <td rowspan="8" background="images/template.slice.5.png"> </td> <td colspan="2" background="images/template.slice.6.png"><form> <div align="center"> <input name="textfield" type="text" id="textfield" size="40" style="height:16px;"> <input type="submit" name="button" id="button" value="Search" style="height:20px;"> </div> </form></td> <td colspan="2" rowspan="2" background="images/template.slice.7.png"> </td> <td><img src="images/spacer.gif" width="1" height="30" border="0" alt="" /></td> </tr> <tr> <td colspan="2" rowspan="3" background="images/template.slice.8.png"><p> </p> <p> </p></td> <td colspan="2" background="images/template.slice.9.png"> </td> <td><img src="images/spacer.gif" width="1" height="70" border="0" alt="" /></td> </tr> <tr> <td rowspan="2" background="images/template.slice.10.png"> </td> <td colspan="4" background="images/template.slice.11.png"> </td> <td rowspan="6" background="images/template.slice.12.png"> </td> <td><img src="images/spacer.gif" width="1" height="30" border="0" alt="" /></td> </tr> <tr> <td colspan="4" background="images/template.slice.13.png"></td> <td><img src="images/spacer.gif" width="1" height="8" border="0" alt="" /></td> </tr> <tr> <td rowspan="4" background="images/template.slice.14.png"> </td> <td colspan="4" background="images/template.slice.15.png"> </td> <td colspan="2" rowspan="4" background="images/template.slice.16.png"> </td> <td><img src="images/spacer.gif" width="1" height="35" border="0" alt="" /></td> </tr> <tr> <td colspan="4" background="images/template.slice.17.png"> </td> <td><img src="images/spacer.gif" width="1" height="37" border="0" alt="" /></td> </tr> <tr> <td colspan="4" align="center" valign="top" background="images/template.slice.18.png" style="vertical-align:top;"><p class="standard"> </p> <table width="80%" border="0"> <tr> <td colspan="2"> <?php if($messages){ //displayErrors($messages); } else { //echo("<p align=\"center\" class=\"standard\">Your account has been activated.</p><p align=\"center\" class=\"standard\">You now need to change your password. If you like you can also change your username, Remember that you only have 3 days to do so and this change will be permanent.</p>"); ?></td> </tr> <form name="ChangeDetails" method="post" action="<?=$_SERVER['PHP_SELF']?>"> <input type="hidden" name="activationid" value="<?php if($_GET['id']){ $id=$_GET['id']; echo($id); } elseif($_POST['activationid']){ $id=$_POST['activationid']; echo($id); } else { die("No ID") } ?>" /> <tr> <td width="50%"><div align="right" class="standard">New Username: </div></td> <td width="50%"><input name="login" type="text" id="login" size="35" maxlength="30" /></td> </tr> <tr> <td><div align="right" class="standard">New Password:</div></td> <td><input name="password" type="password" id="password" size="35" maxlength="30" /></td> </tr> <tr> <td><div align="right" class="standard">Re-enter password:</div></td> <td><input name="passwordc" type="password" id="passwordc" size="35" maxlength="30" /></td> </tr> <tr> <td><div align="right" class="standard">Please enter the code: </div></td> <td> <?php require_once('recaptchalib.php'); $publickey = "6Le4fsESAAAAAKMOHb8aaiyDfGRJyr0y0EU7dXm-"; // you got this from the signup page echo recaptcha_get_html($publickey); ?> </td> </tr> <tr> <td> </td> <td><input type="submit" name="submit" id="submit" value="Change your details" /></td> </tr> </form> </table> </td> <td><img src="images/spacer.gif" width="1" height="450" border="0" alt="" /></td> </tr> <tr> <td colspan="4" background="images/template.slice.19.png"> </td> <td><img src="images/spacer.gif" width="1" height="50" border="0" alt="" /></td> </tr> <tr> <td colspan="9" background="images/template.slice.20.png"> </td> <td><img src="images/spacer.gif" width="1" height="40" border="0" alt="" /></td> </tr> </table> </div> </body> </html> <?php } ?> Thanks to all you kind people that take your time to read and help me with this problem. I'm sorry if it is a really simple problem I missed out that makes me look like a right idiot and wasted your time, but that's me I'm always missing stuff out like that, I do proof read though just sometimes not good enough. Thanks in advance! Since I didn't want to type it out myself I wrote a small Date of Birth drop down menu generator. Now I'm wondering how I can make the code copy-able in a text area? The script should be inserting all the code ready and finished into a textarea so you can copy and go. How is it done? Here's the script: <?php echo "<center>"; ?> <form action='' method='POST'> <input type='submit' name='submit' /> </form> <?php $submit = $_POST['submit']; if ($submit) { echo "<form action='' method='POST'>"; echo "<select name='month'>"; for ($m = 01; $m <= 12; $m++) { echo " <option value='" . $m . "'>" . $m . "</option> "; } echo "</select>"; echo "<select name='day'>"; for ($d = 01; $d <= 31; $d++) { echo " <option value='" . $d . "'>" . $d . "</option> "; } echo "</select>"; echo "<select name='year'>"; for ($y = 1900; $y <= 2010; $y++) { echo " <option value='" . $y . "'>" . $y . "</option> "; } echo "</select>"; echo "</form>"; echo "</center>"; } ?> class curl2{ private $curl_init; private $CURLOPT_URL; public function connect(){ $this->curl_init = curl_init(); } public function debug(){ curl_setopt($this->curl_init, CURLOPT_VERBOSE, TRUE); $fp = fopen("curl2.txt", "w"); curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE); } public function setUrl($url = null){ $this->CURLOPT_URL = $url; curl_setopt($this->curl_init, CURLOPT_URL, $this->CURLOPT_URL); } public function execute(){ $out = curl_exec($this->curl_init); curl_close($this->curl_init); return $out; } } $curl2 = new curl2; $curl2->connect(); $curl2->setUrl("http://www.linuxformat.co.uk"); $curl2->debug(); echo $curl2->execute(); It display a blank page like attachment result1.jpg, but if I move the $fp = fopen("curl2.txt", "w"); curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE); from function debug() and join it with function execute() like this: public function execute(){ $fp = fopen("curl2.txt", "w"); curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE); $out = curl_exec($this->curl_init); curl_close($this->curl_init); return $out; } it return me Linuxformat content ( expected result ) like result2.jpg below is the working code : class curl2{ private $curl_init; private $CURLOPT_URL; public function connect(){ $this->curl_init = curl_init(); } public function debug(){ curl_setopt($this->curl_init, CURLOPT_VERBOSE, TRUE); } public function setUrl($url = null){ $this->CURLOPT_URL = $url; curl_setopt($this->curl_init, CURLOPT_URL, $this->CURLOPT_URL); } public function execute(){ $fp = fopen("curl2.txt", "w"); curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE); $out = curl_exec($this->curl_init); curl_close($this->curl_init); return $out; } } $curl2 = new curl2; $curl2->connect(); $curl2->setUrl("http://www.linuxformat.co.uk"); $curl2->debug(); echo $curl2->execute(); Why I couldn't split "CURLOPT_STDERR, CURLOPT_RETURNTRANSFER" with "curl_exec" can someone please tell me what is wrong with this code? <?php function documentType(){ echo <<<HEREDOC <?xml version="1.0" encoding="UTF-8"?> <!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> } HEREDOC; ?> Hey, I got this script off phpfreaks in the post "Basic Pagination Code", and got it to work except I'm experiencing this really tiny problem. The script displays only the first row in my table, and displays 127 times, which is how many rows I have total in the table. This is where I have this script running at. You can go there to see what I'm talking about: http://www.djsmiley.net/guestbook.php This is the code I got and tweaked: Code: [Select] <?php //your username $username = "your username"; //your password $password = "your password"; //your mySQL server $host = "your hostname"; //The name of the database your table is in $database = "your database"; //connect, but if there is a problem, display an error message telling why there is a problem $conn = mysql_connect($host,$username,$password) or die("Error connecting to Database!<br>" . mysql_error()); //Choose the database from your mySQL server, but if there is a problem, display an error telling why $db = mysql_select_db($database) or die("Cannot select database!<br>" . mysql_error()); // find out how many rows are in the table $sql = "SELECT COUNT(*) FROM comments"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 10; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; // get the info from the db $sql = "SELECT * FROM comments ORDER BY commentid DESC LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { // echo data if ($name == 'DJ Smiley' && $adminkey == 'adminkey') { echo(" <div style=\"border-radius: 10px; border: solid 2px #E5E5E5; padding: 10px; width: 95%; background: #F6F6F6;\"> <p> <a name=\"$commentid\" id=\"$commentid\"></a><img src=\"http://www.djsmiley.net/images/Icons/Arrows/Right 2.png\" class=\"fltlft2\" height=\"25\" width=\"25\"><strong>$name</strong> (<a href=\"http://whois.domaintools.com/$ip\"><font size=1>$ip</font></a>) says: <br><p class=\"BottomBorder\"></p> <table><tr><td><img src=\"http://www.djsmiley.net/images/Self/Self (2).jpg\" height=\"50\" width=\"50\"></td><td>$comment</td></tr></table> <br><p class=\"BottomBorder\"></p> added on $time<p><em>$email</em></p> </p> </div><br> "); } elseif ($name == false) { echo(" <div style=\"border-radius: 10px; border: solid 2px #E5E5E5; padding: 10px; width: 95%; background: #F6F6F6;\"> <p> <a name=\"$commentid\" id=\"$commentid\"></a><img src=\"http://www.djsmiley.net/images/Icons/Arrows/Right 2.png\" class=\"fltlft2\" height=\"25\" width=\"25\"><strong>Anonymous</strong> (<a href=\"http://whois.domaintools.com/$ip\"><font size=1>$ip</font></a>) says: <br><p class=\"BottomBorder\"></p> <table><tr><td><img src=\"http://www.djsmiley.net/images/Icons/People/Anonymous 2.png\" height=\"50\" width=\"50\"></td><td>$comment</td></tr></table> <br><p class=\"BottomBorder\"></p>added on $time<p><em>$email</em></p> </p> </div><br> "); } else { echo(" <div style=\"border-radius: 10px; border: solid 2px #E5E5E5; padding: 10px; width: 95%; background: #F6F6F6;\"> <p> <a name=\"$commentid\" id=\"$commentid\"></a><img src=\"http://www.djsmiley.net/images/Icons/Arrows/Right 2.png\" class=\"fltlft2\" height=\"25\" width=\"25\"><strong>$name</strong> (<a href=\"http://whois.domaintools.com/$ip\"><font size=1>$ip</font></a>) says: <br><p class=\"BottomBorder\"></p> <table><tr><td><img src=\"http://www.djsmiley.net/images/Icons/People/Anonymous 2.png\" height=\"50\" width=\"50\"></td><td>$comment</td></tr></table> <br><p class=\"BottomBorder\"></p> added on $time<p><em>$email</em></p> </p> </div><br> "); } } // end while /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/ ?> I have a form on a page which is accessed when a user logs into their account. The form dynamically pulls bits of the users info from 2 tables in a mysql database, Tables (ITEMS) and Table (USERS). Table (USERS) holds the users info (NAME, EMAIL ETC) while Table (ITEMS) hold information about the users items for which they may have several of. When the form page is accessed all the users items from Table (ITEMS) are dynamically shown on the form with several radio buttons at the side of each item. The user can tick certain radio buttonss at the side of each item and click the send button. TRYING TO ACHIEVE... After the form is sent a thank you message is returned on the same page with details of the items and what radios were ticked. An Email of the same is sent to user with info of the items and what radios were ticked. An Email is also sent to me with same info of the items and what radios were ticked. WHAT I AM ACHIEVING SO FAR WITH CODE BELOW: The form page is ok showing all users items, radios, send button etc. The returned thank you page is fine showing items, what radios were checked etc. Even the email part is working sending an email to the user and myself. THE PROBLEM IS THAT A SEPERATE EMAIL IS SENT TO BOTH OF US FOR EACH ITEM THE USER HAS IN THE DATABASE. I JUST WANT ONE EMAIL SENDING TO BOTH OF US DETAILING ALL ITEMS. I realise this is because of the while statement in the call to the database which is looping the below code for each item thus sending an email for each item. What I can not suss out is how to send just the one email with all items on. Tried moving the closing loop bracket all over the place and parts of the code but to not avail. THE CODE: (some unecessary code removed from echo/thank you to simplify) <table width="100%"> <tr> <td class="bodytext"><strong>Name</strong></td> <td class="bodytext"><strong>Ref</strong></td> <td><strong>Status</strong></td> <td><strong>Type</strong></td> <td><strong>Date</strong></td> <td><strong>Extend</strong></td> <td><strong>Feature</strong></td> <td><strong>Offer</strong></td> </tr> <form action="example-this-page" method="post"> <input type="hidden" name="action" value="0"> <input type="hidden" name="id" value="<?php echo $_REQUEST["id"]; ?>"> <?php $sql = "SELECT * FROM ".$TABLES["items"]." WHERE user_id='".$_SESSION["UserAccount"]."'"; $sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql); while ($ITEMS = mysql_fetch_assoc($sql_result)) { $sql = "SELECT * FROM ".$TABLES["users"]." WHERE id='".$ITEMS["user_id"]."'"; $sql_resultT = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql); $USER=mysql_fetch_assoc($sql_resultT); ?> <? if (isset($action)) { $to = $USER["email"]; $mailheader = "From: $email\r\n"; $mailheader .= "Reply-To: $email\r\n"; $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; $msg = "Dear ".stripslashes($USER["name"])."<br><br> <table><tr> <td><strong>Name</strong></td> <td><strong>Ref No</strong></td> <td><strong>Status</strong></td> <td><strong>Type</strong></td> <td><strong>Date</strong></td> <td><strong>Extend</strong></td> <td><strong>Feature</strong></td> <td><strong>Offer</strong></td> </tr> <tr> <td>".stripslashes($ITEMS["name"])."</td> <td>".stripslashes($ITEMS["ref"])."</td> <td>".stripslashes($ITEMS["status"])."</td> <td>".stripslashes($ITEMS["type"])."</td> <td>".stripslashes($ITEMS["date"])."</td> <td>".$_POST['extend']."</td> <td>".$_POST['feature']."</td> <td>".$_POST['offer']."</td> </tr> </table> "; mail($to, "subject", $msg, $mailheader) or die ("Failure"); mail("me@me.co.uk", "subject", $msg, $mailheader) or die ("Failure"); echo "<br /><br /><font size=2> <strong><center>Thank you!</center><br /> Your details of your request has been sent:</center><br /> "; }; ?> <tr> <td><?php echo stripslashes($ITEMS["name"]); ?></td> <td><?php echo stripslashes($ITEMS["ref"]); ?></td> <td><?php echo stripslashes($ITEMS["status"]); ?></td> <td><?php echo stripslashes($ITEMS["type"]); ?></td> <td><?php echo stripslashes($ITEMS["date"]); ?></td> <td><input type="radio" name="extend<?php echo stripslashes($ITEMS["id"]); ?>" value="No"> No <input type="radio" name="extend<?php echo stripslashes($ITEMS["id"]); ?>" value="Yes" /> Yes</td> <td><input type="radio" name="featured<?php echo stripslashes($ITEMS["id"]); ?>" value="No"> No <input type="radio" name="featured<?php echo stripslashes($ITEMS["id"]); ?>" value="Yes" /> Yes</td> <td><input type="radio" name="latedeal<?php echo stripslashes($ITEMS["id"]); ?>" value="No"> No <input type="radio" name="latedeal<?php echo stripslashes($ITEMS["id"]); ?>" value="Yes" /> Yes</td> </tr> <?php } ?> <tr> <td> <input type="submit" name="Submit" value="Send"></td> </tr></table> </form> </table> I'm trying to find the write coding to pull the First and Second words from the 2nd line and the entire 3rd line from this file and have them as $subject1 and $subject2 And I have no php background. http://www.weatherserver.net/text/CWTO/WOCN11.txt so $subject1 = WOCN11 CWTO and $subject2 = SPECIAL WEATHER STATEMENT Hey guys i have a contact form for my site working fine but when i receive the emails i get some unwanted texts after the email section. here they r : name1: ryan number: 343244 message1: hey email: ss@yahoo.com clearField: [type Function] label1: NAME label2: E-MAIL label3: PHONE label5: MESSAGE countField: 5 arrayLabel: undefined,NAME,E-MAIL,PHONE,undefined,MESSAGE i: 6 txtField: _level0.topmenu.page.pages.contactform.txtField5 _request: contact/email.php the script Code: [Select] <?php /***************************************************\ * PHP 4.1.0+ version of email script. For more * information on the mail() function for PHP, see * http://www.php.net/manual/en/function.mail.php \***************************************************/ // First, set up some variables to serve you in // getting an email. This includes the email this is // sent to (yours) and what the subject of this email // should be. It's a good idea to choose your own // subject instead of allowing the user to. This will // help prevent spam filters from snatching this email // out from under your nose when something unusual is put. $sendTo = "hey@email.com"; $subject = "helloy"; // variables are sent to this PHP page through // the POST method. $_POST is a global associative array // of variables passed through this method. From that, we // can get the values sent to this page from Flash and // assign them to appropriate variables which can be used // in the PHP mail() function. // header information not including sendTo and Subject // these all go in one variable. First, include From: $headers = "From: " . $_POST["firstName"] ." ". $_POST["lastname"] . "<" . $_POST["email"] .">\r\n"; // next include a replyto $headers .= "Reply-To: " . $_POST["email"] . "\r\n"; // often email servers won't allow emails to be sent to // domains other than their own. The return path here will // often lift that restriction so, for instance, you could send // email to a hotmail account. (hosting provider settings may vary) // technically bounced email is supposed to go to the return-path email $headers .= "Return-path: " . $_POST["email"]; // now we can add the content of the message to a body variable $message = $_POST['message']; $message = ""; foreach($_POST as $key=>$value) { $message .= $key.": ".$value."\n\r"; } // once the variables have been defined, they can be included // in the mail function call which will send you an email mail($sendTo, $subject, $message, $headers); ?> can some1 suggest me something iam a complete noob ! Hi, i have a class which i am writing(just a small test) which is supposed to create a label for a form but nothing is showing up. Here is the html part: $frobj=new asf_form(); $frobj->form_label('Username'); and here is the class code: function form_label($label='') { if($label == '') { return false; } else { return '<label for='.$label.'>'.$label; } } Have i done something wrong? People on this forum have given me great advise. Now I almost have my login PHP correct. One thing is going wrong. (has to be my code) When I run the login and have it processed, it falls through the testing directly to the error statements. Checked the code but I cant figure it out. Been playing with it for 3 hours. I'll be highly grateful if someone out there can solve this. My code: <?php // Open members db - ceck to ensure user is not previously logged in - if no log yhe user in to the mem_log table. // If yes display appropriate error message. /// Page Name: login.php /// Date: 11-7-10 Time: 5:34 /// Tested: 11-7-10 by: bnl include "include/session.php"; include "include/z_db.php"; $userName=$_POST['userName']; $password=$_POST['password']; ?> <!doctype html> <html> <head> <title>Taft Union High School Alumni Class of 1965</title> <meta name="GENERATOR" content="NotePad++"> <meta name="FORMATTER" content="NotePad++"> </head> <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000"> <?php $userName=mysql_real_escape_string($userName); $passWord=mysql_real_escape_string($passWord); $sql_query = mysql_query("SELECT * FROM `signup` WHERE `userName`='$userName' AND `passWord` = '$passWord' LIMIT 1"); if (mysql_num_rows($sql_query) > 0) { //log session data include "include/newsession.php"; $tm=date("Y-m-d H:i:s"); //$ip=@$REMOTE_ADDR; // The above line is commented and the line below is used for the servers where register_global=Off $ip=$_SERVER['REMOTE_ADDR']; echo $ip; $rt=mysql_query("insert into mem_login(id,userName,ip,tm) values('$_SESSION[id]','$_SESSION[userName]','$ip','$tm')"); // Username and password passed redirect to memPage header("location: memPage.html"); session_unset(); } else { // RUN YOUR ERROR MESSAGE echo " <div style='width:350px; border: medium ridge navy; background-color:gold; padding:10px;' > <table border='0' cellspacing='0' cellpadding='3' align='center bgcolor='gold'> <th style='font-weight:bold; fony-size:1,4em;color:#FFFFFF;background-color:red;'> INCORRECT USERNAME OR PASSWORD <hr> </th> <tr> <td>The username or Password was not located in the database, Check to ensure you have the correct information. If you need assistance, contact the site administrator at: <br> http://www.admin@tuhs-class65.c9m. <br><br> <center> <input type='button' value='Retry' onClick='history.go(-1)'> </center> </td> </tr> </table> </div> "; } ?> </body> </html> I know the program is working as the includes are being pulle in. I also have two records in the table. I have made a php cart : check it out on http://fhcs.be/cart-demo4/ My question is: when I order something by clicking on the "voeg toe" button, I'm redirected to the shopping cart. But I don't want to be redirected to the shopping cart, I want to stay on de menu list. What is an easy way to fix this? thanks people index.php Code: [Select] <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>PHP Shopping Cart Demo · Bookshop</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Welkom, plaats uw order</h1> </div> <div id="booklist"> <h1>Warme dranken</h1> <?php $sql = 'SELECT * FROM products WHERE cat=2'; $result1 = $db->query($sql); $output1[] = '<ul>'; while ($row = $result1->fetch()) { $output1[] = '<li>'.$row['name'].': €'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Voeg Toe</a></li>'; } $output1[] = '</ul>'; echo join('',$output1); ?> <h1>Cocktails</h1> <?php $sql = 'SELECT * FROM products WHERE cat=3'; $result2 = $db->query($sql); $output2[] = '<ul>'; while ($row = $result2->fetch()) { $output2[] = '<li>'.$row['name'].': €'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Voeg Toe</a></li>'; } $output2[] = '</ul>'; echo join('',$output2); ?> </div> </body> cart.php Code: [Select] <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session session_start(); // Process actions $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; case 'delete': if ($cart) { $items = explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($_GET['id'] != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } $cart = $newcart; } break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; } $_SESSION['cart'] = $cart; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>PHP Shopping Cart Demo · Cart</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Uw bestelling</h1> <?php echo writeShoppingCart(); ?> </div> <div id="contents"> <h2>Gelieve na te kijken voordat u bestelt</h2> <?php echo showCart(); ?> <p><a href="index.php">Terug naar lijst</a></p> <form action="mail.php" method="post"> <input type="submit" name="sendemail" value="Bestel" /> <input type="hidden" name="cart" value="<?= $cart; ?>" /> </form> </div> </body> </html> echo "<tr> <td class='trow2' align='center' valign='center' width='1'></td> <td class='trow2' valign='center'> <strong><a href='server.php?view=details&id=" . $list['id'] . "'>" . capitalizeFirstCharacter($list['servername']) . "</a></strong> <div class=\"stat2\"> <div class=\"stat\"> if(!$sock=@fsockopen($list_f['serverip'],$list_f['serverport'], $num, $error, 1)) { echo "<font color='red'><b>Offline</b></font>"; } else { echo "<font color='green'><b>Online</b></font>"; } </div> </div> <div class='smalltext'>" . $list['shortdescription'] . "</div> </td> <td class='trow1' valign='middle' align='left' style='white-space: nowrap'><span class='smalltext'>" . $list['revision'] . "</span></td> <td class='trow2' valign='middle' align='right' style='white-space: nowrap'><font size='4px'>" . $voteAmount . " Votes</font></td> </tr>"; How can I make this echo code work? Okay, I am writing a new form validation script that also keeps the data so it can re-populate the fields the user already filled out if there is an error on the page so they do not have to fill it out again. Here is an example of the code I am using in the HTML part of the form input elements. <input name="name" type="text" id="name" value="<?php=$fields['name']?>"> Now, the problem I am getting is the <?php=$fields['name']?> code is being physically displayed within the form field at all times. How would I go about having it not display this line of code in the field? Thanks!! This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=348574.0 Hi, my name is Michael Vallier and I am the director of Killer Film Fest. This year I have incorporated some new features and need some php help. If you are able to help with either or both problems, please let me know. Thanks in advance. 1. I am using a forum and I need help customizing it. I have no idea what I am doing. I have changed a few things, but don't know enough to do what I want. I don't need anything crazy, just to fit the look of our website. The forum is not open yet but you can see it he http://www.killerfilmfest.com/forum/ 2. I found a add-on to my website which is a file manager. People can create an account and upload files to my FTP server. I want to use this for filmmakers to upload their films if they choose to do it this way. There is a 10mb limit and it is possible to make it unlimited. I contacted the creator of the application and he led me to a wiki page with the directions. It looked real simple and I tried to do this but without any luck. So if there is anyone out there who can help, that would be great. Thanks -Michael Vallier- let say i have this <a href="myuploadfolder/picture1.jpg">Picture</a> and when user click on the link, they can see in which folder their picture were kept...is this dangerous?? if yes then how to hide it?? thanks in advance |