PHP - Php Form Results Don't Make It To Inbox
Hello,
<?php Similar TutorialsHello everyone, When someone starts an OC (Organised Crime) On my game, they invite 3 people. I was just testing it and found that everything is fine up until 1 point, the actual Inbox mail that the invited user gets. I can't click Accept or Reject? Here's the bit of code i have... Code: [Select] if (strip_tags($_POST['inv']) == "inv_we"){ $inv_username=strip_tags($_POST['inv_username']); $check = mysql_num_rows(mysql_query("SELECT * FROM users WHERE username='$inv_username'")); if ($check == "0"){ echo "No such user."; }elseif ($check != "0"){ if ($oc->we != "0"){ echo "You need to kick the Weapons expert before you invite someone else."; }elseif ($oc->we == "0"){ $invite_text=" <div align=center>You have been invited to join $username's Organised crime as the Weapons Expert, please choose one of the following options:<br> <input name=Decline type=submit id=Decline class=button value=Decline> | <input name=inv_button type=submit class=button id=inv_button value=Accept> </div><input type=hidden name=place value=we><input type=hidden name=oc_id value=$oc->id> "; mysql_query("INSERT INTO `inbox` ( `id` , `to` , `from` , `message` , `date` , `read` ) VALUES ( '', '$inv_username', '$inv_username', '$invite_text', '$date', '0' )"); echo "Weapons expert invited"; mysql_query("UPDATE oc SET we_inv='$inv_username' WHERE id='$oc->id'"); So far with my inbox I got it to grab the message and display them in order by most recently sent. but now I want to add multiple inbox pages and set a limit on how many messages are on each page. I cant think of the idea behind of doing it. If someone could kindly guide me please. I know i need to use tokens in the link for each page but i dont understand the concept behind having newest messages to oldest showing up on each page Code: [Select] <?php $take3 = "SELECT time_offset FROM users WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'"; $take2 = mysql_query($take3) or die(mysql_error()); $take1 = mysql_fetch_array($take2); $result = mysql_query("SELECT * FROM pm WHERE id = '".($_SESSION['user_id'])."' ORDER BY time DESC"); // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { $pm_id = $row['pm_id']; $msggoauld = $row['sentfrom']; $subject = $row['subject']; $recieved = $row['time']; $time = ($recieved + $take1['time_offset']); date_default_timezone_set('UTC'); $offset = date('m/d/Y/H:i:s', $time); ?> <tr> <td><center><input type="checkbox" name="messageid" class="select-all-box" value="327990" ?></center></td> </label></td> <td><center><a href="search_goaulds.php?goauld=<?php echo $msggoauld; ?>"><?php echo $msggoauld ?></a></center></td> <td><center><a href="view.php?pm_id=<?php echo $pm_id; ?>"><?php echo $subject ?></a></center></td> <td><center><?php echo $offset ?></center></td> </tr> <?php } // while loop ?> </table> <p> </p> </center> </p> </form> Okay so i'm making an inbox system with jQuery but i can't get it to work, basically i want the user to click on a link and jQuery will send get data to read.php, i will post both of the pages of code! Thanks All! Inbox Page. Code: [Select] <?php session_start(); ?> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> <script type='text/javascript'> function doVar() { $.get('read.php', {messageid: $('#in').val()}, function(output){ $('#read').html(output).slideToggle(500); } ); } </script> <div id="inbox_wrap"> <?php $_SESSION['username'] = "Jamie@jaynet.home"; $user = $_SESSION['username']; require("connect.php"); //$id = mysql_query("SELECT id FROM mail WHERE to_name = '$user' ORDER BY id DESC") or die (mysql_error()); $inbox = mysql_query("SELECT * FROM mail WHERE to_name = '$user' ORDER BY id DESC") or die (mysql_error()); $num_msg = mysql_num_rows($inbox); if($num_msg==0) {echo "You have no messages";} for($count = 1; $count <= $num_msg; $count++) { $row = mysql_fetch_array($inbox); $idi = $row['id']; $read = $row['read_yn']; $from = $row['from_name']; $input = "<a href='#' id='in' onClick='doVar();' />";//need to send a value or something have tried <input type='text' value='$idi' /> doesn't work echo $input; if($read==0) echo "New!"; } ?> </div> <div id='read'></div> Read Page. <?php session_start(); $_SESSION['username'] = "Jamie@jaynet.home"; $user = $_SESSION['username']; $messageid = $_GET['messageid']; require("connect.php"); mysql_query("UPDATE mail SET read_yn='1' WHERE id='$messageid'")or die(mysql_error()); $gm = mysql_query("SELECT * FROM mail WHERE id = '$messageid' AND to_name = '$user'") or die(mysql_error()); $gmr = mysql_fetch_assoc($gm); $to = $gmr['to_name']; $from = $gmr['from_name']; $message = $gmr['message']; $read = $gmr['read_yn']; echo "To: ".$to."<br />"."From: ".$from."<br />"."Message: <br />".$message; mysql_close(); if($_POST['delete']) { require("connect.php"); mysql_query("DELETE FROM mail WHERE id = '$messageid'")or die(mysql_error()); mysql_close(); echo "<meta http-equiv='refresh' content='0;url=index.php?page=inbox'"; } ?> <form method='POST'> <input type='submit' name='delete' value='Delete' /> </form> If I have a db with these fields: displayname, title and I run a successful query on the db, will this code: if (mysql_num_rows($results) == 0) { return "!fail"; } else { while ($row = mysql_fetch_assoc($results)) { extract($row); } return $row; } create an associative array of $var = array(array('displayname' => value, 'title' => value), array('displayname' => value, 'title' => value)...) If not, is there a way to do so, especially when I will not know the names or number of fields in a db table? im new to php <?php $to="myemail@yahoo.com"; $subject="Testing Purposes"; $message="This is my message"; $headers="From: samle@yahoo.com"; mail($to,$subject,$message,$headers); ?> this one goes to the bulk!!! what i want i to send i to inbox any ide thanks in advance Hi, I have a regular MySQL query that displays it's results to the screen in a browser as an HTML table, all nice and fruity. The managers who use this function like to send out the results to staff, currently they simply take a screen shot and paste it into an email to send out to everyone - quite an overhead on the email system, company network, not to mention the time taken to do the screen shot and paste it into an email in the first place. It would be good if I could include a standard HTML form button (preferably) or link on the results page to shove the displayed results to Outlook as an email, that contains the table all ready for the manager to add in what ever they want to the email and then send (usually to 'all@mysite.com' but it would be useful if they could change or add to this as they see fit). This is kind of what happens with a normal mailto HTML tag, except I want it to contain the MySQL query result too. This is the existing table output routine (something I inherited): Code: [Select] /* Output data into a HTMl table */ echo "<p>"; echo "<table align=center width=800 border=\"1\">"; echo "<tr>"; echo "<td BGCOLOR=\"#ffcc00\"><strong>Agent name</strong></td> <td BGCOLOR=\"#ffcc00\"><strong>Number of calls made / handled</strong></td> <td BGCOLOR=\"#ffcc00\"><strong>Average call minutes</strong></td> <td BGCOLOR=\"#ffcc00\"><strong>Total mins (inc hours + secs rounded)</strong></td> </tr>"; while($row = mysql_fetch_row($numresults)) { echo "<tr>"; for($i=0; $i < mysql_num_fields($numresults); $i++) { echo "<td align=center width=443>$row[$i]</td>"; } echo "</tr>\n"; } echo "</table></p>"; Hi, I have search form which works apart from 1 part, I have set the results limit to 10 per page with a next link if there are more than 10 results, however when the next link is clicked, i get the error 'you do not have a search parameter' which comes from this code: Code: [Select] if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } The next link is defined by the code below: Code: [Select] // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>"; } Can anyone see where I have gone wrong with this code without me sending the whole search form? Any help would be very much appreciated. Thanks I have a simple form which sends results (using php) to my email. It works fine. I want to make a similar form, and send the results not to email but to another web page, showing a summary of the form results, so user can check if all is entered correctly before continuing. Can anyone advise if this is possible and how. I am a real php beginner ... EDIT: sorry - new to posting guidelines - using XAMPP with mysql 5.1.44 (I think this is correct!!) Newbie question he I have successfully created a form that that displays students (based on a selected lesson/group/date) with the ability to enter scores. I'm now trying to set the form up so that if data already exists then it is displayed in the form. Eg: if a member of staff choses group 7AS, lesson 1, 24/09/2010 and another member of staff has entered a score already for one student it shows up in the <select> drop down by using Code: [Select] <option>" . $scorevalue . "</option> I had this working at one point but have made a change somewhere and cannot get it working again! can anyone spot an obvious mistake I am making? The code I am using is as follows: Code: [Select] <input type="hidden" name="tutor" value="<?php echo $_GET["tutor"]; ?>" /> <input type="hidden" name="date" value="<?php echo $_GET["date"]; ?>" /> <input type="hidden" name="lesson" value="<?php echo $_GET["lesson"]; ?>" /> <?php error_reporting(-1); $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("lakeside", $con); $result = mysql_query("SELECT students.admin, students.fname, students.surname, students.tutor FROM students WHERE tutor='$_GET[tutor]' ORDER BY students.tutor, students.surname"); echo "<table class='scores'> <tr> <th>Admin</th> <th>Firstname</th> <th>Surname</th> <th>Tutor</th> <th>Score</th> <th>Code</th> <th>Comment</th> </tr>"; while($row = mysql_fetch_array($result)) { $sqlstatement = "SELECT * FROM scores where admin = '" . $row['admin'] . "' and lesson = '" . $_GET[lesson] . "' and date = '" . $_GET[date] . "' "; $scorevalue = mysql_query($sqlstatement); echo " . $score . "; while($rowvalue = mysql_fetch_array($scorevalue)) { $score = $rowvalue['score']; $comment = $rowvalue['comment']; $code = $rowvalue['code']; } echo "<tr>"; echo "<td>" . $row['admin'] . "</td>"; echo "<td>" . $row['fname'] . "</td>"; echo "<td>" . $row['surname'] . "</td>"; echo "<td>" . $row['tutor'] . "</td>"; echo "<td><select name='score" . $row['admin'] . "' value='{$row['score']}' /> <option>" . $scorevalue . "</option> <option>0</option> <option>1</option> <option>2</option> <option>2.5</option> <option >3</option> <option>3.5</option> <option>4</option> </select> </td>"; Hi, I'm currently learning PHP through tutorials and I am working on a webpage that filters statistics (crime records) from an SQL table and filters them by an option of years that the user has picked from a dropdown box. $desiredyear = $_POST['year'] is the year picked from the drop down box on a different page. I did not encounter any problems simply displaying the entire table until I tried to filter the crimes by year. I keep getting this error message. Warning: sqlsrv_fetch_array() expects parameter 1 to be resource, boolean given in C:\RDEUsers\NET\400792\1.php on line 40 Here is the error line. Code: [Select] while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) And here is my code so far Code: [Select] <?php $server = 'SQL2008'; $connectionInfo = array( "Database"=>"rde_400792"); $conn = sqlsrv_connect($server,$connectionInfo); $desiredyear = $_POST['year']; $describeQuery='select year, force, homicide from crime where year = $desiredyear '; $results = sqlsrv_query($conn, $describeQuery); echo '<table border="1" BORDERCOLOR=Black>'; echo '<tr><th bgcolor = "LightBlue">Year</th><th bgcolor = "LightBlue" >Force</th><th bgcolor = "LightBlue">Homicide</th></tr>'; while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) { echo '<tr>'; echo '<td >' .$row['year'].'</td>'; echo '<td>' .$row['force'].'</td>'; echo '<td>' .$row['homicide'].'</td>'; echo '</tr>'; } echo '</table>'; sqlsrv_close($conn); Please can somebody help me fix this? It's driving me mad and I've exhausted my limited knowledge on the subject. I just don't understand what I'm doing wrong. I know the php is basic and not completed yet, but I am working on that. My next step I want the result to show on index.php when a form is submitted to calculator2.php. I just cant seem to get it. Please help! index.php Code: [Select] <div class="post"> <h2 class="title">Calculator</h2> <hr /> <form method="post" action="calculator2.php"> Fireplace Front Width: <input type="text" name="fw"> <br /> Fireplace Back Width: <input type="text" name="bw"> <br /> Fireplace Depth: <input type="text" name="fd"> <br /> <input type="submit" name="Submit" value="Submit"> </form> Pounds Of Glass Needed: <?php echo $res1; ?> </div> calculator2.php Code: [Select] <?php $frontwidth = $_POST['fw']; $backwidth = $_POST['bw']; $firedepth = $_POST['fd']; $x = $frontwidth + $backwidth+ $firedepth; $y = ($x / 3) * .6667; $res1 = $y *2; echo $res1; ?> Hi Guys. I have some code which displays the rows of a database table in a html table on my webpage: Code: [Select] <?php//to display image from source$dir = "360_covers";echo '<table>';echo '<tr><th>Title</th><th>Cover</th><th>comment</th></tr>';$result = mysql_query("SELECT * FROM xbox_games order by gametitle");while ($row = mysql_fetch_assoc($result)) { echo "<tr><td>{$row['gametitle']}</td><td><img src=\"$dir/{$row['cover']}\" width='38' height='38'></td><td>{$row['cover']}</td></tr>";}//close out tableecho '</table>';?> What i want to do now is add a form, possibly at the end of each row of the html table, which will allow a session user to update that record. Can anybody advise on the best way to do this? Sounds a bit long winded in the name so i'll explain... I'm coding a site where the user inputs their vehicle reg, and submits the form. The site will then show their car's details. This is being done using an external service that provides an up to date database of vehicle details. So far, i've got the form and when you submit it, it returns the vehicle data in an XML, but the XML it displays is remote. I need to retrieve the details back to the website to display on the page. Here is what I have already: Code: [Select] <html> <head> <title>Reg Test Page</title> </head> <body> <form method="post" action="https://www.****.com/UAT/"> <input type="hidden" name="ESERIES_FORM_ID" value="B2INT"> <input type="hidden" name="MXIN_USERNAME" value="****"><br /> <input type="hidden" name="MXIN_PASSWORD" value="****"><br/> REG<input type="text" name="MXIN_VRM" value="REG NUM"><br /> <input type="hidden" name="MXIN_TRANSACTIONTYPE" value="03"><br /> <input type="hidden" name="MXIN_PAYMENTCOLLECTIONTYPE" value="02"><br /> <input type="hidden" name="MXIN_CAPCODE" value="1"><br /> <input type="submit" /> </form> </body> </html> I've ***'d out some details for obvious reason. The form currently works fine and returns a valid XML response, but it's remote. My original plan was to get the form to load up in another php file that processes the detail and sends a file_get_contents() request, but looking at the results page on the xml, there is no extension to the posted url and if you go directly to it, you get the error "METHOD NOT ALLOWED. ONLY 'POST' IS ALLOWED." The other issue I have is that i'm not sure how it's handling the request, and the url is not modified, so i'm not sure how i'd set an url with values to retrieve it? Any help is gratefully received. Cheers Guys. This sounds like overkill, but is there any way I can take the results of an html form, and plug them into their respective cells on a excel spreadsheet? Thanks in advance! -Brad I am looking for a high-level (but detailed) conceptual technique on making dynamic selection via a web page, where selection options are stored for later use in a database.
Scenario: I have various options for assembling a custom-made product. I can select demands that the product must satisfy via a form, and submit my selection to the server.
It then runs an algorithm to match my selections to the possible products that can be built to satisfy the demands. There can be anywhere from 0 (not possible to build product), to 1 to 200 various ways to build possible products that match my selection. I will call original user selection as "original selection" and the 200+ options as "options".
Right now there is an existing system in place which is a hideous mess of JSON, JS, HTML, and PHP. Maybe the technologies are the way to solve my problem, but the way it is solved now is hard to maintain. I don't know if there is a better way. Right now, all options are being pre-generated via PHP, and are encoded into JSON, then JSON is read by JS, which drives the dynamic selection of options. Then when an option is saved, entire list of options is saved along with it... Then, when we want to know which original selection was made, we read back all the options from the database and the index of the one we actually need. They are in JSON, we decode that, and then we have what we went. It sounds convoluted to me, and I would like to simplify it a lot, potentially rewriting it. How?
Basically I want this end-user scenario:
1. User makes selections via form, submit
2. User is presented with all options. Since there are a lot of options we want user to be able to navigate through them in real time. JS may be of value here, rather than doing new page loads, including AJAX page loads.
3. User saves their selection, and results from page are either displayed back to the user or are saved in DB.
I have a Login page which i want to check if the user details (username, password and activation) are valid then redirect user dependent on his/her "accessLevel" (admin, member and none)
Admin will be directed to "index.php"
Member will be directed to "tasks.php"
and none will be redirected to "notActive.php"
here is my current code which half works;
<?php include ('connect.php'); if(isset($_POST['submit'])) { // Initialize a session: session_start(); // Define $username and $password $username=$_POST['username']; $password=$_POST['password']; // To protect MySQL injection $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $sql="SELECT * FROM ecmt_members WHERE username='$username' and password='$password' AND Activation IS NULL"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $username and $password, table row must be 1 row if($count==1){ // Register $username, $password and redirect to file "index.php" $role = mysql_fetch_array($result); $_SESSION['username']= $username; $_SESSION['password']= $password; //$_SESSION['role']= $role['accessLevel']; if($role['accessLevel'] == "admin"){ $_SESSION['adminuser']=$role['accessLevel']; header("location:index.php"); exit(); } elseif($role['accessLevel'] == "member"){ $_SESSION['user']=$role['accessLevel']; header("location:tasks.php"); exit(); } else { echo "Error: Username, Password or Access Level incorrect! Go Home, you're Drunk!!!"; } } } // End of the main Submit conditional. ?><!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Login Form</title> <!-- jQUERY --> <script src="//code.jquery.com/jquery-latest.js"></script> <!-- Add Main CSS --> <link rel="stylesheet" type="text/css" href="../tool/css/main.css"> <!-- Font-Awesome --> <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"> <style> body { background: url(../tool/images/bg1.jpg) no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; } .exactCenter { width:auto; height:auto; position: fixed; top: 50%; left: 50%; margin-top: -200px; ; } </style> </head> <body> <div class="exactCenter"> <div id="login-container"> <img src="../tool/images/bigLogo.png" /><br /> <form action="login.php" method="post" class="form"> <fieldset class="group"> <input class="input" type="text" id="username" name="username" size="25" placeholder="username"/> <img src="../tool/images/spacer.png" width="5" height="5" /> <input class="input" type="password" id="password" name="password" size="25" placeholder="password"/> <img src="../tool/images/spacer.png" width="5" height="5" /> </fieldset> <input type="hidden" name="formsubmitted" value="TRUE" /> <button type="submit" name="submit" class="btn btn-blue" ><i class="fa fa-unlock-alt"></i> Login</button> <img src="../tool/images/spacer.png" width="5" height="5" /> <a href="Register.php"><button type="button" class="btn btn-green" ><i class="fa fa-hand-o-up"></i> Register</button></a> </form> </div></div> </body> </html>When i test it with admin login credentials i get the page refresh again without error, when i login with member credentials it shows tasks.php and when i try to log in with unactivated account "acivation column is not NULL" i get a page refresh also with no error. Can someone help me make it work for each role and perhaps have some sort of error reporting depending on error. im pulling my hair out here and this is the first time i have worked with login conditions, and im VERY confused. Edited by jacko_162, 28 October 2014 - 05:12 PM. When I click on the letter of the alphabet on my form page, it will bring up the results of my query. I got this part working. The next part is to be able to click on any of the populated results and have it autofill my form with organization, first name, last name, email address and phone number.
I know that I need to use Ajax and jQuery to accomplish this.
Here is my html
<!-- Letter Search --> <div class="searchBox span12"> <h3>Choose the First Letter of the Person's Last Name</h3> <ul> <li class="alphabets" id="A"><a href="?by=A">A</a></li> <li class="alphabets" id="B"><a href="?by=B">B</a></li> <li class="alphabets" id="C"><a href="?by=C">C</a></li> <li class="alphabets" id="D"><a href="?by=D">D</a></li> <li class="alphabets" id="E"><a href="?by=E">E</a></li> <li class="alphabets" id="F"><a href="?by=F">F</a></li> <li class="alphabets" id="G"><a href="?by=G">G</a></li> <li class="alphabets" id="H"><a href="?by=H">H</a></li> <li class="alphabets" id="I"><a href="?by=I">I</a></li> <li class="alphabets" id="J"><a href="?by=J">J</a></li> <li class="alphabets" id="K"><a href="?by=K">K</a></li> <li class="alphabets" id="L"><a href="?by=L">L</a></li> <li class="alphabets" id="M"><a href="?by=M">M</a></li> <li class="alphabets" id="N"><a href="?by=N">N</a></li> <li class="alphabets" id="O"><a href="?by=O">O</a></li> <li class="alphabets" id="P"><a href="?by=P">P</a></li> <li class="alphabets" id="Q"><a href="?by=Q">Q</a></li> <li class="alphabets" id="R"><a href="?by=R">R</a></li> <li class="alphabets" id="S"><a href="?by=S">S</a></li> <li class="alphabets" id="T"><a href="?by=T">T</a></li> <li class="alphabets" id="U"><a href="?by=U">U</a></li> <li class="alphabets" id="V"><a href="?by=V">V</a></li> <li class="alphabets" id="W"><a href="?by=W">W</a></li> <li class="alphabets" id="X"><a href="?by=X">X</a></li> <li class="alphabets" id="Y"><a href="?by=Y">Y</a></li> <li class="alphabets" id="Z"><a href="?by=Z">Z</a></li> </ul> <? include('search.php'); ?> </div> <hr style="color:#ccc; margin-bottom:20px;" /> <!-- Main Form --> <div id="mainForm"> <form method="post" id="icsForm" class="searchBox span12"> <div id="col1" class"span6"> <h3>Contact Information</h3> <label>Church / Organization:</label><input type="text" name="organization" id="organization" class="span6 upright" /><br /> <label>First Name:</label><input type="text" name="firstName" id="firstName" class="span6 upright" /> <label>Last Name:</label><input type="text" name="lastName" id="lastName" class="span6 left upright" /> <label>Email Address:</label><input type="text" name="email" id="email" class="span6 left upright" /> <label>Phone Number:</label><input type="text" name="phone" id="phone" class="span6 left upright" /> </div> </div>Here is my php if(preg_match("/^[A-Z | a-z]+/", $_POST['name'])){ $name=$_POST['name']; } if(isset($_GET['by'])){ $letter=$_GET['by']; //query to sort by last name $sql="SELECT contact_id, first_name, last_name, church_org, email_address, phone_number FROM ics_data WHERE last_name LIKE '$letter%' ORDER BY last_name ASC"; //run the query against the mysql query function $result=mysql_query($sql); //count results $numrows=mysql_num_rows($result); echo "<p>" .$numrows . " results found for " . $letter . "</p>"; //Create while loop and loop through result set while($row=mysql_fetch_array($result)){ $first_name=$row['first_name']; $last_name=$row['last_name']; $church_org=$row['church_org']; $email_address=$row['email_address']; $phone_number=$row['phone_number']; $contact_id=$row['contact_id']; //display the result of the array echo "<div id=\"search-results\">"; echo "<ul class=\"letter-results\">\n"; echo "<li class=\"result-row\">" . "<a href=\"#\" class=\"testclass\">" .$first_name . " " .$last_name . "". ", " ."" .$church_org ."</a></li>\n"; echo "</ul>"; echo "</div>"; } }Here is my Javascript file (Ajax) $(document).ready( function() { function formfill() { var organization = $('#organization').val(); var firstname = $('#firstname').val(); var lastname = $('#lastname').val(); var email = $('#email').val(); var phone = $('#phone').val(); $.ajax ({ method: "GET", url: "search.php", dataType: 'json', data: { organization:organization, firstname:firstname, lastname:lastname, email:email, phone:phone }, type: "POST", success: function(data) { $organization $firstname $lastname $email $phone }, failu function() { alert('fail!'); } }); }I know that I do not have a reference yet to JSON in my php file and that it is needed. I'm not solid on the Ajax part. That is the part that is tripping me up. I know that I need to make the form autofill when clicking on a specific result returned from my query... but i'm not sure how to do that. Thank you in advance for any help or advice you can give!! I am relatively new to programming. Hopefully I posted this in the right forum as a lot of these technologies overlap. Edited by kjetterman, 26 September 2014 - 10:23 AM. Hello: Did my first post last week and am new to PHP. Making the jump from Classic ASP into PHP. I got some good advice last time. I have a feedback form I have been using, and it works fine for sending results to the website owner. How can I add to it so it will first add all the data to mySQL database, and then email the results to the site owner? Also, I hear about SQL injection attacks a lot - is my current code safe from that? This is what I have: contact.php Code: [Select] ... <form method="post" name="myform" action="sendmail.php"> Full Name: <input type="text" name="FullName" /> Address: <input type="text" name="Address" /> City: <input type="text" name="City" /> State: <input type="text" name="State" /> Zip: <input type="text" name="Zip" /> Phone: <input type="text" name="Phone" /> Email: <input type="text" name="Email" /> Website: <input type="text" name="Website" /> Comments: <textarea cols="43" rows="6" name="Comments"></textarea> <input type="submit" /><br /> </form> ... sendmail.php Code: [Select] <?php $FullName = $_REQUEST['FullName'] ; $Address = $_REQUEST['Address'] ; $City = $_REQUEST['City'] ; $State = $_REQUEST['State'] ; $Zip = $_REQUEST['Zip'] ; $Phone = $_REQUEST['Phone'] ; $Email = $_REQUEST['Email'] ; $Website = $_REQUEST['Website'] ; $Comments = $_REQUEST['Comments'] ; mail( "info@website.com", "Contact Request", "Full Name: $FullName\nAddress: $Address\n City: $City\n State: $State\n Zip: $Zip\n Phone: $Phone\n Email: $Email\n Website: $Website\n Comments: $Comments\n", "From: $Email" ); header( "Location: http://www.website.com/thanks.php" ); ?> Any help or coding examples would be most appreciated! Thanks! I'm very new to this and really could use some help. I've got a Web app that has one form that collects data from the user and puts it into a mysql database and has another form that allows the user to select critiera to find records in the database and display them on the page. All this is working just fine, but now that my database is getting more data in it, I want to add functionality to display 10 records on a page with results page navigation links so the user can move forward and backward in the results set. This part is not working and I've put in echo statements to figure out what the code is doing. The problem I'm having is that when the selection critiera pulls more than 10 records from the database, the first page of results is correct per the selection criteria entered by the user on the select form. When the 'next' link is selected to review the second page of results, the query is executed again. But this time the form variables have been reset and the results now contains the entire contents of the db. The start record is set to look at the 11th instance of the results set, so the second page starts with the 11th record in the database instead of the 11th record in the original results set. The original select statement is built by determining which criteria is selected using $_POST against each form variable. How can I retain the form variables or the original select statement so the second execution of the select statement results in the same results set as the first? The other option that may be better is to retain the original results set and avoid re-executing the select statement altogether. But I don't know how to do that either. Any suggestions, code samples or adivice is much appreciated! Hi all, I am new to PHP and am trying to implement a window that opens when a user is trying to validate an organisation on our site. I have an initial page where users can enter data. One of the fields is organisations. This has a button to its right that lets the user search existing organisations in the mysql db. I have the search piece thanks to some code I found and altered. However, instead of a static non-linked list 1,2,3 coming back from the search, I need the search results to be links / or at least "select"-able. When the user chooses the organisation they were referring to that exists in the db I would like the selection to go back to the original php page and populate the organisation field. Ideally without having other data in the original form being lost. Any tips, hints or links would be greatly appreciated. Here is my code: <?php $dbHost = 'localhost'; $dbUser = 'root'; $dbPass = 'mypass'; $dbDatabase = 'mydb'; $con = mysql_connect($dbHost, $dbUser, $dbPass) or trigger_error("Failed to connect to MySQL Server. Error: " . mysql_error()); mysql_select_db($dbDatabase) or trigger_error("Failed to connect to database {$dbDatabase}. Error: " . mysql_error()); // Set up our error check and result check array $error = array(); $results = array(); // First check if a form was submitted. // Since this is a search we will use $_GET if (isset($_GET['search'])) { $searchTerms = trim($_GET['search']); $searchTerms = strip_tags($searchTerms); // remove any html/javascript. if (strlen($searchTerms) < 3) { $error[] = "Search terms must be longer than 3 characters."; }else { $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. } // If there are no errors, lets get the search going. if (count($error) < 1) { $searchSQL = "SELECT Organisation_Name FROM vcaccount_contact_organisation WHERE "; // grab the search types. $types = array(); $types[] = isset($_GET['Organisation_Name'])?"`Organisation_Name` LIKE '%{$searchTermDB}%'":''; $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked) if (count($types) < 1) $types[] = "`Organisation_Name` LIKE '%{$searchTermDB}%'"; // use the body as a default search if none are checked $andOr = isset($_GET['matchall'])?'AND':'OR'; $searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `Organisation_Name`"; // order by organisation. $searchResult = mysql_query($searchSQL) or trigger_error("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); if (mysql_num_rows($searchResult) < 1) { $error[] = "The search term provided {$searchTerms} yielded no results."; }else { $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$i}: {$row['Organisation_Name']}<br /><br />"; $i++; } } } } function removeEmpty($var) { return (!empty($var)); } ?> <html> <title>My Simple Search Form</title> <style type="text/css"> #error { color: red; } </style> <body> <?php echo (count($error) > 0)?"The following had errors:<br /><span id=\"error\">" . implode("<br />", $error) . "</span><br /><br />":""; ?> <form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>" name="searchForm"> Organisation: <input type="text" name="search" value="<?php echo isset($searchTerms)?htmlspecialchars($searchTerms):''; ?>" /><br /> <input type="submit" name="submit" value="Search!" /> </form> <?php echo (count($results) > 0)?"Your search term: {$searchTerms} returned:<br /><br />" . implode("", $results):""; ?> </body> </html> |