Jump to content

bigashish123

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

bigashish123's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. To all AJAX Gurus! I am trying to create a small ajax script that will allow me to select one or multiple check boxes and pass on their value (variable). Once I am on the PHP page, I am having trouble trying to verify if the checkbox is checked or not. Or I might be having a problem with my AJAX script. I am not sure at this point!! ??? Here is the initially AJAX script along with the initial HTML page: <html> <body> <script language="javascript" type="text/javascript"> <!-- //Browser Support Code function ajaxFunction(){ var ajaxRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ var ajaxDisplay = document.getElementById('ajaxDiv'); ajaxDisplay.innerHTML = ajaxRequest.responseText; } } var age = document.getElementById('age').value; var wpm = document.getElementById('wpm').value; var sex = document.getElementById('sex').value; var colord = document.getElementById('colord').value; var queryString = "?age=" + age + "&wpm=" + wpm + "&sex=" + sex + "&colord=" + colord; ajaxRequest.open("GET", "ajax-example.php" + queryString, true); ajaxRequest.send(null); } //--> </script> <form name='myForm'> Max Age: <input type='text' id='age' /> <br /> Max WPM: <input type='text' id='wpm' /> <br /> Sex: <select id='sex'> <option value='m'>m</option> <option value='f'>f</option> </select> <BR> Color: D <input type="checkbox" name="colord" id="colord" value="D"/> E <input type="checkbox" name="colore" value="E"/> F <input type="checkbox" name="colorf" value="F"/> G <input type="checkbox" name="colorg" value="G"/> H <input type="checkbox" name="colorh" value="H"/> I <input type="checkbox" name="colori" value="I"/> J <input type="checkbox" name="colorj" value="J"/> <BR> <input type='button' onclick='ajaxFunction()' value='Query MySQL' /> </form> <div id='ajaxDiv'>Your result will display here</div> </body> </html> I am trying to experiment with the "colord" checkbox only. The two text fields and the drop down list work fine but the chechbox functionality does not. Please be kind and detailed in your critique of my coding. I am definitely a newbie at this! Thank you for all your help!! Here is the PHP Code: <?php $dbhost = "IPAddress"; $dbuser = "username"; $dbpass = "password"; $dbname = "dbname"; //Connect to MySQL Server mysql_connect($dbhost, $dbuser, $dbpass); //Select Database mysql_select_db($dbname) or die(mysql_error()); // Retrieve data from Query String $age = $_GET['age']; $sex = $_GET['sex']; $wpm = $_GET['wpm']; $colord = $_GET["colord"]; // Escape User Input to help prevent SQL Injection $age = mysql_real_escape_string($age); $sex = mysql_real_escape_string($sex); $wpm = mysql_real_escape_string($wpm); $colord = mysql_real_escape_string($colord); //build query $query = "SELECT * FROM ajax_example WHERE ae_sex = '$sex'"; if(is_numeric($age)) $query .= " AND ae_age <= $age"; if(is_numeric($wpm)) $query .= " AND ae_wpm <= $wpm"; if($colord.checked = true) $query .= " AND ae_color = $colord"; //Execute query $qry_result = mysql_query($query) or die(mysql_error()); //Build Result String $display_string = "<table>"; $display_string .= "<tr>"; $display_string .= "<th>Name</th>"; $display_string .= "<th>Age</th>"; $display_string .= "<th>Sex</th>"; $display_string .= "<th>WPM</th>"; $display_string .= "<th>Diamond Color</th>"; $display_string .= "</tr>"; // Insert a new row in the table for each person returned while($row = mysql_fetch_array($qry_result)){ $display_string .= "<tr>"; $display_string .= "<td>$row[ae_name]</td>"; $display_string .= "<td>$row[ae_age]</td>"; $display_string .= "<td>$row[ae_sex]</td>"; $display_string .= "<td>$row[ae_wpm]</td>"; $display_string .= "<td>$row[ae_color]</td>"; $display_string .= "</tr>"; } echo "Query: " . $query . "<br />"; $display_string .= "</table>"; echo $display_string; ?>
  2. Okay MySQL Gurus - I need your help please! I have this code and it returns no results when I run within PHP. When I run the code in my backend PHP Admin tool, the code executes perfectly. I think it has to do with the Apostrophes I have within the query (i.e., Men's Wedding Ring, Women's Wedding Ring, etc). The double Apostrophes I have in my code below works in my backend MySQL Admin tool but within this PHP code, I return no results. Can I not use double apostrophes ('') within this php code?? Can someone PLEASE tell me what I am doing wrong?? Thank you!!! <?php $connect = mysql_connect("IPAddress", "username", "password") or die ("Hey loser, check your server connection."); mysql_select_db("dbname"); // Get all the data from the "example" table $quey1="SELECT distinct ProductID, Productname, Brand, CONCAT('$',MIN(ABS(SUBSTRING_INDEX(Price,'$',-1)))) AS Price, imageURL, Category, buyURL, LongDesc FROM JewelryStore WHERE Category LIKE '%Classic Solitaire Setting%' or Category LIKE '%Collections::Classic Solitaires%' or Category LIKE '%Collections::Sidestone%' or Category LIKE '%Collections::Vintage%' or Category LIKE '%Five-Stone Setting%' or Category LIKE '%Gemstone Ring%' or Category LIKE '%Gold Wedding Band for Women%' or Category LIKE '%Gold Wedding Bands for Men%' or Category LIKE '%Men''s Wedding Ring%' or Category LIKE '%Pre-set Engagement Ring%' or Category LIKE '%Setting with Sidestones%' or Category LIKE '%Three-Stone Diamond Rings%' or Category LIKE '%Three-Stone Setting%' or Category LIKE '%Women''s Diamond Ring%' or Category LIKE '%Women''s Wedding Ring%' GROUP BY ProductID order by Price ASC"; $result=mysql_query($quey1) or die(mysql_error()); ?> <table class='reference' cellspacing='0' cellpadding='0' border='1' width='100%'> <tr> <th>Ring Image</th> <th>Ring Name</th> <th>Price</th> <th>Ring Description</th> </tr> <?php while($row = mysql_fetch_array( $result )) { echo "<tr>"; echo "<td>"; /* echo '<img src="' . $row['imageURL'] . '"/>';*/ echo '<a href="' .$row['buyURL']. ' "/ target="_new"/> <img src="' . $row['imageURL'] . '"/ border="no"/>'; echo "</td>"; echo "<td>"; echo '<a href="' .$row['buyURL']. ' "/ target="_new"/>'; echo $row['name'] ; echo "</td>"; echo "<td>" . $row['Price'] . "</td>"; echo "<td>" . $row['LongDesc'] . "</td>"; echo "</tr>"; } echo "</table>"; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.