PHP - Passing Variables To A Function On A Click On Image
Hey guys,
I want to pass the unique id of a node to a function when that image is clicked. Actually i am a newbee in php so don't know what to search about or where to look for it,but find this place and you all guys so helpful so i am asking for a guide here Similar TutorialsI am trying to pass a variable from inside of a function in a file that is included eg include.php Code: [Select] <? function noms(){ $foobar = "apples"; } ?> main.php Code: [Select] <? include("include.php"); noms(); echo "these ". $foobar. " are most delicious... OM NOM NOM"; ?> I am essentially using a include file for a mysql connection and based on the connection outcome i am either setting a value to true or false. It prints "Connected succesfully" and what not just fine, but, after that it wont pass on the variables data. I know its the function because, it passes the data if i put the variable before the function... i just dont get it.. any help would be great. Thanks. Ansel Hi, I'm trying to pass a variable into a URL and apparently I'm doing it wrong this code is OK Code: [Select] $id = $3; echo '<a href="newPage.php?id=3"></a> If I use Code: [Select] $id = $_GET['id']; echo $id; on the newPage.php, I echo 3 whereas, if I do Code: [Select] $id = $3; echo '<a href="newPage.php?id="'.$id.'"></a> when echo out on the newPage.php it prints out nothing also, in current url look like this: Code: [Select] www.site.com/newPage.php?id= What am I doing wrong? Many thanks hai everybody....
1. can any one let me know how to pass a variable from view to controller in CodeIgniter...
2. if possible send me a complete login application...developed by using CodeIgniter....
Thanks & Regards,
Shankaar.
I'm a newbie here and to php and Javascript. So hello all. I am trying to get a portion of a file name passed from one file (first.php) which displays a MySql table. One of the fields is a link that is supposed to open a popup window (second.php) and begin playing a mp3 file with the flash media player. I have everything (almost) working. The table displays as it should, the link is fine. However, I can not get the popup to open with the dimensions I asked for. It opens in a full size new window. And the mp3 will not play. I get the message from the player "we are unable to connect...etc etc". The file name shows up in the status bar and in the URL window. In the file first.php, the table displays, the links appear to be active. when clicked the new window opens, the file names carry over but I can not get the file to play. The player loads (in file second.php) but I get the message from the player "we are unable to connect...etc etc". I suspect it is in the syntax. I have tried so many combinations I can't list them here and so far I have been unable to find anything on google, etc to answer this. After almost three days I have resorted to here. This may not even be the right place for me. Javascript may be my best bet for all I know. Can someone please look over what I have and at least point me in the right direction? Any help is greatly appreciated as this is my first attempt at a website. Thanks first.php Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script language="JavaScript"> <!-- Begin function popUp(URL) { playwindow=window.open(URL, 'name', 'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,width=350,height=250'); } // End --> </script> <script language="JavaScript"> <!-- function openPlayer(URL) { player = window.open('player10.php?','width=350,height=275') } // End --> </script> <?php $username="myusername"; $password="mypassword"; $database="mydb"; mysql_connect('mydb',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM mytable"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> </head> <body> <table border="1" cellspacing="2" cellpadding="2"> <tr> <th><font face="Arial, Helvetica, sans-serif">Listen</font></th> <th><font face="Arial, Helvetica, sans-serif">f2</font></th> <th><font face="Arial, Helvetica, sans-serif">f3</font></th> <th><font face="Arial, Helvetica, sans-serif">f4</font></th> <th><font face="Arial, Helvetica, sans-serif">f5</font></th> <th><font face="Arial, Helvetica, sans-serif">f6</font></th> </tr> <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"listen"); $f2=mysql_result($result,$i,"field2"); $f3=mysql_result($result,$i,"field3"); $f4=mysql_result($result,$i,"field4"); $f5=mysql_result($result,$i,"field5"); $f6=mysql_result($result,$i,"field6"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><a href="javascript:openPlayer('player10.php?<?php echo $f1?>')">Listen</a></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f6; ?></font></td> </tr> <?php $i++; } ?> </body> </html> SECOND.PHP Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" > <meta http-equiv="X-UA-Compatible" content="IE=8" > <title>My Title </title> <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" > <script language="JavaScript" type="text/javascript"> <!-- // // Make sure there's some data // if (location.search) { // // Extract the name of the graphics file // var mp3_filename = location.search.substring(1) // // Write the <IMG> tag using the name of the graphics // file (you may need to adjust the SRC text) // document.write('<a href="http://mywebsite.com/+mp3_filename">') } // End --> </script> </head> <body> <object width="400" height="300"> <param name="movie" value="http://fpdownload.adobe.com/strobe/FlashMediaPlayback.swf"> </param> <param name="flashvars" value="src=http%3A%2F%2Fmywebsite.com%2Faudio%2F+mp3_filename"> </param> <param name="allowFullScreen" value="true"> </param> <param name="allowscriptaccess" value="always"> </param> <embed src="http://fpdownload.adobe.com/strobe/FlashMediaPlayback.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="400" height="300" flashvars="src=http%3A%2F%2Fmywebsite.com%2Faudio%2F+mp3_filename"> </embed> </object> </body> </html> Hello all, So I've picked up a PHP book in an attempt to learn it. The issue I'm having is preventing me from getting any further. They have me creating a simple order form, but the data is not passing from the HTML page to the PHP Processing file. I know there are other ways of doing this that I'm unaware of, but this code is verbatam to what we are isntructed to type within the book itself. Here is the code orderform.html: Code: [Select] <html> <body> <form action="processorder.php" method="post"> <table border="0"> <tr bgcolor="#cccccc"> <td width="150">Item</td> <td width="15">Quantity</td> </tr> <tr> <td>Tires</td> <td align="center"><input type="text" name="tireqty" size="3" maxlength="3"></td> </tr> <tr> <td>Oil</td> <td align="center"><input type="text" name="oilqty" size="3" maxlength="3"></td> </tr> <tr> <td>Spark Plugs</td> <td align="center"><input type="text" name="sparkqty" size="3" maxlength="3"></td> </tr> <tr> <td>How did you find Bob's?</td> <td><select name="find"> <option value = "a">I'm a regular customer</option> <option value = "b">TV advertising</option> <option value = "c">Phone directory</option> <option value = "d">Word of mouth</option> </select> </td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="Submit Order"></td> </tr> </table> </form> </body> </html> processorder.php: <!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>Bobs Auto Parts - Order Results</title> </head> <body> <h1>Bobs Auto Parts</h1> <h2>Order Results</h2> <?php $tireqty = $_post['tireqty']; $oilqty = $_post['oilqty']; $sparkqty = $_post['sparkqty']; echo "<p>Order Processed at "; echo date('H:i, jS F Y'); echo "</p>"; echo '<p>Your order is as follows: </p>'; echo $tireqty.' tires<br />'; echo $oilqty.' bottles of oil<br />'; echo $sparkqty.' spark plugs<br />'; $totalqty = 0; $totalamount = 0.00; define('TIREPRICE', 100); define('OILPRICE', 10); define('SPARKPRICE', 4); ?> </body> </html> For some reason the values on the processing form dont show up. The only text thats displayed is : Bobs Auto Parts Order Results Order Processed at 17:07, 9th January 2011 Your order is as follows: tires <---- Should be showing the total quantity ordered bottles of oil <---- Should be showing the total quantity ordered spark plugs <---- Should be showing the total quantity ordered Is anyone able to let me know where the error is in this code? The writers website isnt any help.... Regards, sapper6fd The code below is a form the gets information from a database and post it into the appropriate field. I am having a problem with the while loop. All the variables before the while loop work just great and echo out how they should. But everything after the while loop does not work. I know it has something to do with the while loop because when I take the while loop out everything works as it should. Can anyone please help me with this? <? $id = $_POST["id"]; $therapy = $_POST["therapy"]; db_connect(); $query=mysql_query("select * from student where student_id = $id") or die ("invalid query"); $row=mysql_fetch_array($query); print "<table width='330' border=0 align='center'> <form method='POST' action='table.php'> <td>*First Name:</td> <td>*Last Name:</td> <tr>"; ?> <td width="157"><input size="23" name="first_name" value="<?php echo "$row[first_name]"; ?>" /></td> <td width="138"><input type="text" size="23" name="surname" value="<?php echo "$row[surname]"; ?>" /></td> </tr> <tr> <td>Level:</td> <td>Therapy:</td> </tr> <tr> <td> <select name="program_level"> <option <?php if ($row[program_level]=='1') echo "selected=yes"; ?> value="1">O&A</option> <option <?php if ($row[program_level]=='2') echo "selected=yes"; ?> value="2">Student</option> <option <?php if ($row[program_level]=='3') echo "selected=yes"; ?> value="3">Supervisor</option> <option <?php if ($row[program_level]=='4') echo "selected=yes"; ?> value="4">Manager</option> <option <?php if ($row[program_level]=='5') echo "selected=yes"; ?> value="5">Director</option> <option <?php if ($row[program_level]=='6') echo "selected=yes"; ?> value="6">Graduate</option> </select> </td> <td> <!-- Auto drop down for therapist names--> <? $query2=mysql_query("select * from therapy_info;"); ?> <select name='therapy'> <? while ($row=mysql_fetch_assoc($query2)){ ?> <option value="<? echo "$row[therapy_name]"; ?>"> <? echo "$row[therapy_name]"; } ?> </option> </select> <!-- End Auto drop down for therapist names--> </td> </tr> <tr> <td>Active:<?php echo "$row[active]"; ?></td> </tr> <tr> <td><select name='active' value='$row[active]'> <option <?php if ($row[active]=='1') echo "selected=yes"; ?> value='1'>Active</option> <option <?php if ($row[active]=='0') echo "selected=yes"; ?> value='0'>Inactive</option> </select> </td> </tr> <?php print "<tr> <td><input type='submit' value='Change' name='button' /></td> <input type='hidden' name='id' value='$id' />"; ?> <input type='hidden' name='$hardcode_session' /> <? print "</tr> </form> </table>"; I have the following code that outputs a url. It searches my MySQL database for the name of a given item within a theme: $relative = 'http://www.domain.com/wp-content/'; $url1= $relative . 'themes/arjuna-x/itemspec.php?type='; $url2='&item='; <a class="entry-thumbnails-link" href="<?php echo $url1.'Themes'.$url2.$rowThemes['Theme']; ?>"> The output is as follows: http://www.domain.com/wp-content/themes/arjuna-x/itemspec.php?type=Themes&item=(insert variable here) All is good up to this point. My problem however, is that some items (in this case: theme names) have apostrophes in them. For example: April Fool's. This results in breaking my php code. How can I get php to call these variables with apostrophes so that they don't break my php? I normally don't work with PHP or rather I'm learning as I go..and this is pretty much my last barrier between completing this project. Anyway here are my two files: http://pastebin.com/aThU3akC - file i want to grab values from and pass to the file below http://pastebin.com/kTYHr99p - file that is suppose to display the values in $transmessage Basically I need the variables defined in the first file to be passed and usable in the second and I'm not sure why I can't Hi First post here. Long time reader! I'm looking to gauge the general practices of dealing with variables between pages. I'd always pass my variables through the POST. Im normally always doing a post back and processing the data at the top of the page. I never liked the query string as it open to manipulation, but can see its use for a search results page and saving the url. I came from a ASP background and we would only use session variables for holding user login information as the windows server had a habit of restarting the pool and loosing the session. We didn't want this happening, for example, when doing an e-commerce transaction. We always felt the post was the most robust method. Now Im using php and all the great features it has. I was looking to see what the more experience php developers used and am I right sticking to the post method, or is utilising session a more modern way of doing things. I've a few years experience doing web dev, just thought I touch base on a few issues to make sure I'm still heading in the right direction. Thanks for any advice guys! I'm creating this URL to pass variables to use from one Page to another:
http://eg10basketbal...Borgman&team=16
My WP site is seeing the first variable but not the second. After some searching I've found this suggestion, but it's not working for me:
function add_query_vars_filter( $vars ) { $vars[] = "nameFull"; $vars[] = "team"; return $vars; } add_filter( 'query_vars', 'add_query_vars_filter' );I tried putting this in the wp-includes/functions.php file of the, but ended up with a fatal error. I have since added it to my theme's functions.php file. There isn't an error, but it doesn't yield recognition of my second variable. I have some function or method. Is there a better design patter to implement this?
function myFunction($a=null,$b=null,$c=null,$d=null,$e=null,$f=null,$g=null,$h=null) { //Do a bunch of stuff }Maybe the second function? function myNewFunction($data=array()) { $data=array_merge(array('a'=>null,'b'=>null,'c'=>null,'d'=>null,'e'=>null,'f'=>null,'g'=>null,'h'=>null),$array); //Do a bunch of stuff }Please provide decision making factors why you would use one approach over the other. Hey people, I know this is going back to basics but i'm just learning and want to make sure I do it all correctly. I want to pass variable's from one page to another. Now currently say I wanted to hold the users age and email address from his record in the database from page A and pass it to page B for it to be displayed back to him I would store each in their own session variable (so for the purpose of the explanation session_user_email=me@email.com and session_user_age=18. On page B I would then call the session and store it in a variable then destroy the session. Just out of curiosity is the the best way to pass the data? or should i use another method? i've read about session hijacking and i'm now worried about holding personal data within a session so i'm wondering what other people do?? Cheers I have a php script which is viewed with ajax. The script does some important things and I want to make sure that it's viewed by only the ajax and now the user so I was thinking I'd need to pass a code from the main page using a GET in either php or more likely javascript, as I don't want the user to be able to see the code and then be able to just copy it and view the script with it. I've tried to sort this by saving Math.random() to the database by using ajax using a separate file, then underneath it use it to access the file like this: Code: [Select] function saveCode() { var xmlHttp = connect(); if(xmlHttp != false) {var code = Math.random(); xmlHttp.open('GET', '/inc/battle/saveCode.php?i='+code, true); xmlHttp.onreadystatechange = function() { if(xmlHttp.readyState == 4) { battleLog = xmlHttp.responseText; battleList = battleLog.split('\n'); battleCount = battleList.length; addLine(); } } xmlHttp.send('null'); } This would save the code to the database, then with a separate function, namely endBattle() the variable code would be used to access a file called endBattle.php?i= where this script would compare the code from the GET variable to the code in the database. However, I realised before finishing this that the user could manually set the code to whatever they want through the saveCode.php page, then view the endBattle.php Does anyone have any ideas how else I could validate my endBattle.php page so that users couldn't view it in their browser to run it? Forgive me if this is in the completely wrong forum, I just thought I'd see whether there were any php methods of doing this. Thanks! I have an online store where users can either purchase products or add them to carts for future purchasing. Here is the code for item.php Code: [Select] <?php error_reporting(E_ALL ^ E_NOTICE); ini_set("display_errors", 1); require ('includes/config.inc.php'); include ('./includes/header.html'); require (MYSQL); include ('./includes/main.html'); if($id = isset($_GET['prodID'])) { $query = "SELECT `prodID`, `product`, `prod_descr`, `image`, `price` FROM product WHERE `prodID`='{$_GET['prodID']}'"; $r = mysqli_query($dbc, $query); $showHeader = true; echo "<div id='right'>"; while($row = mysqli_fetch_array($r)) { if($showHeader) { //Display category header echo "<h1>" . "<span>" . "# " . "</span>" . $row['product'] . "<span>" . " #" . "</span>" . "</h1>"; echo "<h2>" . $row['prod_descr'] . "</h2>"; echo "<img src='db/images/".$row['image']."' />"; $showHeader = false; $price = $row['price']; $product = $row['product']; echo '<form target="paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="item_name" value="<?php echo $product; ?>"> <input type="hidden" name="amount_x" value="<?php echo $price; ?>"> <input type="hidden" name="hosted_button_id" value="7UCL9YCYYXL3J"> <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form>'; } } echo "</div>"; } include ('./includes/footer.html'); ?> It displays a product based from a search made. Here is what I want to do? (I have already created test accounts, buttons, etc using PayPal Sandbox) 1. Dynamically pass a variable from when I add a chosen item 2. When my cart loads in Sandbox testing, display the appropriate price, product name, etc, based on the variable or value passed. When I set this up (Add To Cart button) I created default item name and price values, yet I do not want to do this manually using Sandbox. I apologise is this appears rather confusing and still being someone relatively new to PHP, I could do with a better understanding of this but I need some serious help please with this dilemma. i hav this url n whenever i click on this url i get som mssg send on my mobile i hav a form whose code is Code: [Select] <form action="formprocess.php method="post"> telephone<input type="text name="telephone> <input type="submit" name="submit"> </form> i want to send telephone as parameter to this url so whenever user enters his telephone he gets d mssg after clicking on submit.....but i hav no idea how to do tht...help me somone plssssssss http://www.abc.in/smsapi/sendsms.php?sendto=9987234123&msg=your Hi guys, I've been going crazy over this and I'm hoping someone can help me. I'm making a website for a friend and I'm stuck on sending the model over to the contact page (from one form to another on a different page using $_POST). Here is the website : www.ipgetter.com/test I have successfully posted the Make variable to the contact us page, but I can't get the model sent over (the select boxes have different names). Example: Code: [Select] <select class="form-dropdown" style="width:150px" id="input_2" name="q2_make"> <option selected="selected" value="Alfa Romeo"> Alfa Romeo </option> <option value="Aston Martin"> Aston Martin </option> <option value="Audi"> Audi </option> <option value="Bently"> Bently </option> <option value="BMW"> BMW </option> <option value="Chevrolet"> Chevrolet </option> <option value="Chrysler"> Chrysler </option> <option value="Citroen"> Citroen </option> <option value="Ferrari"> Ferrari </option> <option value="Fiat"> Fiat </option> <option value="Ford"> Ford </option> <option value="Honda"> Honda </option> <option value="Hyundai"> Hyundai </option> <option value="Infiniti"> Infiniti </option> <option value="Isuzi"> Isuzi </option> <option value="Jaguar"> Jaguar </option> <option value="Jeep"> Jeep </option> <option value="Kia"> Kia </option> <option value="Lamborghini"> Lamborghini </option> <option value="Land Rover"> Land Rover </option> <option value="Lexus"> Lexus </option> <option value="Lotus"> Lotus </option> <option value="Maserati"> Maserati </option> <option value="Mazda"> Mazda </option> <option value="Mclaren"> Mclaren </option> <option value="Mercedes-Benz"> Mercedes-Benz </option> <option value="MG"> MG </option> <option value="Mini"> Mini </option> <option value="Mitsubishi"> Mitsubishi </option> <option value="Nissan"> Nissan </option> <option value="Peugeot"> Peugeot </option> <option value="Porsche"> Porsche </option> <option value="Renault"> Renault </option> <option value="Rolls-Royce"> Rolls-Royce </option> <option value="Seat"> Seat </option> <option value="Skoda"> Skoda </option> <option value="Smart"> Smart </option> <option value="Ssangyong"> Ssangyong </option> <option value="Subaru"> Subaru </option> <option value="Suzuki"> Suzuki </option> <option value="Toyota"> Toyota </option> <option value="Vauxhall"> Vauxhall </option> <option value="Volkswagen"> Volkswagen </option> <option value="Volvo"> Volvo </option> <option value="Other"> Other </option> </select> That's the make, as for the model, the select boxes have different names so how am I supposed to capture the users selection and POST it? Code: [Select] <li class="form-line" id="id_3"> <label id="label_3" for="input_3"></label> <div id="cid_3" class="form-input"> <select class="form-dropdown" style="width:150px" id="input_3" name="q3_model"> <option selected="selected" value="147"> 147 </option> <option value="159"> 159 </option> <option value="8C"> 8C </option> <option value="Breva"> Breva </option> <option value="Giulietta"> Giulietta </option> <option value="Mito"> Mito </option> <option value="Other"> Other </option> </select> </div> </li> <li class="form-line" id="id_4"> <label id="label_4" for="input_4"></label> <div id="cid_4" class="form-input"> <select class="form-dropdown" style="width:150px" id="input_4" name="q4_model4"> <option selected="selected" value="Cygnet"> Cygnet </option> <option value="DB9"> DB9 </option> <option value="DBS"> DBS </option> <option value="Rapide"> Rapide </option> <option value="Vantage"> Vantage </option> <option value="Virage"> Virage </option> <option value="Other"> Other </option> </select> </div> </li> I want to post only the selected make/model depending on the user selection. So my question is, how can I send the users chosen model selection over to the contact page form where there is more than one different select box? These select boxes are conditional so when you select "other" as make or model make/model, you may type one in. I'd like to send that also. Any help is appreciated guys, thanks so much. Having some problems with PHP session i currently use cookies to log users in, but i have decided to use php session instead but i can get it to work, it simply dose not pass the variables unless include session id in every single link on my website, can anyone tell me where i am going wrong these are the session setting from php.in session.use_cookies = 1 session.use_only_cookies = 0 session.name = usersesid session.auto_start = 1 session.cookie_lifetime = 0 session.referer_check = 1 session.cache_expire = 180 session.use_trans_sid = 1 Hi there,
I want to pass a input variable from login_success.php which will be sent to sqlprocess.php as the variable 'SQLinput';
sqlprocess.php
$link = mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $query = $_REQUEST['SQLinput']; //You don't need a ; like you do in SQL $result = mysql_query($query); $numfields = mysql_num_fields($result);login_sucess.php <form action="" method="post" <label> <span>SQL Input :</span> <input type ="text" id="message" name="SQLinput" placeholder="Input SQL"></textarea> </label> <label> <span>SQL Output :</span> <output id="text" id="SQLoutput" ></input> <script type="text/javascript" charset="utf-8"> // handles the click event for link 1, sends the query function getOutput() { getRequest( 'sqlprocess.php', // URL for the PHP file drawOutput, // handle successful request drawError // handle error ); return false; } // handles drawing an error message function drawError () { var container = document.getElementById('output'); container.innerHTML = 'Bummer: there was an error!'; } // handles the response, adds the html function drawOutput(responseText) { var container = document.getElementById('output'); container.innerHTML = responseText; } // helper function for cross-browser request object function getRequest(url, success, error) { var req = false; try{ // most browsers req = new XMLHttpRequest(); } catch (e){ // IE try{ req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { // try an older version try{ req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ return false; } } } if (!req) return false; if (typeof success != 'function') success = function () {}; if (typeof error!= 'function') error = function () {}; req.onreadystatechange = function(){ if(req .readyState == 4){ return req.status === 200 ? success(req.responseText) : error(req.status) ; } } req.open("GET", url, true); req.send(null); return req; } </script> <a href="#" onclick="return getOutput();"><button type="submit" id="search_btn" value="Submit">Submit</button> </a> <div id="output">waiting for action</div>Prior to the JS code - I was able to peform this action - however the JS code enables me to post the query onto the same page. I would like essentially like to query the database through an input box and output the same result on the same page. Thanks! I have created a PHP form which includes validation, however.. everytime the validation passes, php redirects the form to another page where mysql code is to insert the variables... for some reason the variables are not being sent at all. Any suggestions. page 1 <?php error_reporting(E_ALL); ini_set('display_errors', 1); ?> <?php function VerifyForm(&$values, &$errors) { // Do all necessary form verification // Validate Model Number if (strlen($values['model']) < 4) { $errors['model'] = 'Model Number too short'; } elseif( strlen($values['model']) > 20) { $errors['model'] = 'Model Number too long';} // Validate Price if (is_numeric($values['price']) == 0){ $errors['price'] = 'No Price has been entered';} // Validate Product if(($values['product']) == 0){ $errors['product'] = 'No Product has been selected';} // Validate Image $imageinfo = getimagesize($_FILES['photo']['tmp_name']); if($imageinfo['mime'] != 'image/gif' && $imageinfo['mime'] != 'image/jpeg' && isset($imageinfo)){ $errors['photo'] = 'Image format must be either JPEG or GIF';} // Validate Description if (strlen($values['description']) == 0){ $errors['description'] = 'Description is too short';} return (count($errors) == 0); } function DisplayForm($values, $errors) { ?> <!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>Test Area</title> <link rel="stylesheet" href="test.css" type="text/css" media="screen" /> </head> <body> <div id="container"> <h1>Add a Product</h1> <form method="post" id="customForm" action="" enctype="multipart/form-data"> <table> <tr> <td>Model Number:</td> <td><input id="model" type="text" size="30" name="model" value="<?php echo htmlentities($values['model']); ?>"/></td> <td class="error"><p style="color:#FF0000"><?php echo isset($errors['model']) ? $errors['model'] : ''; ?></p></td> </tr> <tr> <td>Choose a Product:</td> <td> <select class="product" name="product"> <option value="0">Please select an option below</option> <option value="19lcdtv">19" LCD TV</option> <option value="22lcdtv">22" LCD TV</option> <option value="26lcdtv">26" LCD TV</option> <option value="32lcdtv">32" LCD TV</option> <option value="37lcdtv">37" LCD TV</option> <option value="37plasmatv">37" Plasma TV</option> <option value="3D">3D Technology</option> <option value="42lcdtv">42" LCD TV</option> <option value="42plasmatv">42" Plasma TV</option> <option value="46plasmatv">46" Plasma TV</option> <option value="50plasmatv">50" Plasma TV</option> <option value="54plasmatv">54" Plasma TV</option> <option value="58plasmatv">58" Plasma TV</option> <option value="65plasmatv">65" Plasma TV</option> <option value="bluraydiscs">Bluray Discs</option> <option value="blurayhomecinema">Bluray Home Cinema System</option> <option value="blurayplayer">Bluray Player</option> <option value="blurayportable">Bluray Portable</option> <option value="blurayrecorder">Bluray Recorder</option> <option value="breadmaker">Breadmakers</option> <option value="cdradio">CD, Radio and Cassette Players</option> <option value="convectorheater">Convector Heaters</option> <option value="cylindercleaner">Cylinder Cleaner</option> <option value="answerphone">DECT Answer Phone</option> <option value="phone">DECT Phone</option> <option value="fire">Dimplex Fires</option> <option value="dishwasher">Dishwashers</option> <option value="dvddiscs">DVD Discs</option> <option value="dvdplayer">DVD Player</option> <option value="dvdportable">DVD Portable</option> <option value="dvdrecorder">DVD Recorder</option> <option value="epilator">Epilators</option> <option value="fanheater">Fan Heaters</option> <option value="freezers">Freezers</option> <option value="fridgefreezer">Fridge-Freezers</option> <option value="hdcamcorder">HD Camcorders</option> <option value="hddcamcorder">HDD Camcorders</option> <option value="homecinema">Home Cinema System</option> <option value="iron">Irons</option> <option value="kettle">Kettles</option> <option value="beauty">Ladies Shavers/Beauty</option> <option value="leads">Leads</option> <option value="shaver">Mens Shavers/Grooming</option> <option value="microsystem">Microsystems</option> <option value="microwavegrill">Microwave (Grill)</option> <option value="microwavesolo">Microwave (Solo)</option> <option value="microwavecombi">Microwave Combination</option> <option value="dvtapes">Mini DV Tapes</option> <option value="minisystems">Minisystems</option> <option value="pvr">Personal Video Recorder (PVR)</option> <option value="projector">Projector</option> <option value="pure">Pure Radios</option> <option value="fridges">Refridgerators</option> <option value="sdcamcorder">SD Camcorders</option> <option value="sdcards">SD/SDHC/SDXC Cards</option> <option value="straighteners">Straighteners</option> <option value="stylishcamera">Stylish Cameras</option> <option value="superzoomcamera">Super Zoom Cameras</option> <option value="toaster">Toasters</option> <option value="tumbledryer">Tumble Dryers</option> <option value="uprightcleaner">Upright Cleaner</option> <option value="brackets">Wall Bracket</option> <option value="washingmachine">Washing Machine</option> </select> </td> <td class="error"><p style="color:#FF0000"><?php echo isset($errors['product']) ? $errors['product'] : ''; ?></p></td> </tr> <tr> <td>Price:</td> <td><input id="price" type="text" size="30" name="price" value="<?php echo isset($values['price']) ? $values['price'] : htmlentities($values['price']) ; '';?>"/></td> <td class="error"><p style="color:#FF0000"><?php echo isset($errors['price']) ? $errors['price'] : ''; ?></p></td> </tr> <tr> <td>Please upload an Image:</td> <td><input id="photo" type="file" size="30" name="photo" value="<?php echo isset($values['photo']) ? htmlentities($values['photo']) : ''; ?>"/></td> <td class="error"><p style="color:#FF0000"><?php echo isset($errors['photo']) ? $errors['photo'] : ''; ?></p></td> </tr> <tr> <td valign="top">Description:</td> <td> <textarea id="description" name="description" cols="" rows=""><?php echo isset($values['description']) ? htmlentities($values['description']) : ''; ?></textarea> </td> <td class="error"><p style="color:#FF0000"><?php echo isset($errors['description']) ? $errors['description'] : ''; ?></p></td> </tr> <tr> <td><input id="submit" name="submit" type="submit" value="Submit" /></td> </tr> </table> </form> </div> </body> </html> <?php } function ProcessForm($values) { //INSERT VARIABLES FROM INSERT_ADD.PHP // Replace with actual page or redirect :P header ("Location: http://www.example.com"); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $formValues = $_POST; $formErrors = array(); if (!VerifyForm($formValues, $formErrors)) DisplayForm($formValues, $formErrors); else ProcessForm($formValues); } else DisplayForm(null, null); ?> This is the page which includes database details and insert commands <?php $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name=""; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); //This is the directory where images will be saved $target = "images/"; $target = $target . basename( $_FILES['photo']['name']); // Get values from form $model=$_POST['model']; $product=$_POST['product']; $description=$_POST['description']; $price=$_POST['price']; $photo=($_FILES['photo']['name']); // Insert data into mysql $sql="INSERT INTO $tbl_name(model, product, description, price, photo)VALUES('$model', '$product', '$description', '$price', '$photo')"; $result=mysql_query($sql); if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "<center>The file " . basename($_FILES['photo']['name']) . " has been uploaded, and your information has been added to the directory</center>"; } else { //Gives and error if its not echo "Sorry, There was a problem Uploading your Details."; } // close connection mysql_close(); ?> |