PHP - Can't Store Value In Variable ???
It seems that in the following script I am not able to make $page contain some values as it always acts as it contains 0.
The script will give you more idea about what I wanna do with it. Code: [Select] <?php include('dbinfo.inc'); session_start(); $connect= mysql_connect($host,$dbuser,$password) or die("connect to database fails"); mysql_select_db($dbname, $connect); //This will set the number of messages we want to display on each page $rows_per_page = 5; function show_msg() { echo "<tr align='center'> <td>$row[message]</td> </tr> <tr><td><strong>Sent By: $_SESSION[username] ON Date: $row[date]</strong></td></tr> <tr><td></td></tr>"; } //This will set the necessay variables required to set the page layout function page_vars() { $sql = "select * from msgs"; $result = mysql_query($sql, $connect); $numrows = mysql_num_rows($result); $total_pages = ceil($numrows/$rows_per_page); //Check whether page is given or not if(isset($_GET["page"])) { $page = $_GET["page"]; } else { $page = 1; } if($page < 1): { $page = 1; } elseif($page > $total_pages): { $page = $total_pages; } endif; } if($_SESSION[loggedin] == TRUE && $_SESSION[actype] == lecturer) { echo "<form action='postmsg.php' method='POST'>"; echo "<table width='80%' border='1'><tr align='center'><td><strong>To send a new message type it in the below box and press SUBMIT</strong> </td></tr>"; echo "<tr align='center'> <td><textarea name='msgarea' cols='40' row='5'></textarea></td> </tr> <tr align='center'> <td><input type='submit' value='Send Message' /></td> </tr> </table>"; $limit .= 'LIMIT '.($page - 1)*$rows_per_page.', '.$rows_per_page; echo $limit; $sql = "select * from 'msgs' $limit"; $result = mysql_query($sql); echo "<table width='80%' border='1'>"; $row = mysql_fetch_assoc($result); while($row) { show_msg(); } } else { page_vars(); $limit .= 'LIMIT '.($page - 1)*$rows_per_page.', '.$rows_per_page; $sql = "select * from msgs $limit"; $result = mysql_query($sql,$connect); echo "<table width='80%' border='1'>"; while($row = mysql_fetch_assoc($result)) { show_msg(); } echo "<tr align='center'> <td> <a href='$_SERVER[php_self]?page=1'>First Page</a> <a href='$_SERVER[php_self]?page=($page - 1)'>$page</a> <a href='$_SERVER[php_self]?page=$page'>$page</a> <a href='$_SERVER[php_self]?page=($page + 1)'>$page</a> <a href='$_SERVER[php_self]?page=($total_pages)'>>>>Last Page</a> </td> </tr>"; echo "</table>"; } ?> now when i echo $limit it always shows "-5, 5" , that's not what i want from this script. Instead I want limit to store "0, 1" with the same concept not direct because it will change according to what $_GET[page] holds. Hope I will get the solution here.... Similar TutorialsQuote i need to store a variable from database like if i have "copies" in one of my column in my database then i have to store a particular value for copies store it to $copies here i want that i can store value of copies into $copies $update_book="update book set copies=copies-1 where bookid='$bookid'"; $result=mysql_query($update_book,$linkID1); if($result) { print "<html><body background=\"header.jpg\"> <p>book successfully subtracted from database</p></body></html>"; } else { print "<html><body background=\"header.jpg\"> <p>problem occured</p></body></html>"; } } hello, um i got a form that stored an array of variables upon users clicks. it submits to another page fine as an array and i can print them using if(!empty($_POST['langSpoken'])) { echo "\n<p><strong>You selected the following LangSpoken:</strong></p>\n<ul>"; foreach($langSpoken as $lang) { // exclude any items with chars we don't want, just in case someone is playing if(!preg_match('/^[-A-Z0-9\., ]+$/iD', $lang)) continue; // print the lang echo "\n\t<li>" . htmlspecialchars($lang) . "</li>"; } echo "\n</ul>"; } else { echo "\n<p>No items selected</p>"; } it prints a list a of array like english spanish but i need to store each one in one variable so i can store in a database is there a way? thanks Currently I am adding the concept of "entitlements" to my website. In the past, my "article.php" script would simply look to the URL for which article was being requested and then load it. However now that I am also adding the concept of "premium content" for "paid members", I need a way to control who sees what. What I am wondering is - from a security standpoint - how much information I should load into the $_SESSION variable. For instance, right now when a user logs in, I think I just store the "memberID" and "FirstName" and possibly "Username". It would be more efficient when a Member logs in to also retrieve their "Membership Plan" and store that in the $_SESSION variable, so that as they browse my website, each page can simply grab $_SESSION['MembershipPlan'] and run that through a function that I need to build and then determine if the user gets to access said page. However, maybe it would be more secure to have it so when a user lands on page XYZ, I would look at their "memberID" and query the database to get their "MembershipPlan"? Any thoughts on each approach? Again, my main concern is *security*, but I also suppose this plays into "performance".
//multi query $sql= "SELECT option_value FROM settings WHERE option_name = 'email_temp_issue';"; //1 $sql .="SELECT title FROM books WHERE id = '$bookid';"; //2 $sql .="SELECT fullName from students WHERE email = '$username'"; //3 $sql_run = mysqli_multi_query($connection,$sql); if(mysqli_num_rows($sql_run)>0) { foreach ($sql_run as $row) { $email_template = $row['option_value']; //retrieve from query 1 $title = $row['title']; //retrieve from query 2 $name = $row['fullName']; //retrieve from query 3 } } I am trying to store the data from the multi query into each variable, which I am not sure how to do..Anyone can help? :) the same page? Hi, I want to be able to let user type in xml text and it will be parsed and uploaded to db, but it doesn't work, it just keeps redirecting me back to this form below! here is html form: Code: [Select] <html> <body> <form method='post' method='form.php'> <p> <textarea name="pastedXML" rows="10" cols="30"> Please paste your xml file here. </textarea> </p> <p> <input type="submit" value="Convert to SQL" name="textXML" /> </p> </form> </body> </html> Here is script (form.php;I just want to retrieve the contents typed in text area to store to variable...how??) Code: [Select] <?php //get the text in textarea and shred it! if(isset($_POST['textXML'])) print $_POST['pastedXML']; ?> Any help much appreciated! Hi, I want to store files to variable array using glob() like $files[0] = xyz.txt $files[1] = pqr.txt . . . $files[n] = nfile.txt I know how to list files from directory using glob() Code: [Select] <?php foreach (glob("*.txt") as $filename) { echo "$filename size " . filesize($filename) . "\n"; } ?> How can I do that ? Hello, I have a variable called $Price, We are getting it through Mysql Database using While loop. We getting the data from database in ordered by ID. Now then i have requirement to store that data into Low to High form ... Like we are receiving $price lke unordered form .. 50 14 35 25 00 145 52 Here i just want to store it in Low to high form like 00, 14,25,35 ... and so on .. Please suggest me the appropriate code. While($myrow=mysql_fetch_array($result, MYSQL_ASSOC)) { some codes return value $price. // want to store in array } $array($price) // here want to store in Low to high with key value. Well, I am storing some of images on my server, but I have to type in the name myself which gets a bit boring and I may overwrite an old image by accident, so, I was thinking of having mysql auto increment the image names. But will this be suitable for images, or should it be text. Hi,
I am building a website that will contain listings, there will be a categories page which will bring the user to the subcategories for that category then the user can see all listings linked to that subcategory. At the minute I am just linking each page using basic href tags to go to the page name.php and all my pages end up being homepage.com/clickedlink.php.
How do I change my URL's so that if i click on a certain category the url changes to page name.php?category=chosen category?
Thanks
Hi, I want to maintain users who log in a webpage and each time they leave, I want to record the current time, so this sounds silly but do I just set in my db table in a field that tracks a user's last log in with DEFAULT: CURRENT_TIMESTAMP? db structu user_id lastActivity lastSession (stores TIMESTAMP of last time user logged in) Any help much appreciated how do i get a drop down value and store it in a another table as of now i am getting the value from one table showing it on drop down now once that is selected i need to insert it into another table. <html> <?php mysql_connect('localhost','root','') or die('Could not connect to mysql ' . mysql_error()); mysql_select_db("dbtest") or die(mysql_error()); if(isset($_POST['submit'])) { //$name=$_POST['val']; $id = $_POST['select']; $id=$row['name']; ?> <input type="text" name="name2" value="<?php echo $row['name'] ?>"><br /> <?php $query = "INSERT INTO sub (`sub`) values('" . $id . "')"; $result = mysql_query($query); if($query) { echo "query executed"; } } ?> <form id="name" action="<?php $_POST['SERVER_SELF'] ?>" method="POST" > <input type="text" name="name1"><br /> <select name="select" id="select"> <?php $query = "SELECT name,id FROM main"; $result = mysql_query($query); if($query) { while($row = mysql_fetch_array($result)) { $options .= '<option value="' . $row['name'] . '">' . $row['name'] . '</option>'; // $out .= "<option value=\" . $row['name'] . \" >' . $row['name'] . '</option>"; } } echo $options; ?> </select> <input type="submit" name="submit1"> </form> </html> Thanks the above seem to work. Hi, I am writing a advertisement system, where i have two fields Ad_Start_date Ad_End_Date i was always confused, in doing this things regarding date whether to use datetime or timestamp in mysql Thanks, Hey Guys, Im currently working on this sport management system where managers can control their team. At the moment im trying to add a feature where if a player is injured on your team, the manager can click an 'injury' button and say how long he will be injured for. Although, what i would like to do with this feature is when it's stored into the database i want to make it so that when his injury time runs out he will become available again (not injured). How would i go about doing this feature? Cheers Browny I want to store... - questionID - questionNo - questionText ...in one array? How do I do that?! Debbie hey der.... m a newbie to php and i dont know if this is the right place for this post. i have a php code and i would like it to be displayed on the browser as well as store it in mysql server in i proper format.... i tried to work with cookies but got the data displayed in array format please help me store it and display it separately i.e., name="XXXX" age="YY".........and so on the code i used in cookies is as follows <?php setcookie("name", $_POST["name"], time()+3600, "/","", 0); setcookie("age", $_POST["age"], time()+3600, "/", "", 0); ?> when i retrieve the cookie data by <?php print_r($_COOKIE)?> i get the output as: Array ( [name] => mohit [age] => 22 ) last but not the least to put the value of the cookie in mysql any help appreciated.... thnx Hi, I am trying to store the view rate of articles so that I can retrieve them later on by "the most popular". I have searched around but cannot find a straight answer. Can anyone point me towards the right direction? Edit: Never mind, I was over complicating the logic behind this. Every now and then, I experience some strange behavior and eventually trace it back to parse_ini_file's scanner_mode being applicable to some parameter but not another, and am looking for alternatives. Below are several of my thoughts. How do you store configuration settings? Do you use different approaches based on the application, and if so what criteria governs which you use? Keep with a ini file with parse_ini_file. Obviously, not working for me. An ini file but with a class dedicated to ensuring the data is appropriate. Seems like too much duplicating content which will result in errors. YAML. Don't think I want to. XML. Not as readable. In a database. Maybe, but might be harder to manage. Hardcode an array in PHP. Probably not. JSON. I like the idea, but feel comments are important in a config file, and am considering the following: Add extra valid JSON properties which contain comments. Don't like the idea. Use JavaScript's JSON.stringify. Too much mixing technologies. Add comments to the JSON and then strip them using a 3rd party parser such as https://json5.org/ or a little regex. My main issue is inability to auto-format, but this seems viable. Any other ideas?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. |