Jump to content

anne3marie

Members
  • Posts

    14
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

anne3marie's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Yes I am getting Your request was not submitted, please contact NewLeaf Delivery' If I place my query in a variable, I simple then echo the variable? Didn't I place my query in a variable? $sql is my variable. I am very new to this. How would I do that exactly?
  2. I have a form which post to this page and the update is not happening. What did I do wrong? I also tried removing the where clause to see if that was the problem but it still did not work. Thanks! <?php include 'db.php'; session_start(); $user=$_SESSION['userid']; $box_selection=$_POST["box_selection"]; $agree=$_POST["agree"]; $payment=$_POST["payment"]; $sql = mysql_query("Update grocery_cart SET order_size='$box_selection', pp_check='$agree', payment='$payment' WHERE userid='$user'"); if(!$sql){ echo 'Your request was not submited, please contact NewLeaf Delivery';include'sign_up.php';} else{ echo "Your request has been received";include 'signed_up.php'; } ?> Thanks!
  3. I am hard coding those values currently until I can get the script to work! I also want the text field in the form to show the item quantity that the customer has currently selected.
  4. I am trying to create a simple update or insert form which is not working. This is the code for my form <form action="add_to_cart5.php" method="post" name="form1" onSubmit="MM_validateForm('banana_qnt','','NisNum');return document.MM_returnValue"> <label for="banana_qnt">3 Organic Bananas $1.49 Quantity</label> <input name="banana_qnt" type="text" id="banana_qnt" value="<?php "SELECT quantity FROM grocery_cart WHERE username='cust_username' and product_id='bananaid' " ?> "> <input type="submit" name="add_to_cart" id="add_to_cart" value="update"> </form> I can add new rows fine but when I try to update or insert using the following code, nothing works. <?php include 'db.php'; //register variable $banana_qnt = $_POST['banana_qnt']; $sql="UPDATE grocery_cart SET quantity='$banana_qnt' WHERE username='cust_username' and product_id='bananaid'"; //Insert cart line if (!$sql){$sql2 = mysql_query("INSERT INTO grocery_cart (username, product_id, quantity, price) VALUES('cust_username','bananaid ','$banana_qnt','1.49')ON DUPLICATE KEY UPDATE quantity=$banana_qnt") ;} if(!$sql and !$sql2){ echo 'Item quantity not updated, please contact NewLeaf Delivery';include'grocery_cart.php';} else{ echo "Item Quantity Updated!";include 'grocery_cart.php'; } ?> if anyone has a better way of doing this that would help. Each customer gets a new line in the database when they enter a quantity. For this reason, there is no way to use duplicate key function because there is no unique primary key except for auto increment #. Also on my form I would like for the text box to b=have an initial value set to the "banana_qnt" in the database. Please help. Thanks for reading!
  5. I changed 'where' to 'location' and added '' around each entered variable and I am no longer getting an error message but when i submit the form, the register_member.php is completely blank with no errors. here is the updated code. <?php include 'db.php'; // Define post fields into simple variables $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email_address = $_POST['email_address']; $username = $_POST['username']; $address = $_POST['address']; $zip = $_POST['zip']; $phone = $_POST['phone']; $instructions = $_POST['instructions']; $location = $_POST['location']; /* Let's strip some slashes in case the user entered any escaped characters. */ $first_name = stripslashes($first_name); $last_name = stripslashes($last_name); $email_address = stripslashes($email_address); $username = stripslashes($username); $info = stripslashes($info); /* Do some error checking on the form posted fields */ if((!$first_name) || (!$last_name) || (!$email_address) || (!$username) || (!$address) || (!$phone) || (!$location)){ echo 'You did not submit the following required information! <br />';include 'join_form.html';} if(!$first_name){ echo "First Name is a required field. Please enter it below.<br />"; } if(!$last_name){ echo "Last Name is a required field. Please enter it below.<br />"; } if(!$email_address){ echo "Email Address is a required field. Please enter it below.<br />"; } if(!$username){ echo "Desired Username is a required field. Please enter it below.<br />"; } if(!$address){ echo "Delivery Address is a required field. Please enter it below.<br />"; } if(!$phone){ echo "Phone is a required field. Please enter it below.<br />"; } if(!$location){ echo "Where would you like your delivery driver to leave your box is a required field. Please enter it below.<br />"; } // Show the form again! /* End the error checking and if everything is ok, we'll move on to creating the user account */ exit(); // if the error checking has failed, we'll exit the script! /* Let's do some checking and ensure that the user's email address or username does not exist in the database */ $sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'"); $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'"); $email_check = mysql_num_rows($sql_email_check); $username_check = mysql_num_rows($sql_username_check); if(($email_check > 0) || ($username_check > 0)){ echo "Please fix the following errors: <br />"; if($email_check > 0){ echo "<strong>Your email address has already been used. Please submit a different Email address!<br />"; unset($email_address); } if($username_check > 0){ echo "The username you have selected has already been used by another member in our database. Please choose a different Username!<br />"; unset($username); } include 'join_form.html'; // Show the form again! exit(); // exit the script so that we do not create this account! } /* Everything has passed both error checks that we have done. It's time to create the account! */ // Enter info into the Database. $sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, username, address, zip,phone, instructions, location, signup_date) VALUES('$first_name', '$last_name', '$email_address', '$username', '$address', '$zip', '$phone','$instructions', '$location', now())") or die (mysql_error()); if(!$sql){ echo 'There has been an error creating your account. Please contact NewLeaf Delivery at newleaf@newleafdelivery.com.'; } else { $userid = mysql_insert_id(); // Let's mail the user! $subject = "A NewLeaf Member!"; $message = "NewLeaf, $first_name $last_name, just registered online. The delivery address is $address, and email address is $email_address. Check the delivery address and email the new member!! NewLeaf Delivery This is an automated response, please do not reply!"; mail('annemari.riley@gmail.com'|| 'newleaf@newleafdelivery.com', $subject, $message, "From: NewLeaf Delivery<newleaf@newleafdelivery.com>\nX-Mailer: PHP/" . phpversion()); echo "";include 'order_contents.php'; } ?>
  6. I have been working for hours! I have a html form that submits to a php to update my sql database. The first bit of code is my registration form. <form name="register" method="post" action="register_member.php"> <p>Please create a free account to get started! </p> <table width="100%" border="0" cellpadding="4" cellspacing="2"> <tr> <td width="34%" align="left" valign="top"><div align="right">First Name</div></td> <td width="66%"><input name="first_name" type="text" id="first_name2" value="<? echo $first_name; ?>"></td> </tr> <tr> <td align="left" valign="top"><div align="right">Last Name</div></td> <td><input name="last_name" type="text" id="last_name" value="<? echo $last_name; ?>"></td> </tr> <tr> <td align="left" valign="top"><div align="right">Email Address</div></td> <td><input name="email_address" type="text" id="email_address" value="<? echo $email_address; ?>"></td> </tr> <tr> <td align="left" valign="top"><div align="right">Username</div></td> <td><input name="username" type="text" id="username" value="<? echo $username; ?>"></td> </tr> <tr> <td align="left" valign="top"><label for="delivery address"> <div align="right">Delivery Address</div> </label></td> <td><input type="text" name="address" id="delivery address" /></td> </tr> <tr> <td align="left" valign="top"><div align="right">City, State</div></td> <td>Roseburg, OR</td> </tr> <tr> <td align="left" valign="top"><div align="right">Zip Code</div></td> <td><label for="Zip"></label> <input type="text" name="zip" id="Zip" /></td> </tr> <tr> <td align="left" valign="top"><div align="right">Phone</div></td> <td><label for="phone"></label> <input type="text" name="phone" id="phone" /></td> </tr> <tr> <td align="left" valign="top"><div align="right">Check all that apply:</div></td> <td><input type="checkbox" name="hill" id="hill" /> <label for="hill">I live on a hill</label></td> </tr> <tr> <td align="left" valign="top"> </td> <td><input type="checkbox" name="hard" id="hard" /> <label for="hard"></label> My house is hard to find</td> </tr> <tr> <td align="left" valign="top"> </td> <td><input type="checkbox" name="gated" id="gated" /> <label for="gated"></label> I live in a gated community</td> </tr> <tr> <td align="left" valign="top"> </td> <td><input type="checkbox" name="apartment" id="apartment" /> <label for="apartment"></label> I live in an apartment</td> </tr> <tr> <td align="left" valign="top"><div align="right">Special instructions, keycode, etc, for your delivery:</div></td> <td><label for="instructions"></label> <textarea name="instructions" id="instructions" cols="35" rows="3"></textarea></td> </tr> <tr> <td align="left" valign="top"><div align="right">Where would you like your delivery rider to leave your box?</div></td> <td><label for="where"></label> <textarea name="where" id="where" cols="35" rows="3"></textarea></td> </tr> <tr> <td align="right">I agree to the NewLeaf <a href="policies.html" onclick="MM_openBrWindow('Policies_and_Procedures.html','','width=500,height=300')">Policies and Procedures:</a></td> <td><input type="checkbox" name="pp_check" id="pp_check" /> <label for="pp_check"></label></td> </tr> <tr> <td align="left" valign="top"> </td> <td><input type="submit" name="Submit" value="Join Now!"></td> </tr> </table> </form> Next this is my register_member.php which should process the form, insert mysql database, and email me that a new member needs to be reviewed. <? include 'db.php'; // Define post fields into simple variables $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email_address = $_POST['email_address']; $username = $_POST['username']; $address = $_POST['address']; $zip = $_POST['zip']; $phone = $_POST['phone']; $hill = $_POST['hill']; $hard = $_POST['hard']; $gated = $_POST['gated']; $apartment = $_POST['apartment']; $instructions = $_POST['instructions']; $where = $_POST['where']; $pp_check = $_POST['pp_check']; /* Let's strip some slashes in case the user entered any escaped characters. */ $first_name = stripslashes($first_name); $last_name = stripslashes($last_name); $email_address = stripslashes($email_address); $username = stripslashes($username); $info = stripslashes($info); /* Do some error checking on the form posted fields */ if((!$first_name) || (!$last_name) || (!$email_address) || (!$username) || (!$address) || (!$phone) || (!$where)){ echo 'You did not submit the following required information! <br />';include 'join_form.html';} if(!$first_name){ echo "First Name is a required field. Please enter it below.<br />"; } if(!$last_name){ echo "Last Name is a required field. Please enter it below.<br />"; } if(!$email_address){ echo "Email Address is a required field. Please enter it below.<br />"; } if(!$username){ echo "Desired Username is a required field. Please enter it below.<br />"; } if(!$address){ echo "Delivery Address is a required field. Please enter it below.<br />"; } if(!$phone){ echo "Phone is a required field. Please enter it below.<br />"; } if(!$where){ echo "Where would you like your delivery driver to leave your box is a required field. Please enter it below.<br />"; } // Show the form again! /* End the error checking and if everything is ok, we'll move on to creating the user account */ exit(); // if the error checking has failed, we'll exit the script! /* Let's do some checking and ensure that the user's email address or username does not exist in the database */ $sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'"); $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'"); $email_check = mysql_num_rows($sql_email_check); $username_check = mysql_num_rows($sql_username_check); if(($email_check > 0) || ($username_check > 0)){ echo "Please fix the following errors: <br />"; if($email_check > 0){ echo "<strong>Your email address has already been used. Please submit a different Email address!<br />"; unset($email_address); } if($username_check > 0){ echo "The username you have selected has already been used by another member in our database. Please choose a different Username!<br />"; unset($username); } include 'join_form.html'; // Show the form again! exit(); // exit the script so that we do not create this account! } /* Everything has passed both error checks that we have done. It's time to create the account! */ // Enter info into the Database. $sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, username, address, zip, phone, hill, hard, gated, apartment, instructions, where, pp_check, signup_date) VALUES('$first_name', '$last_name', '$email_address', '$username', '$address', '$zip', $phone, $hill, $hard, $gated, $apartment, $instructions, $where, $pp_check, now())") or die (mysql_error()); if(!$sql){ echo 'There has been an error creating your account. Please contact NewLeaf Delivery at newleaf@newleafdelivery.com.'; } else { $userid = mysql_insert_id(); // Let's mail the user! $subject = "A NewLeaf Member!"; $message = "NewLeaf, $first_name $last_name, just registered online. The delivery address is $address, and email address is $email_address. Check the delivery address and email the new member!! NewLeaf Delivery This is an automated response, please do not reply!"; mail('annemari.riley@gmail.com'|| 'newleaf@newleafdelivery.com', $subject, $message, "From: NewLeaf Delivery<newleaf@newleafdelivery.com>\nX-Mailer: PHP/" . phpversion()); echo "";include 'order_contents.php'; } ?> When I fill out the form, I get this message from the browser "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where, signup_date) VALUES('test', 'test', 'test', 'test', 'test','test','test' at line 1" Test is what I entered into each field. THank you for reading. Hope you can help!
  7. I fixed this problem by adding to my update.php. I think php is getting easier!! I have only been coding for about 2 weeks! $_SESSION['item_1'] = $_POST['item1'];
  8. When a customer updates the database with their item selections, they have to log out and log back in to see the changes updated. How can I update these session variables when the customer refreshes the page? Thanks!
  9. I changed the option to "none" and wrote this. It seems to work. Thanks for the help! if($item_5=='none'){ ;} else{$query5 = "UPDATE users SET item_5 = '$item_5' WHERE userid='$userid'";}
  10. No 'do not replace' is simply one of the options that is populated from the database. The other options are carrots, tomatoes, celery, etc. I thought that I could use an if statement to tell it not to update when that option was chosen, but it seems this is not the way to do it. I need to make a selection option that does not update the database but I do not know how to do it. My update code is below. I am currently only working with item 1 until I get this figured out <?php include 'db.php'; session_start(); $item_1 = $_POST['item1']; $item_2 = $_POST['item2']; $item_3 = $_POST['item3']; $item_4 = $_POST['item4']; $item_5 = $_POST['item5']; $item_6 = $_POST['item6']; $item_7 = $_POST['item7']; $item_8 = $_POST['item8']; $item_9 = $_POST['item9']; $item_10 = $_POST['item10']; $userid=$_SESSION[userid]; $query = "UPDATE users SET item_1 = '$item_1' WHERE userid='$userid'"; if(mysql_query($query)){ echo "updated";} else{ echo "fail";} ?>
  11. I have a html form drop down list of produce which my customers chose from. The options in the form are automatically populated from a database. When submitted, the form updates the list of produce in mysql database. I want to add an if statement which allows the customer to not change that selection (leave it as it currently is in the database). There is currently a 'do not update' selection option if($item_1=='do not replace'){}. I don't know how to finish this statement or if something like this will work. Or is there a way to set up my html form that the menu select form automatically submits no item_1 if nothing is chosen? Thanks! This is the code for my selection menu <select id="item1" name="item1"> <?php require('db.php'); $cdquery="SELECT items FROM food"; $cdresult=mysql_query($cdquery) or die ("Query to get data from table failed: ".mysql_error()); while ($cdrow=mysql_fetch_array($cdresult)) { $cdTitle=$cdrow['items']; echo "<option> $cdTitle </option>"; } ?> </select>
  12. I thought I tried that but it seems adding session_start() did the trick. Thanks for helping me. I knew it was a simple fix! Now do you know how I would add a conditional statement that leaves the database entry alone? I don't know what goes at the end of this statement or if it is possible. something like If '$item1'== 'do not update' {} not sure
  13. Sorry, I also have $userid=$_SESSION[userid]; How do I code for it to be updated of the logged in user's item1?
  14. I am very new to php. I am using the code below to process a html form to update customers preference called item1. I want to update only the loggin in customer which is where my problem is. If i write "WHERE userid=4" or no where statement at all it updates correctly. When I include the where statement, it echos "updated" but the database doesn't change. I cannot figure out the correct where statement! Please Help! <?php include 'db.php'; $item_1 = $_POST['item1']; $query = "UPDATE users SET item_1 = '$item_1' WHERE userid='$userid'"; if(mysql_query($query)){ echo "updated";} else{ echo "fail";} ?>
×
×
  • 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.