Jump to content

Skor

Members
  • Posts

    48
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Skor's Achievements

Member

Member (2/5)

0

Reputation

  1. This doesn't account for the $i variable which I need to increment for each row returned.
  2. Is there a better way to retrieve the results of my query as well as iterate over the form?
  3. I haven't done many for loops, but this one's making me a little nutty. What I'm trying to do is increment the field names, starting at 1, up to the number of rows that are returned from the query. I've gotten to return either two rows (which is correct), the the $i variable stays at 1 for both entries. Or, I've gotten four rows to return (which is wrong) and the $i variable, goes 1-2 1-2. Not what I want either. I suspect(or hope) that I've made a simple error and just need a more experienced set of eyes. Thanks in advance. $result = mysql_query($query) or die('Query not successfully processed: ' . mysql_error()); $num_rows = mysql_num_rows($result); //echo "Number of rows: $num_rows"; // get each row while($row = mysql_fetch_assoc($result)) { $cat = $row["cat_code"]; $pid = $row["pid"]; $name = $row["name"]; $price = $row["price"]; $units = $row["units"]; $qty = $row["qty"]; $itemname = $name.'('.$cat.$pid.')'; echo "<tr valign=\"top\">"; for($i=1; $i <= $num_rows; $i++) --is this where the problem is? { echo "<td>$name<input name=\"product$i\" type=\"hidden\" value=\"$itemname\"></td>"; echo "<td> $$price<input name=\"price$i\" type=\"hidden\" value=\"$price\"></td>"; echo "<td><select name=\"qty$i\"> <option value=\"0\" selected=\"selected\">Select quantity</option> <option value=\"1\">1</option> <option value=\"2\">2</option> <option value=\"3\">3</option> </select>"; echo "<input name=\"scode$i\" type=\"hidden\" value=\"$pid\"> <input name=\"units$i\" type=\"hidden\" value=\"$units\"></td></tr>"; } }
  4. Thanks for the ideas. I appreciate it.
  5. It's not ftp, I'm requesting info from one of their online databases with a request. fopen seemed odd to me too.
  6. I'm trying to help a client out here. This is typically out of my domain, but the forum's been great in the past. Here's what we're trying to do, but don't know how to in PHP. 1. I have a URL string where the client needs to include some variable information. test.abc.com:8080?variable1=9899&variable2=09oid&variable3=Y 2. What comes back is either a YES or a NO 3. The code will branch accordingly. My question is what is the best approach to connect to the site? I've done a little research and found a couple of alternatives -- fsockopen, fopen, GET/HTTP. The partner can't get what he's coded and wanted to know if he's just barking up the wrong tree. Just looking for a recommended approach here. Thanks in advance.
  7. Thanks, the woes of late night programming.
  8. In my test script I just added an if conditional and can't seem to get out of the T_STRING vortex. I just added the IF statement tonite. The update has been in place for a few months now and worked file. Putting it at the else has wreaked havoc apparently. Here's what I have. This is my testing utility that's why there's so many echos. PHP Code: $code = substr($desc,-6,1); echo "Code = $code <br>"; if ($code == 'B') { $insertqty = "INSERT INTO qytorders (cat_code, order_num, pid, price, sold_date, sold_code, quantity, order_id, email, discount) VALUES ('$code','','$pid','$money','NOW()','QTY','$qty','$id','$email','$discount'); mysql_query ($insertqty); echo '...Insert data into qytorders <br>'; } else { //The error message is on the following line: // Parse error: syntax error, unexpected T_STRING // This code worked fine before the IF statement. ??? $update = "UPDATE ckd_labinv SET status ='S', sold_code = 'SLD', sold_date = NOW() WHERE pid = '$pid' and status = 'A'"; $result = mysql_query($update) or die (mysql_error()); } $num_rows = mysql_affected_rows();//$result echo "<br>Number of Rows: $num_rows<br>"; What did I miss here? Thanks.
  9. I'm receiving the error above in my shopping cart application. I sell one-off items and use Paypal as the payment engine. In the remote possibility an item was previously purchased I loop through each order and update one at a time. I'm counting rows so if a record is not updated, I'd like to know. Strangely, it's working as designed (sending emai), but don't want to deploy unless I know why this error is occuring. Here's what I've got so far. Here's the full error: 1. is not a valid MySQL result resource in cartworks15.php on line 105. 2. Do I need to change the variable to a different function. Is my syntax correct. Please let me know. Thanks in advance. 3. The code: mysql_query ($query); // breaks the string into an array of products $products = explode("~", $cart); $i = 0; // breaks each product string into its own array foreach($products as $var => $val){ $product[$i] = explode(":", $val); $desc = $product[$i][0]; $qty = $product[$i][1]; $money = $product[$i][2]; $pid = $product[$i][4]; $update = "UPDATE ckd_labinv SET status ='S', sold_code = 'COD', sold_date = NOW() WHERE pid = '$pid' and status = 'A'"; mysql_query($update) or die(mysql_error()); $i++; } //echo '...Updated Database <br>'; $to = "me@test.com"; $subject = "Already Purchased Alert!"; $contents = "\nThe following item has already been purchased:\n\n * $desc \n\nThis item was purchased by the following customer:\n\n $inv_name,$email, on $date.\n"; $from_header = "From: purchasealerts@ckd.com"; $num_rows = mysql_num_rows($update); [color="Red"][b]//offending line[/b][/color] //mysql_affected_rows($update); if ($num_rows == 0) { mail( $to, $subject, $contents, $from_header); echo '...sent Already Purchased Alert <br>'; } Thanks in advance.
  10. I was hoping to put the error on the form itself, near the drop-down...is that possible to do. If not, I can certainly put it on the post page, which I'll try this evening. Thanks.
  11. Where do you put the "if" statement -- at the top of the form, bottom, outside of the form tags. Just curious. Tinkering with your suggestion and haven't gotten it to work yet....
  12. Yes, I do need to make it specific to the drop down. The check box is an option and can be null. Thanks much.
  13. I've got one that has me scratching my head, not sure exactly how to do this. I've got a drop down menu that I would like to consider mandatory. If it's not selected, I'd like to display an error on the page close to the drop-down, if it is selected, the form should post to another page. I've tinkered with a little javascript which I couldn't figure out. I've used a switch to display different dropdowns and that works fine, I've just included one as an example. Here's what the form looks like: <FORM NAME="CORDS" METHOD="POST" ACTION="checkmeout.php"> <INPUT TYPE="HIDDEN" NAME="product" VALUE="<?php echo $item3; ?>"> <INPUT TYPE="HIDDEN" NAME="price" VALUE="<?php echo $price; ?>"> <INPUT TYPE="HIDDEN" NAME="pagetype" VALUE="neck"> switch ($neck) { case "A": echo " <input type=\"hidden\" name=\"product[]\" value=\"$item3\"> <select name=\"product[]\"><option value=\"\">Select your cord or chain:</option> <option value=\"18-inch silver chain\">18-inch Sterling silver box chain</option> <option value=\"16-inch black cord\">16-inch black rubber cord</option> <option value=\"18-inch black cord\">18-inch black rubber cord</option></select>"; break; } ?> <br><br>Include giftbox <input type="checkbox" name="giftbox" value="giftbox"> <INPUT TYPE="SUBMIT" Value="Add to Cart"> </FORM>
  14. Unfortunately, this didn't work. I went back to != and played with single and double quotes and still got my error message. Thanks for the ideas.
  15. I tried this and it didn't work. If ($ref != 'http://www.sitename.com/page1.php' || $ref != 'http://www.sitename.com/page2.php') { echo Looks like the array solution only evaluates one value unless I'm incorrect here.
×
×
  • 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.