Two Questions
Hi everyone. I am new to the group, and also relatively new to PHP. I have two questions relating to a website that I am setting up. Brief description:
This is a website that lists reviews of yarn stores. Included in the information that it captures is the price of certain yarns.
Question 1:
If I am using an array to call the <input name = xyz>, how do I write my insert statement to use it?
This is what I have so far, but I am very skeptical that it would work:
The form code:
$dbh=mysql_connect ("host", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("knittin1_yarnstore");
$getyarns = "SELECT yarnid, yarnco, yarnname FROM yarns";
$listyarns = mysql_query ($getyarns) or die ("Error at ListYarns: " . mysql_error() . "\n Whole Query: " . $getyarns);
$counter = 10;
printf ('<tr>');
while ($yarnarray = mysql_fetch_array ($listyarns)) {
printf ('<td>' . $yarnarray['yarnco'] . " " . $yarnarray['yarnname'] . '</td>');
printf ('<td>$<input ... ></td>');
$counter++;
if ($counter % 2 == 0) {
printf ("</tr><tr>");
$counter = 10;
}
}
And the processing code:
$yarns = "SELECT yarnid FROM yarns";
$yarnidquery = mysql_query ($yarns) or die ("Error at Yarns " . mysql_error() . "\nWhole Query: " . $yarns);
$yarnarraysetup = mysql_fetch_array ($yarnidquery);
$yarnarray = $yarnarraysetup['yarnid'];
while ($yarnidlist = mysql_fetch_array ($yarnidquery)) {
if ($yarnidlist['yarnid'] == $_POST['$yarnarray']) {
//$yarnprice = "INSERT INTO prices (yarnid, storeid, price) VALUES ('$storeidset', $yarnidlist['yarnid'], $_POST['$yarnarray'])";
//$yarnpriceinsert = mysql_query ($yarnprice) or die ("Error at YarnPrice: " . mysql_error() . "\nWhole Query: " . $yarnprice);
}
}
Question 2:
Is there any way to pass variables through an <a href= > tag? I want to set up the ability to browse through stores without having to use all dropdown menus.
Thanks in advance for all of the help.
This is a website that lists reviews of yarn stores. Included in the information that it captures is the price of certain yarns.
Question 1:
If I am using an array to call the <input name = xyz>, how do I write my insert statement to use it?
This is what I have so far, but I am very skeptical that it would work:
The form code:
$dbh=mysql_connect ("host", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("knittin1_yarnstore");
$getyarns = "SELECT yarnid, yarnco, yarnname FROM yarns";
$listyarns = mysql_query ($getyarns) or die ("Error at ListYarns: " . mysql_error() . "\n Whole Query: " . $getyarns);
$counter = 10;
printf ('<tr>');
while ($yarnarray = mysql_fetch_array ($listyarns)) {
printf ('<td>' . $yarnarray['yarnco'] . " " . $yarnarray['yarnname'] . '</td>');
printf ('<td>$<input ... ></td>');
$counter++;
if ($counter % 2 == 0) {
printf ("</tr><tr>");
$counter = 10;
}
}
And the processing code:
$yarns = "SELECT yarnid FROM yarns";
$yarnidquery = mysql_query ($yarns) or die ("Error at Yarns " . mysql_error() . "\nWhole Query: " . $yarns);
$yarnarraysetup = mysql_fetch_array ($yarnidquery);
$yarnarray = $yarnarraysetup['yarnid'];
while ($yarnidlist = mysql_fetch_array ($yarnidquery)) {
if ($yarnidlist['yarnid'] == $_POST['$yarnarray']) {
//$yarnprice = "INSERT INTO prices (yarnid, storeid, price) VALUES ('$storeidset', $yarnidlist['yarnid'], $_POST['$yarnarray'])";
//$yarnpriceinsert = mysql_query ($yarnprice) or die ("Error at YarnPrice: " . mysql_error() . "\nWhole Query: " . $yarnprice);
}
}
Question 2:
Is there any way to pass variables through an <a href= > tag? I want to set up the ability to browse through stores without having to use all dropdown menus.
Thanks in advance for all of the help.
