Hello all:

I have been developing a web site using PHP and MySQL. I have generally had sucess but am stuck on this.

i have a php page that builds and displays a list of products based on a query on the previous page. the list is generated by a sql query using php. The list looks like this:

Here are the products you selected:

ProductMFG ProductModel ProductPhoto
ProductMFG2 ProductModel2 ProductPhoto2
ProductMFG2 ProductModel2 ProductPhoto2

I want to add a 'Favorite' button to the right of each row. The favorite button would post the ProductMFG and ProductModel variables ($row variables) from the row along with other variables from the original post ($_Post variables).

I have gotten far enough to know that I will need PHP and AJAX and possibly Javascript. I have attempted to get it running but am stuck.

How do you make a button with no other elements (no text box, no multiple select buttons, just one button) that will pass 5 or 6 variables (5 from the post from the previous page and 2 elements specfiic to each record) I want to store in the database and then change appearance to show it has been selected?

Once I get the variables passed to a server side php script I think I can handle the sql. I am stuck on creating the lone button, filling it with several variables from the original post and from the current row selected and linking it to the server side php script.


9 Years
Discussion Span
Last Post by fcrote

I have made progress but still get a consistent "error on page" when I click a button:

Here is the code in the 'button page' This is the script that tests the browser:


<script language="javascript" type="text/javascript">
//Browser Support Code
function ajaxFunction(){

var ajaxRequest; // The variable that makes Ajax possible!

// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;

var word = document.getElementById('test').value;
var queryString = "?word=" + word;
ajaxRequest.open("GET", "php_ajax_input.php" + queryString, true);


Here is the button code

<form name='myForm'>
<input type='hidden' name='email' value='cccc' >
<input type='hidden' name='gender' value ='female' >
<input type='hidden' name='age' value ='over75' >
<input type='hidden' name='color' value='pink' >
<input type='hidden' name='zip' value='aaaa'>
<input type='hidden' name='type' value='sedan'>
<input type='hidden' name='price' value='under25k'>
<input type='hidden' name='goal' value='editors'>
<input type='hidden' name='emailok' value='yes'>
<input type='hidden' name='mfg' value='Hyundai'>
<input type='hidden' name='model' value='Azera'>
<input class='button' onClick='ajaxFunction()'; value='Vote' type='button'>

Finally, here is the .php server side script that should execute



$dt2=date('Y-m-d H:i:s');
$con = mysql_connect("mysql","user","pass");
if (!$con)
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("carnoodle2", $con);$sql="INSERT INTO favorites
(date, email, gender, age, color, zip, type, price, goal, emailok, mfg, model) VALUES ('$dt2', '$_POST[email]','$_POST[gender]','$_POST[age]','$_POST[color]','$_POST[zip]','$_POST[type]','$_POST[price]','$_POST[goal]','$_POST[emailok]','$_POST[mfg]','$_POST[model]')";if (!mysql_query($sql,$con)
  die('Error: ' . mysql_error());
//echo "1 record added";


Thanks in advance for any ideas

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.