PHP - How To Retrieve Text Area Content To Store To Variable
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! Similar TutorialsHello all. I'm new here... and new to php... so please be gentle if I'm overlooking something that's blindingly obvious. I have a 'view blog entries' page and an 'edit blog entries' page. When I go to the 'edit blog entries' page, I want the form fields to display the preexisting blog content for whatever entry I'm about to edit. The code below does display the 'title' but it does not display the 'article' content. (However, the 'title' and 'article' content both show when I view the source code.) Can anyone tell me what I could be doing wrong? Thanks in advance. Code: [Select] // Retrieve the blog post's information: $q = "SELECT title, article FROM entries WHERE article_id=$article_id"; $r = @mysqli_query ($dbc, $q); if (mysqli_num_rows($r) == 1) { // Valid blog entry ID, show the form. // Get the blog entry's information: $row = mysqli_fetch_array ($r, MYSQLI_NUM); echo '<form action="edit_entry.php" method="post"> <p>Title:<br /> <input type="text" name="title" size="45" maxlength="80" value="' . $row[0] . '" /></p> <p>Blog entry<br /> <textarea name="article" id="article" cols="45" rows="5" ' . $row[1] . '></textarea> </p> <p><input type="submit" name="submit" value="Submit" /></p> <input type="hidden" name="submitted" value="TRUE" /> <input type="hidden" name="article_id" value="' . $article_id . '" /> </form>'; } else { // Not a valid entry ID. echo '<p class="error">This page has been accessed in error.</p>'; } mysqli_close($dbc); ?> Hello guys, I am a new programmer and i am building a new website. I would like to give me your advice for the following problem: I want to build a webpage, in which there will be a <div id="book-content"> ...............</div> part. Inside this div i would like to dynamically display pages from a book. Each page will have text, scripting code blocks, blocks with the output of each scripting code, and images. There will be a bar on the left of the webpage in which the user can select which page of the book he wants to load. For example...My web page will look something like this... Code: [Select] <HTML> <HEAD> </HEAD> <BODY> <DIV ID="PAGE-HEADER"> //LOGO OF THE WEB PAGE </DIV> <DIV ID="PAGE-MENU"> //PAGE MENU </DIV> <DIV ID="BOOK-INDEX" WITH FLOAT:LEFT > //HERE A WILL SHOW THE CHAPTERS OF THE BOOK AND THE PAGES OF EACH CHAPTER </DIV> <DIV ID="BOOK-PAGE"> //THE PAGE SELECTED FROM THE PREVIOUS 'BOOK-INDEX' MENU WILL BE DISPLAYED HERE WITH A MYSQL QUERY ****** </DIV> </BODY> </HTML> Then in a mysql database, i would like to have records with a text field, that will contain for example the followng: <h1> Chapter 1: bla bla </h1> <p> in this chapter we will speak about bla bla bla.... </p> <div id="code"> int main() { int x,y; x=2; y=3; x=x+y; } </div> <p> this will outpout the following:</p> <div id="code output"> x=5! </div> I would like to get this html code from the database, and then show it in the <div id=BOOK-PAGE> div. But i dont want to use php eval(). Also, if i store the code to a file and then include it, i will have too may files(equal to the book's number of pages etc 100). Any ideas? Hello people, I have created an application in Code Charge where my site users can login and play games online.The game code is run via flash and html. The Game has 5 stages and from a page in my application called transfertogame.php , i transfer them to the game page. Now i want to be able to track each players progress via database so that when they log back in and they get to the transfertogame.php page, it can check the page they were on before and immediately take them to the page without starting from page 1. Any help will be appreciated as i am very poor with php scripting This is the session ID i guess is being used from my application page //Initialize Method @4-537EA73F function Initialize() { if(!$this->Visible) return; $this->ds->Parameters["sesUserID"] = CCGetSession("UserID"); } //End Initialize Method //Validate Method @4-7E1FC38C function Validate() { $Validation = true; $Where = ""; $this->CCSEventResult = CCGetEvent($this->CCSEvents, "OnValidate"); return (($this->Errors->Count() == 0) && $Validation); } //End Validate Method Hi there. How do I reflect the text content of the variable $a in this text form: <input type="text" name="artist"> Regards Morris hey i am using a MySql database and i need to create a dynamic HTML table with one of its columns as checkboxes.so i have to create multiple checkboxes.but these checkbox values are to be stored in a mysql table and then later retrieved when form reloads.and depending on previous state when form was submitted, the newly created checkboxes have to be checked in the same manner.so how do i store multiple checkbox values in my table and also how do i retrieve them? please help. Quote 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>"; } } Hi, I am not very good with php but this code was kindly given to me by mdjamato, except I added a variable $markGradeSum to add all the $markGrade. Problem is that I will get notice saying undefined variable $markGradeSum because the $markGradeSum is in the foreach loop which it needs to be in for the right calculation but where I want to output the variable is in the while loop in this line: Code: [Select] $output .= "<br><strong>Course:</strong> {$row['CourseId']} - {$row['CourseName']} <strong>Course Mark</strong> <strong>Grade</strong> <br><strong>Year:</strong> {$row['Year'] $markGradeSum}</p>\n"; Below is whole code: Code: [Select] <?php if($num ==0){ echo "<p>Sorry, No Records were found from this Search</p>";} else{ function outputModule($moduleID, $moduleName, $sessionData) { if(!count($sessionData)) { return false; } $markTotal = 0; $markGrade = 0; $weightSession = 0; $markGradeSum = 0; $grade = ""; $sessionsHTML = ""; $courseHTML = ""; foreach($sessionData as $session) { $sessionsHTML .= "<p><strong>Session:</strong> {$session['SessionId']} <strong>Session Mark:</strong> {$session['Mark']}</strong> <strong>Session Weight Contribution</strong> {$session['SessionWeight']}%</p>\n"; $markTotal += round($session['Mark'] / 100 * $session['SessionWeight']); $weightSession += ($session['SessionWeight']); $markGrade = round($markTotal / $weightSession * 100); $markGradeSum = round($markGrade); if ($markGrade >= 70){ $grade = "A";} else if ($markGrade >= 60 && $markGrade <= 69){ $grade = "B";} else if ($markGrade >= 50 && $markGrade <= 59){ $grade = "C";} else if ($markGrade >= 40 && $markGrade <= 49){ $grade = "D";} else if ($markGrade >= 30 && $markGrade <= 39){ $grade = "E";} else if ($markGrade >= 0 && $markGrade <= 29){ $grade = "F";} } $moduleHTML = "<p><br><strong>Module:</strong> {$moduleID} - {$moduleName} <strong>Module Mark:</strong> {$markTotal} <strong>Mark Percentage:</strong> {$markGrade} <strong>Grade:</strong> {$grade} </p>\n"; return $moduleHTML . $sessionsHTML; } $output = ""; $studentId = false; $courseId = false; $moduleId = false; while ($row = mysql_fetch_array($result)) { if($studentId != $row['StudentUsername']) { //Student has changed $studentId = $row['StudentUsername']; $output .= "<p><strong>Student:</strong> {$row['StudentForename']} {$row['StudentSurname']} ({$row['StudentUsername']})\n"; } if($courseId != $row['CourseId']) { //Course has changed $courseId = $row['CourseId']; $output .= "<br><strong>Course:</strong> {$row['CourseId']} - {$row['CourseName']} <strong>Course Mark</strong> <strong>Grade</strong> <br><strong>Year:</strong> {$row['Year'] $markGradeSum}</p>\n"; } if($moduleId != $row['ModuleId']) { //Module has changed if(isset($sessionsAry)) //Don't run function for first record { //Get output for last module and sessions $output .= outputModule($moduleId, $moduleName, $sessionsAry); } //Reset sessions data array and Set values for new module $sessionsAry = array(); $moduleId = $row['ModuleId']; $moduleName = $row['ModuleName']; } //Add session data to array for current module $sessionsAry[] = array('SessionId'=>$row['SessionId'], 'Mark'=>$row['Mark'], 'SessionWeight'=>$row['SessionWeight']); } //Get output for last module $output .= outputModule($moduleId, $moduleName, $sessionsAry); //Display the output echo $output; } } ?> How can I retrieve the variable so it doesn't come up with the notice but be able to display $markGradeSum to the places I want them in (one in foreach loop for calculation and other in while loop for output). Thank You I have a variable $form in the code below what I cant figure out how do it is call it and get the information it has out so I can display the errors: Code: [Select] function login($subuser, $subpass, $subremember){ global $database, $form; //The database and form object /* Username error checking */ $field = "user"; //Use field name for username if(!$subuser || strlen($subuser = trim($subuser)) == 0){ $form->setError($field, "* Username not entered"); } else{ /* Check if username is not alphanumeric */ if(!preg_match("^([0-9a-z])*$^i", $subuser)){ $form->setError($field, "* Username not alphanumeric"); } } if ($database->usernameBanned($subuser)) { $form->setError($field, "*Your Account has been banned"); } /* Password error checking */ $field = "pass"; //Use field name for password if(!$subpass){ $form->setError($field, "* Password not entered"); } /* Return if form errors exist */ if($form->num_errors > 0){ return false; } /* Checks that username is in database and password is correct */ $subuser = stripslashes($subuser); $result = $database->confirmUserPass($subuser, md5($subpass)); /* Check error codes */ if($result == 1){ $field = "user"; $form->setError($field, "* Username not found"); } else if($result == 2){ $field = "pass"; $form->setError($field, "* Invalid password"); } /* Return if form errors exist */ if($form->num_errors > 0){ return false; } I am presuming that I set a global variable so that I can retrieve it on a different page...My filename is userid; and I will need this in many different pages. I set it thusly: Code: [Select] mysql_select_db($db , $link) or die("Couldn't open $db: ".mysql_error()); $long=$_SERVER['PHP_SELF']; //get path $text = substr(strrchr($long, "/"), 1); //get file name+extension $UserID = trim($text, " .php"); //remove extension, leaving userid Globals["UserID"]; and in a different file try to retrieve it thusly: echo "user is ".$GLOBALS["UserID"]; but all I ever see is "user is"------any help appreciated. 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.... Hello, Please could someone tell me how to retrieve an incremental variable from MYSQL as soon as it is inserted? (i.e. before another variable can be inserted) Many thanks. Stu 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".
I am trying to create a code where the user enters the zip code and if found in the database, a location will be retrieved. I am getting two undefined variables as errors. I am still learning the POST and GET method and I fear that is where I am getting something mixed up. I have also attached an image of my DB. Thank you so much any input is greatly appreciated. Notice: Undefined variable: address in C:\xampp\htdocs\index.php on line 53 Notice: Undefined variable: zip in C:\xampp\htdocs\index.php on line 54
<?php include ('header.php'); include ('function.php'); ?> <div class="wrapper"> <div> <?php echo'<form method="POST" action"'.getLocations($conn).'"> <input type="text" name="zip" class="search" placeholder="Zip code"><br> <button type="submit" value="submit" id="submit">Submit</button> </form>'; getLocations($conn); ?> </div> </div> <div> <!--foreach($zip as $zip) : --> <?php echo $address['address']; echo $zip['zip']; ?> </div> function.php file code: <?php $dBServername = "localhost"; $dBUsername = "root"; $dBPassword = ""; $dBName = "addresses"; // Create connection $conn = mysqli_connect($dBServername, $dBUsername, $dBPassword, $dBName); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } function getLocations($conn) { if (isset($_POST['submit'])){ // Validate Zip code field if (!empty ($_POST['zip']) && is_numeric ($_POST['zip'])) { $zip = (int)$_POST['zip']; $query = "SELECT * FROM locations WHERE zip = '$zip'"; //get the results $result = mysqli_query($conn, $query); //fetch the data $zip = mysqli_fetch_all($result, MYSQLI_ASSOC); var_dump($zip); mysqli_free_result($result); //close connection mysqli_close($conn); } } }
//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? :) I'd like to use a text editor like this one: http://tinymce.moxiecode.com/examples/full.php for my forums. But I am not sure exactly how I would prevent abuse and injects to messed up the page, rather than being contained in the designated area it is meant for. Could some one please help me, I know htmlspecailchars will not work, since some of the code needs to render as html Have page#1 with thumbs view_thumbs.php , when a thumb is clicked thumb link goes to page#2 which is the video_play.php page(which must play embed codes from xml sheet) Using GET method to identify incoming link from page#1. QUESTION is how can i retrieve file(embed code) from xml to play on page#2 with incoming GET info from page#1? (embeds not you only from you tube, so no youtube solutions only, just retrieve file) I somehow have to fill play video div on page#2/video_play.php according to GET data from page#1/view_thumbs.php the same page? I’m trying to construct a button that simply writes an "aleph" character into a text area, see below.
My code does not work, can anyone tell me why ? How should I fix it ?
<!DOCTYPE html> <html> <meta charset="UTF-8"> <head> <title>Example</title> <script type="text/javascript"> //JavaScript code goes here function insertAtEnd(text) { var theArea = document.getElementById("thisArea"); theArea.value += '' + text + '';; } </script> </head> <body> <input type="button" id="aleph" name="aleph" value="Write an aleph" onClick="javascript:insertAtEnd(\'<span>א</span>\');return(false)" /> <textarea id="thisArea"> </textarea> </body> </html> 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 ? |