PHP - Noob Question.
Hi all i have a silly noob question....
When i directly query my database with the following i get the exact result i want....... Code: [Select] SELECT * FROM posts WHERE postTopic=3 AND postSubject=business; However when i try this using the following PHP....... $sql = "SELECT * FROM posts WHERE postTopic =" . mysql_real_escape_string($_GET['id']) . "AND postSubject='" . $_SESSION[forum] . "'"; I get no result I also get the correct results from $sql = "SELECT * FROM posts WHERE postTopic =" . mysql_real_escape_string($_GET['id']) . "; and $sql = "SELECT * FROM posts WHERE postSubject='" . $_SESSION[forum] . "'"; mysql_real_escape_string($_GET['id']) is an integer and $_SESSION[forum] is a string. I know this has something to do with the manner in which the query is passed with the AND and the string but i can't for the life of my work out where i am going wrong. Thanks for any help. Similar TutorialsI hope no one rolls their eyes at me, lol, but I literally, just made my first PHP script, but I ran into a snag.
Okay so the code I did was
<!DOCTYPE html> <html> <body> <?php echo <h1>"my First PHP script"</h1>; ?> </body> </html> but in firefox the outcome is always "my first PHP script?> I had added the h1 tags because it wouldn't print at all before I did. I'm trying to figure out what I did wrong. Long story short i'm paginating database results. So pages = results / res-per-page-limit but 28 / 10 will be 2.8 should i use round() or ceil()? OK so sorry if my understandings a bit off, but if a I want to introduce a class into my doc is the best way to fo this with the include() function? OK, so I have a question about databases and how they sort things being loaded into them. I have a database that I have images uploaded to (some people dont like to do it this way but this is what is going to work for my project). I have it set up with an id column that auto-increments. When I upload the files for some reason it is putting the highest id number first and the second one is the lowest then it goes in order from there. Why would this be happening and how do I correct it? But how do I check input to make sure that the input has to be seperated by commas and has to be a integer like "1,2,3,4,5" is correct if a user puts "1,:25,,l2@" or something funky, I can error out Thanks also is there a php function that does this already? and is this way safe? im trying to store comma seperated id's I'm really sorry if this has been answered (I assume it has) I'm unfamiliar with search terms of what I am trying to do. I have this web page Code: [Select] <html> <body> <?php $con = mysql_connect("localhost","user","pass"); if (!$con) { echo "Fail"; die('Could not connect: ' . mysql_error()); } echo "Triumph"; ?> </body> </html> Which I got from a snippet. I load the webpage expecting to see fail or triumph, but I see nothing. My question is how to run the php script so I see something on the page (hopefully triumph. I apoligise for my noobness, I'm a PHP know nothing at the moment. I'm almost embarrassed to ask such a simple question but I just cannot get this to work. I'm trying to figure out how to use sessions that takes the information from a form on the first page and displays it on the last. I have this on page 1: <?php session_start(); ?> <form action="test2.php" method="post"> <p>Page 1</p> <p>First Name <input type="text" name="first" /></p> <p><input type="submit" value="Next page 2" /></p> And this for page 2: <?php SESSION_START(); $_SESSION['first'] = $_POST['first']; echo $_SESSION['first'] = $_POST['first']; ?> <form action="test3.php" method="post"> <p>Page 2</p> <input type="submit" value="Next page 3" /> </form> And this for page 3: <?php SESSION_START(); $_SESSION['first'] = $_POST['first']; echo $_SESSION['first'] = $_POST['first']; ?> <p>Page 3</p> <p>You're done</p> I can get it to display on page 2 but not on page 3. Can anyone tell me why? I've been at this for a long time and it should be simple but I cannot get it to work. Thanks in advance. hey guys! I just got started with php (yesterday) and im currently trying to write a script that cuts email signatures off. The first filter ($sig[0]) works fine, the string is cut and posted- and, well, that's it. I think i did sth wrong within the for- but i cant find it. So please help me out. A hint would be fine already. Thanks in advance- and here is some code: Code: [Select] <?php $string="TESTSTRING!! I AM AN EMAIL TEXT!!! SO RANDOM! --- I AM A SIGNATURE!! HERP DERP CUT ME OFF"; //define possible sig starts (=filter) $sig[0]=("#=="); $sig[1]=("---"); $sig[2]=("the name of an enterprise"); $sig[3]=("___"); for ($i=0; $i<=3; $i++) { /* or count($sig) ? */ $sigpos=strpos($string,$sig[$i]); if($sigpos>0) { $string= substr($string,0,$sigpos); break; echo $string; } else { echo $string; break; } } ?> <br> <? //show where the sig is cut off echo $sigpos; ?> Hi everyone Well I've started learning php yesterday and now I encountered my first problem, I looked around but I don't really know what to search for if I want my answer so here I come Code: [Select] <html> <body> <?php $names = array('Peter','Quagmire','Joe'); $ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34); $who = rand(0,2); $who2 = $names[$who]; echo "$names[$who] is $ages[$who2] years old"; ?> </body> </html> This is the script I have, and there is the kind of script I expected: Code: [Select] <html> <body> <?php $names = array('Peter','Quagmire','Joe'); $ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34); $who = rand('Peter','Quagmire','Joe'); echo "$who is $ages[$who] years old"; ?> </body> </html> But after some search I concluded that rand is only used for random numbers So, my question is, which function should I use to achieve my goal? Is there any randstring('string1','string2',etc) command? Tnx for your time So I'm using simplexml_load_file($url) to load up a client's XML file so I can use it with a jQuery slide show right. My problem is that some of the strings within the xml files are often times sentences and when I echo, for example... Code: [Select] echo $xml->images->categories->category[$gallery]->images->image[0]->description[0]; I should see Dream as if you'll live forever, Live as if you'll die today but all I'm getting is Dream as if you It appears as though php is getting confused when it sees those little single quotes. Anyone? Hello everyone! I'm completely new to PHP and Databases. I've managed to do some nice work by reading, but now I've encountered a problem I can't solve. I made a site with trailers and got tierd of adding them manually. So I created a form which sends the trailer info to my database. There's now trailers in specific organized genres. But the list is beginning to get really big so I wanted to show just 10 trailers per page. And so I found out I could use a paging system which I ALMOST got working. Just one last thing that needs to be fixed and that is when I click on next page "http://www.xxxxxxxx.com/test.php&page=2" it doesn't show the content. While "http://www.xxxxxxxx.com/test.php" does. So I just need that next button to work, I don't know if theres something missing or what it is... Note: I'm new to all this so please excuse my very very bad coding. Here is my code: test.php <link rel="stylesheet" type="text/css" media="all" href="http://www.xxxxxxxxxxxxx.n.nu/createdfiles/trailers/style-twentyten.css" /> <link rel="stylesheet" type="text/css" media="all" href="http://www.xxxxxxxxxxxxx.com/paginate.css" /> <?php $rpp = 10; // results per page $adjacents = 4; $page = intval($_GET["page"]); if(!$page) $page = 1; $reload = $_SERVER['PHP_SELF']; // connect to your DB: $link_id = mysql_connect("server","username","my password"); mysql_select_db("database"); // select appropriate results from DB: $sql = "SELECT * FROM blablabla WHERE Genre LIKE '%Drama%' ORDER BY `blablabla`.`sort` DESC LIMIT 0, 9999"; $result = mysql_query($sql, $link_id); // count total number of appropriate listings: $tcount = mysql_num_rows($result); // count number of pages: $tpages = ($tcount) ? ceil($tcount/$rpp) : 1; // total pages, last page number $count = 0; $i = ($page-1)*$rpp; while(($count<$rpp) && ($i<$tcount)) { mysql_data_seek($result,$i); $query = mysql_fetch_array($result); // output each row: echo "<br />--------------------------------------------------------------------------------------------------------<br /><br />"; ?><strong> <img src=" <?php echo $query['Poster'];?>" /><?php echo "<br /> <br />"; ////////////////////////////// //SHOW TITLE, YEAR AND GENRE// ////////////////////////////// echo "<H1>"; echo $query['Title']; echo "<br /> <br />"; echo "</h1>"; ?></strong> <?php echo "<H2>"; echo $query['Year']; echo "</H2>"; echo "<br />"; echo "<H3>"; echo $query['Genre']; echo "</H3>"; ?> <a href=" <?php ////////////////////////////// //SHOW IMDB, ACTORS AND PLOT// ////////////////////////////// echo $query['IMDB']; ?> " target="_self">Link to IMDb</a> <?php echo "<br /> <br />"; echo "<H2>Stars:</H2>"; echo "<br />"; echo "<H3>"; echo $query['Actors']; echo "</H3>"; echo "<br />"; echo "<H2>Plot:</H2>"; echo "<br />"; echo "<H3>"; echo $query['Plot']; echo "</H3>"; echo "<br /> <br />"; echo "<H2>"; //////////////// //SHOW TRAILER// //////////////// ?> <div id="<?php echo $query['ID'];?>" style="display: none;"> <?php echo $query['Youtube']; echo "</div>"; ?> <a href="javascript:ReverseDisplay('<?php echo $query['ID'];?>')">Click to show/hide trailer.</a> <?php echo "</H2>"; echo "<br /> <br />"; $i++; $count++; } // call pagination function: include("paginate_one.php"); echo paginate_one($reload, $page, $tpages); ?> <?php //////////////////////////////// //SCRIPT FOR SHOW/HIDE TRAILER// //////////////////////////////// ?> <script type="text/javascript" language="JavaScript"><!-- function HideContent(d) { document.getElementById(d).style.display = "none"; } function ShowContent(d) { document.getElementById(d).style.display = "block"; } function ReverseDisplay(d) { if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; } else { document.getElementById(d).style.display = "none"; } } //--></script> paginate_one.php <?php /************************************************************************* php easy :: pagination scripts set - Version One ========================================================================== Author: php easy code, www.phpeasycode.com Web Site: http://www.phpeasycode.com Contact: webmaster@phpeasycode.com *************************************************************************/ function paginate_one($reload, $page, $tpages) { $firstlabel = "First"; $prevlabel = "Prev"; $nextlabel = "Next"; $lastlabel = "Last"; $out = "<div class=\"pagin\">\n"; // first if($page>1) { $out.= "<a href=\"" . $reload . "\">" . $firstlabel . "</a>\n"; } else { $out.= "<span>" . $firstlabel . "</span>\n"; } // previous if($page==1) { $out.= "<span>" . $prevlabel . "</span>\n"; } elseif($page==2) { $out.= "<a href=\"" . $reload . "\">" . $prevlabel . "</a>\n"; } else { $out.= "<a href=\"" . $reload . "&page=" . ($page-1) . "\">" . $prevlabel . "</a>\n"; } // current $out.= "<span class=\"current\">Page " . $page . " of " . $tpages . "</span>\n"; // next if($page<$tpages) { $out.= "<a href=\"" . $reload . "&page=" .($page+1) . "\">" . $nextlabel . "</a>\n"; } else { $out.= "<span>" . $nextlabel . "</span>\n"; } // last if($page<$tpages) { $out.= "<a href=\"" . $reload . "&page=" . $tpages . "\">" . $lastlabel . "</a>\n"; } else { $out.= "<span>" . $lastlabel . "</span>\n"; } $out.= "</div>"; return $out; } ?> Here you can view a test of it all in action: http://www.mansgullberg.com/test.php please dont hack my site I'm thankfull for all of your answers! Really nice forum this! /kvickan Hi guys, Sorry - I know this is a basic question but I've been out of the game for a year now and need to jog my memory. I am trying to count the number of rows per group. e.g: $sql = "SELECT *, COUNT(id) FROM image GROUP BY city"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); echo $row['COUNT(id)']; So if there are, for example, 5 New York's in the table, 3 London's and 2 Sydney's I want the echo to display 5, 3, 2 Should I use a loop for this? Cheers Hello there. I used this code so many times long ago, but I still don't remeber and don't know what I'm doing wrong. http://circus.ka-blooey.net/ If I try to click on any link below the post, I got the error: Code: [Select] Warning: include(.php) [function.include]: failed to open stream: No such file or directory in /home/kablooey/public_html/circus/index.php on line 5 Warning: include(.php) [function.include]: failed to open stream: No such file or directory in /home/kablooey/public_html/circus/index.php on line 5 Warning: include() [function.include]: Failed opening '.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/kablooey/public_html/circus/index.php on line 5 -----------------------x My index is: Code: [Select] <?php include("header.php"); ?> <? if (empty($_GET["boo"])) {$boo="news/show_news";} include "$boo.php"; ?> <?php include("footer.php"); ?> and the footer, where the links are is: Code: [Select] <br /> <div id="menu"><center><a href="http://circus.ka-blooey.net">clear</a> ---x--- <a href="?boo=out">links out</a> ---x--- <a href="?boo=credits">credits</a></center></div><br /> <br /> <br /> <div id="footer"><img src="http://circus.ka-blooey.net/layout/circus_footer.jpg" /></div> </div> </div> </div> </body> </html> Help please? =/ hey guys! Im trying to get hashtags out of a string. The function works so far- but i cant transfer the insides of the preg_match_all array into the string. A hint would be fine already. Thanks in advance- and here is some code Code: [Select] <?php //example string $strcontent = "ima string... #wat #taggy #taggytag im in your stringz, stealing your charz!"; //find hashtags preg_match_all("/(#\w+)/", $strcontent, $matches); echo $matches; //the output is just "array" -> why? foreach ($matches as $match) { // $tempmatch=$match[1]; #####like this? //hiding the hashtags via span $strtemp="<br>ima span<br>" . $match . "<br>ima /span<br>" . $strcontent; $strcontent = $strtemp; echo $strcontent; } #echo $strcontent; # <span style="display:none;"></span> ?> Hey all, I have read as much as I could about "->" (I guess its called the arrow operator) anyway I cant seem to comprehend what it is. Could someone please explain it in the most simplistic way? Thanks in advanced. Please bear with me. In an html file there is an <!-- BEGIN poll --> ..... <!-- END poll --> I need to draw a separation hr between all rows escept the first one. I believe I need a counter. Please show me how to do this. Thank you. I'm a very new PHP user (as in, I just started today) and need to make a set of navigation buttons which will take the user to "next" or "previous" pages. I assume that the $_GET function is involved, but I don't know how to do it. It needs to work like this: If the URL looks like "http://website.com/page1.php" I need the "next" button (a href image) to change it to "/page2.php", and while on page 2, for the "previous" button to take the user to "/page1.php" and so forth. How can I cause the page number to increment or decrease respective to the href image being clicked? Hey guys, I'm new to PHP and I'm currently teaching myself. I'm looking over some code and I'm confused when to use "." inside of code. Can someone please explain to me? Here's some example code I read from a book: <?php $counter = 1; while ($counter <= 12) { echo $counter." times 2 is ".($counter * 2). "<br />" $counter++; } ?> Thanks! well, here's my problem, im new to php, i currently working on this mini online shop the picture will explain it well, i've managed to create the receipt per shop but i cant do the receipt of the overall shopping here is my code: <html> <head> <title>My Shop 4</title> <script type="text/javascript"> function gohome() { window.open("receipt.php","_self"); } function changeshop() { window.open("home.html","_self"); } </script> </head> <body> <form action="" method="POST"> <input type="checkbox" name="prod1" id="prod1"\ value=10>Product 1 10.00php<br> <input type="checkbox" name="prod2" id="prod2"\ value=20>Product 2 20.00php<br> <input type="checkbox" name="prod3" id="prod3"\ value=30>Product 3 30.00php<br> <input type="checkbox" name="prod4" id="prod4"\ value=40>Product 4 40.00php<br> <input type="checkbox" name="prod5" id="prod5"\ value=50>Product 5 50.00php<br> <input type="submit" name="submit" id="submit" value="Buy!!"><br> <?php $det = 4; require("../Labphp/lab.php"); shop($det); ?> </form> </body> </html> and here's the php part <?php $total = 0; $total3 = 0; $total4 = 0; $recent ="HAHAHA"; global $total,$total3,$total4,$recent; ?> <?php function shop($num) { $value1 = $_POST['prod1']; $value2 = $_POST['prod2']; $value3 = $_POST['prod3']; $value4 = $_POST['prod4']; $value5 = $_POST['prod5']; $sum=0; $sum = $value1 + $value2 + $value3 + $value4 + $value5; if($sum!=0) { echo "Selected Products<br>"; echo "Product Name       Price<br>"; if($value1==true) { echo "Product 1              10.php<br>"; } if($value2==true) { echo "Product 2              20.php<br>"; } if($value3==true) { echo "Product 3              30.php<br>"; } if($value4==true) { echo "Product 4              40.php<br>"; } if($value5==true) { echo "Product 5              50.php<br>"; } echo "Total                     $sum php<br>"; if($num==4) { $total4=$sum; $recent.="Shop 4                  $total4 php<br>"; } else if($num==3) { $total3=$sum; $recent.="Shop 3                  $total3 php<br>"; } $total = $total4 + $total3; echo "$recent              $total"; echo "<input type='button' name='go' id='go' value='Choose Another Shop' onclick='javascript:changeshop();'>"; echo "<input type='button' name='end' id='end' value='End Shopping' onclick='javascript:gohome();'>"; } } function getshopping() { return $recent; } ?> the receipt code <?php require("../Labphp/lab.php"); ?> <html> <head> <title>Official Receipt</title> </head> <body <?php echo $_REQUEST["'$recent'"]; ?> </body> </html> I had a developer working on stuff for my site and he died before he got to the uploader. I am not a programmer. I can alter a few basic things, but this is beyond me. I found this basic uploader that I could edit the locations, file types, etc. It is missing one area of functionality that I need, the ability to define how many upload fields through a variable (which is set in an earlier form). So for example $fields = "3" then 3 upload fields appear with descriptions set by variables (for examples sake...front and then upload area, back and then upload area, misc. and upload area). I know this might not make a lot of sense. If you need any clarification please contact me. Any help would be much appreciated! |