PHP - Back To Basics, What Am I Missing?
nothing is echoed
for the second foreach??? foreach($pictures as $picture) -im breaking cause it's a large file Code: [Select] $doc = new DOMDocument(); $doc->load('accommodation.xml'); $i = 0; $accommodations = $doc->getElementsByTagName('accommodation'); foreach($accommodations as $accommodation) { if(++$i > 2) break; $supplierID = $accommodation->getElementsByTagName('code')->item(0)->nodeValue; $pictures = $accommodation->getElementsByTagName('pictures')->item(0)->nodeValue; $pictures=array(); foreach($pictures as $picture) { echo $url = $picture->getElementsByTagName('url')->item(0)->nodeValue; } }//end //XMl schema <?xml version="1.0" encoding="utf-8"?> <accommodations> <accommodation> <code>1</code> <pictures> <picture> <url>http://example.com/images.k.jpg</url> </picture> </pictures> Similar TutorialsPlease, take a look to the following code.After clicking Next it goes to overview.php.Why when I click back on my browser to return to this page again, it is not returning back? When I click back I receive "Confirm Form Resubmission" message. After refreshing page it loads page. I guess problem is in "session_start();" part. Something to do with cookies. Please, help me it is very urgent for me. <?php session_start(); echo "<html> <head> <title>Hello World</title> <meta http-equiv='Content-Type' content='text/html; charset=Windows-1252'/> </head>"; require_once ('functions.inc'); if(!isset($_POST['userid'])) { echo "<script type='text/javascript'>"; echo "window.location = 'index.php'"; echo "</script>"; exit; }else{ session_register("userid", "userpassword"); $username = auth_user($_POST['userid'], $_POST['userpassword']); if(!$username) { $PHP_SELF = $_SERVER['PHP_SELF']; session_unregister("userid"); session_unregister("userpassword"); echo "Authentication failed " . "Please, write correct username or password. " . "try again "; echo "<A HREF=\"index.php\">Login</A><BR>"; exit; } } function auth_user($userid, $userpassword){ global $default_dbname, $user_tablename; $user_tablename = 'user'; $link_id = db_connect($default_dbname); mysql_select_db("d12826", $link_id); $query = "SELECT username FROM $user_tablename WHERE username = '$userid' AND password = '$userpassword'"; $result = mysql_query($query) or die(mysql_error()); if(!mysql_num_rows($result)){ return 0; }else{ $query_data = mysql_fetch_row($result); return $query_data[0]; } } echo "hello"; echo "<form method='POST' name='myform' action='overview.php'>"; echo "<input type='submit' value='Next'>"; echo "</form>"; ?> I was reading how to do some beginner stuff in PHP so this to you guys is easy right?
Why dosent the code work properly? And or am I trying stuff that is to advanced for a total noob??
this is the php code from the tutorial:
<?php I could use some help remembering how sessions and cookies work... (Looks like another thing I have forgotten about!) In one of my old scripts, I start a session using...
session_start()
And then I have...
$sessMemberID = (isset($_SESSION['sessMemberID']) ? $_SESSION['sessMemberID'] : '');
It appears my old naming conventions aren't so clear after being away for several years... In my database I have a MEMBER.id (table/column) which is just an AutoNumber, and I thought that PHP create a "Session ID" but that it was some long hexadecimal number?
So it's not clear to me what is in $sessMemberID.
I tried to look in the cookies file under my Firefox profile, but when I open it in BBEdit all i see is gibberish in that file.
Can someone please help me put these disparate parts together?
Thanks!
Could anyone point me in the right direction for downloading app store statistics from: -the Apple App Store -The Android Market -the Amazon AppStore Specifically, I'd like to get the -average selling price of apps -the top selling apps -the distribution of tablets vs. phones, etc. (e.g. how many apps are there for Honeycomb? How many for iPad?) -total number of apps in store -free vs. paid apps I've seen some sites like http://148apps.biz/app-store-metrics/ and http://www.appbrain.com/stats/ How do these sites get their data? There must be a way to export the whole app store database as a CSV file, or import it to MySQL and run queries. Thanks much for any direction. I've been using PHP includes for a while now but I've just started to try to get more advanced. (not much more) I'm using this code to both generate my page titles and give my li tags a class of active so I can style them with css as being in a down state. All is working but I just need a more efficient way of doing this I think. I currently have Code: [Select] <?php $title = basename($_SERVER['SCRIPT_NAME'], '.php'); if ($title == 'index') { $title = 'home'; } $title = ucfirst($title); $title = str_replace('-', ' ', $title); $title = ucwords($title); ?> Then in my unordered list I have Code: [Select] <?php if ($title == 'Product Selector'||$title == 'Kingston Range') {echo 'class="active"';} ?> I could continue to say if title = a or b or c or d etc but could I use an array to store all of these titles and check to see if the title is in the array? or is there a better way to do this? Thanks in advance This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=317962.0 if anyone out there fancy's helping the needy please can you cast your eyes over my mess! and possibly help me find my way out of this maze? So im useing a third party form, and a third party php script.......... cant get them to work together . form script : [color=red//-------------------------------------------------[/color] <form action="phpquote.php" method="post" id="reserve-form"> <div class="box"> <div class="left-top-corner"> <div class="right-top-corner"> <div class="border-top"></div> </div> </div> <div class="border-left"> <div class="border-right"> <div class="xcontent"> <h5>Get an online quote for your journey</h5> <p>please fill in all fields for your quote.</p> <fieldset> <div class="field"> <label>Customer Information</label> <input type="text" id="name" value="Name" onblur="if(this.value==''){this.value='Name'}" onfocus="if(this.value=='Name'){this.value=''}" /> </div> <div> <input type="text" id="number" value="Phone" onblur="if(this.value==''){this.value='Phone'}" onfocus="if(this.value=='Phone'){this.value=''}" /> </div> </fieldset> <fieldset class="style1"> <div class="field"> <label>Travel Date/ Time</label> <select id="year"> <option>2010</option> <option>2011</option> </select> <select class="sel-1" id="month"> <option>Jan</option> <option>Feb</option> <option>Mar</option> <option>Apr</option> <option>May</option> <option>Jun</option> <option>Jul</option> <option>Aug</option> <option>Oct</option> <option>Sep</option> <option>Nov</option> <option>Dec</option> </select> <select class="sel-2" id="date"> <option>1</option> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> <option>6</option> <option>7</option> <option>7</option> <option>8</option> <option>9</option> <option>10</option> <option>11</option> <option>12</option> <option>13</option> <option>14</option> <option>15</option> <option>16</option> <option>17</option> <option>18</option> <option>19</option> <option>20</option> <option>21</option> <option>22</option> <option>23</option> <option>24</option> <option>25</option> <option>26</option> <option>27</option> <option>28</option> <option>29</option> <option>30</option> <option>31</option> </select> </div> <div class="field"> <select class="sel-2" id="time"> <option>00</option> <option>01</option> <option>02</option> <option>03</option> <option>04</option> <option>05</option> <option>06</option> <option>07</option> <option>08</option> <option>09</option> <option>10</option> <option>11</option> <option>12</option> <option>13</option> <option>14</option> <option>15</option> <option>16</option> <option>17</option> <option>18</option> <option>19</option> <option>20</option> <option>21</option> <option>22</option> <option>23</option></select> <select class="sel-2" id="time"> <option>00</option> <option>15</option> <option>30</option> <option>45</option> </select> </div> <div class="field"> <label>No. Passangers</label> <select id="year"> <option>01</option> <option>02</option> <option>03</option> <option>04</option> <option>05</option> <option>06</option> </select> </div> </fieldset> <fieldset class="style2"> <div class="field"> <label>Pickup Information</label> <input type="text" id="where" value="Pickup Address" onblur="if(this.value==''){this.value='Pickup Address'}" onfocus="if(this.value=='Pickup Address'){this.value=''}" /> </div> <div> <select id="where"> <option>or Airport</option> <option>Stansted</option> <option>Gatwick</option> <option>Heathrow</option> <option>Luton</option> </select> </div> </fieldset> <fieldset class="style2 style3"> <div class="field"> <label>Drop-off Information</label> <input type="text" id="to" value="Drop-off Address" onblur="if(this.value==''){this.value='Drop-off Address'}" onfocus="if(this.value=='Drop-off Address'){this.value=''}" /> </div> <div> <select id="to"> <option>or Airport</option> <option>Stansted</option> <option>Gatwick</option> <option>Heathrow</option> <option>Luton</option> </select> </div> </fieldset> </div> </div> </div> <div class="left-bot-corner"> <div class="right-bot-corner"> <div class="border-bot"><a href="#" class="link2" onclick="document.getElementById('reserve-form').submit()"><em><b>Get Quote</b></em></a></div> </div> </div> </div> </form> //----------------------------------------------------------------------------- php script //----------------------------------------------------------------------------- <?php //--------------------------Set these paramaters-------------------------- // Subject of email sent to you. $subject = 'Results from Contact form'; // Your email address. This is where the form information will be sent. $emailadd = 'm.mcdade@hotmail.co.uk'; // Where to redirect after form is processed. $url = 'http://www.mock.thetaxirank.co.uk/thankyou.html'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty. $req = '0'; // --------------------------Do not edit below this line-------------------------- $text = "Results from form:\n\n"; $space = ' '; $line = ' '; foreach ($_POST as $key => $value) { if ($req == '1') { if ($value == '') {echo "$key is empty";die;} } $j = strlen($key); if ($j >= 20) {echo "Name of form element $key cannot be longer than 20 characters";die;} $j = 20 - $j; for ($i = 1; $i <= $j; $i++) {$space .= ' ';} $value = str_replace('\n', "$line", $value); $conc = "{$key}:$space{$value}$line"; $text .= $conc; $space = ' '; } mail($emailadd, $subject, $text, 'From: '.$emailadd.''); echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; ?> //----------------------------------------------------------------------------- any advice will be appreciated..... thanks in advance to any kind souls !!! To make a long story short, I have a series of forms, where certain options are visible depending on what the user selected on the previous form. The final form processing is where I'm having issues. I have the following for each option, to check if that option was selected (this is all somewhat pared down for clarity): Code: [Select] if (isset($_POST['option1']) && $_POST['option1'] > 0){ $option1 = mysql_real_escape_string($_POST['option1']); $query1 = "DELETE FROM table WHERE itemid = '$option1'"; } I have that basic thing for each of the options, where it assigns a deletion query based on each individual option. Later in my code, I have the following, which again checks if each option was selected (it's restated because it's after several error checks) then is supposed to run the query that was assigned in the previous part: Code: [Select] if ($_POST['option1'] > 0){ mysql_query($query1); } if ($_POST['option2'] > 0){ mysql_query($query2); } if ($_POST['option3'] > 0){ mysql_query($query3); } (etc, for all the options) My problem is that the queries are not executing and I can't see any reason why not. Query #1 is working... it executes the deletion query and all is well, but if I try to select any options other than #1, the query doesn't execute. I tried echoing the queries within the second if statements above (where it runs the queries) and it's echoing them fine (and they look normal), so I know it's able to run the queries, it just isn't... Am I blind? lol. I must be missing something obvious because this is driving me crazy. Thank you in advance. Please let me know if you need more info. Really not seeing where my missing parenthesis goes. Code: [Select] if(isset($this->uri->segment(3)) AND ((empty($this->uri->segment(3))||($this->uri->segment(3) === FALSE)||(trim($this->uri->segment(3)) == ''))) Hi. I am new to PHP and trying out database connections. I am trying to query the database, to see if the date matches a record in the field 'date'. If it does echo yes, if there are no matches 'no'. Can anyone tell me what is missing from my code: Code: [Select] <?php $con = mysql_connect("localhost","root","root"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("date_picker", $con); $date= $_POST['date']; $new_date = date('Y-m-d',strtotime($date)); $sql = 'SELECT date FROM availability' if (date = $new_date) echo "Yes"; else echo "No"; mysql_close($con) ?> I am running a search query from MYSQL and it works, but now I want to get a little custom. I am selecting one field, out of many called paid1 which in database is either Yes or No. I want to do this: if paid1 is NO display Pay Now and everything else display Yes. I want this to be under new heading of paid1b. So the code should look something like this: $paid1b= if(['paid1'}==No){echo "Pay Now";} else {echo "YES";} But I am missing something somewhere. What is it? Thanks The user will click on the first button (.Applybutton) which opens a bootstrap modal with the ID ApplyModal. From then on an apply button (.SendButton) will send the job id that is passed in the first button press $_POST['jobid'] to the database. Let's say I have an array: $myArray[0] = "AtG2"; $myArray[1] = "AtG4"; $myArray[2] = "AtG1"; $myArray[3] = "AtG3"; $myArray[4] = "AtG5"; I want to sort it alphanumerically, so that the key/value pairs are as follows: [zero*] => "AtG1" [1] => "AtG2" [2] => "AtG3" [3] => "AtG4" [4] => "AtG5" * = I have to write [zero] because putting an actual zero number inside of [ and ] braces converts it to an HTML list bullet. It *appears* that natsort() is the proper function for this. The only problem I'm having is that natsort() doesn't manipulate key/value pairs. To confuse me even more, literally every example I can find on using natsort() uses it in conjunction with print_r() like so: natsort($someArray); print_r($someArray); Obviously, something is happening to $someArray when passed to natsort(), otherwise, print_r() wouldn't be able to order the indices in synch with the natural ordering algorithm. Well, I don't need my web app to use print_r()! I just need the darn key/value pairs reordered so that when I echo $myArray[3], I know I'm going to get "AtG4". What am I missing here? What is the point of calling it a "sort" if it doesn't manipulate the key/value pairs??? How can I get what I want?!? well when i am in my forum thing and i go to click on a 'topic' it says no topic exists. and there is one there idk what im missing in the code to make it view it in my table.. Code: [Select] <?php require("top.php"); ?> <div id='content'> <div id='homepageright'> <?php include_once("scripts/connect.php"); if($username){ $cid = $_GET['cid']; $tid = $_GET['tid']; $sql = "SELECT * FROM topics WHERE category_id='".$cid."' AND id='".$tid."' LIMIT 1"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 1){ echo "<table width='100%'>"; if($username){ echo "<tr><td colspan='2'><input type='submit' value='Add Reply' onClick=\"window.location = post_reply.php?cid=".$cid."&tid=".$tid."\" /><hr /> "; } While ($row = mysql_fetch_assoc($res)) { $sql2 = "SELECT * FROM posts WHERE category_id='".$cid."' AND topic_id= '".$tid."'"; $res2 = mysql_query($sql2) or die(mysql_error()); while ($row2 = mysql_fetch_assoc($res2)) { echo "<tr><td valign='top' style='border: 1px solid #000000;'><div style='min-height: 125px; '>".$row['topic_title']."<br /> by ".$row2['post_creator']." - ".$row2['post_date']. "<hr /> ".$row2['post_content']."</div></td><td width='200' valign='top' align='center' style='border: 1px solid #000000;'>User Info Here</td></tr><tr><td colspan='2'><hr /></td></tr>"; } echo "</table>"; } } else{ echo "This Topic Does Not Exist."; } } else{ echo "You Must Be Logged In To Continue."; } ?> </div> <div id='homepageleft'> <?php ?> </div> </html> </body> Hey guys I'm not amazing at PHP, but know just enough to be dangerous. Basically I'm trying to get these records from my database to display in rows of 4. For some reason every time, I'm missing a record (the first record returned in my query). It's probably something simple is my code. Would be grateful if anyone could lend a suggestion. Code: [Select] <?php $a=0; $b=3; while ($ArrayData = mysql_fetch_array($QueryData)) { //if a=0, start new row if ($a==0) { echo '<tr>'; } //create cell //if thumbnail exists, use it, otherwise throw in the unavailable image if ($ArrayData["PhotoThumb"]!="") { $ImageToUse = $ArrayData["PhotoThumb"]; } else { $ImageToUse = "image_unavailable_thumb.jpg"; } echo ' <td width="33%" align="center" valign="top"><p><a href="item.php?ItemID='.$ArrayData["ItemID"].'"><img src="images/'.$ImageToUse.'" border="0" /></a></p> <p><a href="item.php?ItemID='.$ArrayData["ItemID"].'" class="cart_body_text">'.$ArrayData["ItemName"].'</a><br /> <span class="style1"> <strong>$'.sprintf("%01.2f", $ArrayData["UnitPrice"]).'</strong></span><br /> </p> </td>'; //increment by 1 $a++; //if a = 3 then close the row using </tr>, ready to start a new one if ($a==$b) { echo ' </tr>'; //reset counter, ready to start new row $a=0; } } if ($a > 0 ) { echo '</tr>'; } ?> Thanks guys! Hi all - It's gotta be something obvious, but I can't for the life of me how I'm sending output in this file before I send a header redirect. Can anyone see it? <?php //Initialize securimage captcha session_start(); require_once('dbconnect.php'); // initialize db connection to populate email address include_once('../securimage/securimage.php'); $language = $_POST['lang']; include($language . ".php"); //Load language file for feedback. TODO: Maintain separate file for this so the script doesn't need to load so many unused variables? $securimage = new Securimage(); if ($securimage->check($_POST['captcha_code']) == false) { die($contact_bad_captcha); } // pump post vars into local vars and clean them up, assign to session to display on contact completion function lang($language) { //Give hidden post var for language a human name switch ($language) { case en: return "English"; break; case es: return "Español"; break; default: return "Español"; } } $reason = htmlentities($_POST['reason'], ENT_QUOTES); $name = htmlentities($_POST['name'], ENT_QUOTES); $email = htmlentities($_POST['email'], ENT_QUOTES); $phone = htmlentities($_POST['phone'], ENT_QUOTES); $cell = htmlentities($_POST['cell'], ENT_QUOTES); $method = htmlentities($_POST['method'], ENT_QUOTES); $comments = htmlentities($_POST['comments'], ENT_QUOTES); $lang = lang($language); // Query for email addresses $query = "SELECT `description`,`email` FROM contact WHERE `code` = \"" . $reason . "\" AND `language` = \"" . $language . "\""; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $to = $row['email']; $reason = $row['description']; } $subject = "ELP Contact Form Submission From " . $name; $_SESSION['name'] = $name; $_SESSION['email'] = $email; $_SESSION['phone'] = $phone; $_SESSION['cell'] = $cell; $_SESSION['method'] = $method; $_SESSION['comments'] = $comments; // Build the mail object $header = "From: " . $email . "\r\n"; $header .= "Reply-To: " . $email . "\r\n"; $header .= "Bcc: email@address.com\r\n"; $header .= "Content-type: text/html; charset=iso-8859-1\r\n"; $message = "Reason: " . $reason . "<br>"; $message .= "Name: " . $name . "<br>"; $message .= "Email: " . $email . "<br>"; $message .= "Phone: " . $phone . "<br>"; $message .= "Cell: " . $cell . "<br>"; $message .= "Method to contact: " . $method . "<br>"; $message .= "Comments/Questions: " . nl2br($comments) . "<br>"; $message .= "Language: " . lang($language); // Send it after checking that variables are set correctly if (isset($name) && isset($email) && isset($method) && isset($comments) && isset($header) && isset($message)) { mail($to, $subject, $message, $header); header("Location: ../contactcomplete.php?lang=" . $language); // Forward to completion page which displays what was sent } else { echo $contact_general_error; //Unknown error } ?> Code: [Select] Warning: Cannot modify header information - headers already sent by (output started at /home1/supresen/public_html/configs/es.php:1) in /home1/supresen/public_html/configs/email.php on line 67 Thanks for the help! I've been trying to figure out this issue for a couple of days now. I have a client that insists in using the Innovaeditor in IE. I have placed a stylesheet in on the editors, and it breaks the scrollbar in IE. When I take it out it returns. I still want to preserve the styles I want to set, and be able to scroll down the editor box. It works fine in Firefox. Any help would be MUCH appreciated. I've got a syntax error, but I can't for the life of me see where there's a problem. unexpected T_VARIABLE, expecting ',' or ';' ... on line 35 Code: [Select] <? include("header.php"); ?> <html> <head> <title>login </title> </head> <body> <?php // this is the login page require ('databaseconnect.php'); // set the page title if (isset($_POST['submitted'])) { $e = escape_data($_POST['username']); } else { echo '<p> >font color="red" size="+1> You forgot to enter your user name</font></p>'; $e = FALSE; } // validate password if (!empty($_POST['password'])) { $p = escape_data($_POST['password']); } else { $p = FALSE; echo '<p><font color="red" size="+1:>You forgot to enter your password!</font></p>; } if($e && $p) { $query = "SELECT ID, first_name FROM table WHERE (username='$e' AND password=SHA('$p') AND active IS NULL"; $result = mysql_query($query) or trigger_error("Query: $query\n<br /> MySQL Error: " . mysql_error()); if (@mysql_num_rows($result) ==1) { $row = mysql_fetch_array ($result, MYSQL_NUM); mysql_free_result($result); mysql_close(); $_SESSION['first_name'] = $row[1]; $_SESSION['id'] = $row[0]; // start defining url $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // check for trailing slash illegal access attempts if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // chop off slash } $url .= '/index.php'; ob_end_clean(); //delete the buffer header(:location: $url"); exit(); } else { // no match made echo '<p> >font color="red"size="+1"> Either the user name and password are not correct or you have not activated your account. </font></p>'; } mysql_close(); } ?> <h1>Login</h1> <p> your browser must allow cookies to log in.</p> <form action="login.php" method="post"> <fieldset> <p><b>User name: <input type="text" name="username" size="20" maxlength="20" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?> /></p> <p><b> Password: <input type="password" name="password" size="20" maxlength="20" /></p> <div> align="center"><input type="submit" name="submit" value="Login" /></div> <input type="hidden" name="submitted" value="TRUE" /> </fieldset> </form> <? include("footer.php"); ?> I have a form with a table that contains ONLY dropdown menus for users to select quantities from 25 dinner items. It contains some Javascript, but nothing fancy. In an effort to establish my database and TEST to see how some PHP functions might respond so I could improve my form, I created a mini version of the db in MySQL. But when I click the submit button, the page blinks, the address bar fills with field names, but there is no connect. No error messages. No data transfer. NO NOTHING! I searched the web and copied a form and plugged it in (an html form, a php insert file, and a MySQL database) and it worked fine. I peared down my page to mirror it, and still, no success. What little detail am I missing?? If I have 25 fields but create a db for the first 6, should it function? If I reduce it and try to re-use the same db, am I persuing a problem? I've tried error trapping and changing the form inputs, but it just still doesn't connect. Please help! |