Jump to content

esoteric

Members
  • Posts

    104
  • Joined

  • Last visited

    Never

Everything posted by esoteric

  1. well the value has to be a set value, the value will change and is used elsewhere in the script, im trying the following but is it the best way to do things? what its doing is checking if the field 'offerValue' has been set if ($offerValue != NULL) { if (($offerPercent == NULL) && ($offerPrice == NULL) && ($ShippingPrice == NULL)) { $offer = "OFFER_VALUE"; }elseif (!isset($offer)) { echo "You must only use one type of offer!" ; } }
  2. I have a form with multiple options to fill out (its a admin form) i want to make sure only one of the of the options are set, so im checking if the variable is empty with if ($variable1 != NULL) { $new_variable = "yep, this option was filled out"; } so if the form sent anything from the form with the value 'variable1' it then sets a new variable ($new_variable) Problem is i have multiple fields so i need to make sure if it finds a a variable is not empty, then too check if the others have anything in them too. If it does find another (meaning more than one has been filled out) echo an error (echo "you must only complete one option..") What is the best way to check if more than one variable exists? Sorry if i explained it complicated. Thank you
  3. Oh, that makes sense. Thank you for explaining it. That seems to be working. Thanks very much
  4. thanks for your reply. two things, what does '-=' mean? Also i tested it again but changed the credit on my account to £17.50, the item is still £25 and the result returned as; Total Invoice: £32.5 (should be £7.50?) Remaining Credit: £0 my script so far; ////////////////////////////// // check if credit used if ($credit == 'Y'){ $total_credit = $customer_credit - $TOTAL; $connection = mysql_connect("") or die (mysql_error()); mysql_select_db("") or die (mysql_error()); mysql_query ("UPDATE users SET user_credit='".$total_credit."' WHERE id='".$customer_id."' ") or die (mysql_error()); } if($TOTAL <= $total_credit){ // is credit enough to pay bill? // YES $total_credit -= $TOTAL; // remove item cost from credit $TOTAL = 0; // set total cost to 0 for invoice }else{ // NO $TOTAL -= $total_credit; // use available credit $total_credit = 0; // } // echo 'Invoice Total: '.$TOTAL.'<br>'; // echo 'Remaining Credit: '.$total_credit.'<br>'; /////////////////////////////
  5. Ok i changed that line, done the same test as i did above but the invoice total is now saying "total invoice £175", so the - sign is gone but i how do i just show what the total with the credit subtracted is? using the example above again, if i take £25 (cost of the item) from £200 (amount of credit available) that should show the invoice total as £0 and the remaining credit on the account as £175. $total_credit should be the new total value shouldn't it? in this case £0?
  6. Can anyone see what im doing wrong here. I have a variable called 'TOTAL' which is the total amount the order comes too. A variable called 'customer_credit' which is the amount of credit a user has on there account, this is posted by a hidden field on my form. My form contains an option as to whether or not a customer wants to use there available credit and if so set the variable of 'credit' to Y. If the 'credit' variable equals Y i want to subtract the amount of credit the user has ('customer_credit') from the total ('TOTAL'). My script; if ($credit == 'Y'){ $total_credit = $TOTAL - $customer_credit; $connection = mysql_connect("$host", "$user", "$pass") or die (mysql_error()); mysql_select_db("$db") or die (mysql_error()); mysql_query ("UPDATE users SET user_credit='".$total_credit."' WHERE id='".$customer_id."' ") or die (mysql_error()); } if ($credit == 'N'){ $total_credit_unchanged = ("Credit not used. You could have saved $customer_credit on this order!"); } For a test i set the credit on my account to '200.00', i then went to purchase an item which costs '25.00'. The invoice then printed as "invoice total - £-175", it also saves the users total credit to '-175'. How can i make it so the credit is subtracted from the total, then the remaining credit are saved to teh database whilst the new total is shown on the invoice? Sorry for the long and possibly complicated post, i tried to explain best i could. Appreciate any help.
  7. Hi guys, im trying to connect to a database and get the value for the user in the row called 'user_credit', if it equals 1 or more then i want to show the ''You have £ ....'' bit in the script. Problem is nothing shows at all, even without the if statement. I have changed the value for me in the database so in user_credit the value is 100, which is more than 1 so it should appear. I have probably done something wrong. Any ideas? <? include '../admin/database/membership_dbc.php'; $r = mysql_query("SELECT * FROM users WHERE user_name='".safe($_SESSION['user_name'])."'") or die ("Cannot find table"); while( $cred = mysql_fetch_array($r) ) { if ($cred >= '1' ) { ?> <p>You have £<? echo $cred['user_credit']; ?> available on you account, would you like to use it on this order?<br> <label for="credit"></label> <select name="credit" id="credit"> <option value="Y" selected>Yes, use credit</option> <option value="N">No, save credit</option> </select> </p> <? } } ?>
  8. What is the correct way to right a simple maths question i have my total as: <?php echo $row['total'];?> i have my another number as: <?php echo $row['user_credit']; ?> but what i want to do is subtract the user_credit from the total and save it as a new variable called 'credits_used' but im unsure how to write it do i do it like $row['total'] - $row['user_credit'] = $row['credit_used']; Thank for any help
  9. I tried $op1_av = ("SELECT option3_available FROM $tbl WHERE title='$product'") or die ("Cannot find purchase options"); if ( $op1_av == 'Y' ) { ... }else echo "Nope, not working "; but it just echo the else statement instead, even if the variable in the table is set to Y
  10. Hi, i cant seem to get something working, should be simple but its not working for me. I just need to only display a table if a variable in my table = a certain value. The column in the table is called 'option1_available' and if its value is set to 'Y' i want it to display a table. Appreciate any help, Thanks
  11. thanks for the replies, i tried both suggestions but it doesn't seem to work. Can you see anything im doing wrong here> <? database stuff ?> <?php $background = $status == 'placed' ? '#FFCACA' : ($status == 'processing' ? '#FFD89D' : ($status == 'complete' ? '#BFFFBF' : null)); ?> <table width="600" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="<?php echo $background; ?>"> <tr> <td><?php $sql="SELECT * FROM orderTable WHERE userId = '{$_SESSION['user_id']}'"; if ($query=@mysql_query($sql)) { if (mysql_num_rows($query) > 0) { while ($req=mysql_fetch_array($query)) { ?></td> <td> </td> </tr> <tr> <td width="223">Invoice - <?php echo $req['orderNum'];?><br> <br> <?php echo $req['orderDate'];?> <br> <br> £<?php echo $req['total'];?> </td> <td width="377" align="center" valign="top"> <textarea name="textarea" cols="60" rows="5" disabled id="textarea"><?php echo $req['strMessageBody'];?></textarea></td> </tr> <tr> <td colspan="2" class="description"><?php } } else { echo "No orders found."; } } else { echo "Query failed ".mysql_error(); } ?></td> </tr> </table>
  12. how can i set the color of a table background depending on what a variable is in my database? I currently have a table which echos data from my database, but i want the background too be a color depending on the value of a variable called 'status' (there are 3 variations) the variations are; order placed, processing and complete so for example: if (status == placed) { background would be red } if (status == processing) { background would be orange } if (status == complete) { background would be green } appreciate any help. thank you.
  13. Hi, im trying to figure out how to have a form preview something next to the form depending on what options have been selected on a form. So let me explain better what i mean. I want to create a form which is for customers to create a custom product (in this case a nameplate). The options could be something like; letters (what word they want) font type: [few different font names here] font size: [small, medium, large] color: ... So if the customer typed in 'name' in the letters field then it would be displayed in the preview box If the customer then selected a font type, the change would then be reflected in the preview box.. and so on. I hope you understand what i trying to explain. I can just about handle creating the form but i don't know how to have it display what options have been chosen. If this is too much effort would it just be easier to submit this form and then display the data? or is it not too complicated to have it display on the same form before you submit it? I would prefer it displayed on the same page Thanks for any help.
  14. esoteric

    Div trouble

    I have no idea why but setting them all to float left seems to have worked. And i have no idea center didnt exist, well that sorted it anyway so thank you very much sir.
  15. esoteric

    Div trouble

    Sorry about the wrong section. The container is larger than the 3 divs. I even changed there width to 33% just in case. The right div is still too far down. Could a mod move this please! thanks
  16. esoteric

    Div trouble

    Can anyone see a problem with this? I'm trying to align 3 div's next to each other, the left and center is fine but the right is too far down, the top is approx at the bottom of the other 2. I can't understand why it isn't lining up. They should all appear at the top. <div id="newswrapper"> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <?php xxx ?> <td align="center"> <div id="newsleft"> <table width="100%"> <tr> <td><span class="headline"><span class="featuredescription"><span class="checkout"><a href="<?php echo $row['frag1Link']; ?>"><img src="<?php echo $row['frag1Image']; ?>" alt="" width="300" height="100"/></a></span></span></span></td> </tr> <tr> <td align="center"><span class="headline"><?php echo $row['frag1Title']; ?>test</span></td> </tr> <tr> <td align="center"><span class="headline"><span class="featuredescription"><?php echo $row['frag1Description']; ?>test</span></span></td> </tr> </table> </div> <div id="newscenter"> <table width="100%"> <tr> <td align="center"><span class="headline"><?php echo $row['frag1Title']; ?>test</span></td> </tr> <tr> <td align="center"><span class="headline"><span class="featuredescription"><?php echo $row['frag1Description']; ?>test</span></span></td> </tr> <tr> <td><span class="featuredescription"><span class="checkout"><a href="<?php echo $row['frag1Link']; ?>"><img src="<?php echo $row['frag1Image']; ?>" alt="" width="300" height="100"/></a></span></span></td> </tr> </table> </div> <div id="newsright"> <table width="100%"> <tr> <td><span class="featuredescription"><span class="checkout"><a href="<?php echo $row['frag1Link']; ?>"><img src="<?php echo $row['frag1Image']; ?>" alt="" width="300" height="100"/></a></span></span></td> </tr> <tr> <td align="center"><span class="headline">test<?php echo $row['frag1Title']; ?></span></td> </tr> <tr> <td align="center"><span class="featuredescription">test<?php echo $row['frag1Description']; ?></span></td> </tr> </table> </div> </td> </tr> </table> </div> <? } ?> my css #newsleft { padding-top: 50px; float:left; width:330px; margin: auto; } #newscenter { float: center; width: 330px; margin: auto; } #newsright { padding-top: 50px; float:right; width:330px; margin: auto; } Thank you.
  17. $yourname = "name"; $youremail = "[email protected]"; $subject = "you subject title"; $body = "message you want to send" $headers = "MIME-Version: 1.0\n"; $headers .= "Content-type: text/plain; charset=iso-8859-1\n"; $headers = "From: $yourname<$youremail>\r\n"; $headers .= "X-Mailer: PHP's mail() Function\n"; mail($to, $subject, $body, $headers); Try this
  18. So you use = to assign the variable a value and == to check the variable equal something? Well either way that seems to have got it, thanks very much.
  19. I have many pages i want to only be accessed by an admin when they are logged in, at the moment they are accessed by anyone logged in or not, this is a big problem if someone figured out the right url so i been trying to only make them accessible if the right variables exist. i have tried many thing but none of them seems to work, i have no idea why as they look right to me attempt 1 session_start(); $admin = 'FALSE'; if (isset ($_SESSION['user_level']) && ($_SESSION['user_level'] == '5')) { $admin = 'TRUE'; } if($admin = 'FALSE') { echo '<span style="color:#F00; text-align:center; font-size:14px;">Unauthorized Access Attempt!</span>'; exit; } if ($admin = 'TRUE') { ###my script here### } attempt 2 session_start(); if (isset ($_SESSION['user_level']) && ($_SESSION['user_level'] == '5')) { ###my script here### }else { echo '<span style="color:#F00; text-align:center; font-size:14px;">Unauthorized Access Attempt!</span>'; } any ideas? all i want is it too check if the user level is 5 (which is my admin level) and if so allow access to the page, if not give and echo message. Thank you.
  20. Thanks for you post, this is what i have so far, the list box populates fine but it doesn't populate the form. I get no errors. select_product.php <? xxx mysql_connect("$host", "$username", "$password") or die( "Unable to connect to database"); mysql_select_db("product_catalogue") or die( "Unable to select database"); ?> <form name="form" method="POST" action="../products/edit_product.php"> <select name="ProductName" id="ProductName"> <?php $sql="SELECT * FROM Products"; $result =mysql_query($sql); while ($data=mysql_fetch_assoc($result)){ ?> <option value ="<?php echo $data['ProductName'] ?>" ><?php echo $data['ProductName'] ?></option> <?php } ?> </select> <input type="submit" value="submit"> </form> edit_product.php <? xxxx $connection = mysql_connect("$host", "$username", "$password") or die( "Unable to connect to database"); $db = mysql_select_db("product_catalogue") or die( "Unable to select database"); $data = 'SELECT * FROM Products WHERE ProductName = "'.$data.'"'; $query = mysql_query($data) or die("Couldn't execute query. ". mysql_error()); $product_data = mysql_fetch_assoc($query); $id = htmlentities($product_data['ID']); $name = htmlentities($product_data['ProductName']); $productid = htmlentities($product_data['ProductId']); $category = htmlentities($product_data['Category']); $version = htmlentities($product_data['ProductVersion']); $imagepath = htmlentities($product_data['ProductImage']); $linkpath = htmlentities($product_data['ProductLink']); $description = htmlentities($product_data['ProductDescription']); $price = htmlentities($product_data['ProductPrice']); $shipping = htmlentities($product_data['ShippingPrice']); ?> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <form method="post" action="http://xxxxx/admin/products/update.php"> <tr bgcolor="#EDF5FA"> <td width="131" class="details">ID</td> <td width="459"><input type="text" name="prodnum" size="30" value="<?php echo $id; ?>"/></td> </tr> <tr> <td class="details">Name</td> <td><input type="text" name="name" size="30" value="<?php echo $name; ?>" /></td> </tr> <tr bgcolor="#EDF5FA"> <td class="details">Product ID</td> <td><input type="text" name="id" size="15" value="<?php echo $productid; ?>" /></td> </tr> <tr> <td class="details">Category</td> <td><input type="text" name="id" size="15" value="<?php echo $category; ?>" /></td> </tr> <tr bgcolor="#EDF5FA"> <td class="details">Version</td> <td><span class="details">v.</span> <input type="text" name="version" size="5" value="<?php echo $version; ?>" /></td> </tr> <tr> <td class="details">Image Path</td> <td><input name="image2" type="text" size="50" value="<?php echo $imagepath; ?>" /></td> </tr> <tr bgcolor="#EDF5FA"> <td class="details">Link Path</td> <td><input name="link" type="text" size="50" value="<?php echo $linkpath; ?>" /></td> </tr> <tr> <td class="details">Description</td> <td><textarea name="desc" cols="50" rows="10" value="<?php echo $description; ?>"></textarea></td> </tr> <tr bgcolor="#EDF5FA"> <td class="details">Price</td> <td><input type="text" name="price" size="10" value="<?php echo $price; ?>" /></td> </tr> <tr> <td class="details">Shipping</td> <td><input type="text" name="shipping" size="10" value="<?php echo $shipping; ?>" /></td> </tr> <tr> <td> </td> <td><p> <input type="submit" value="Update" /> </p> </form> </td> </tr> <tr> <td> </td> <td> </td> </tr> </table> I probably have done something right, any ideas? Thank you.
  21. Thanks for your reply. It doesn't have to be fancy at all, its only for admin eyes anyway. I just need to somehow make a list or menu that then populates the form, that's where i'm struggling because i cant quite figure out how to make it fill in the fields. Any sample code would be much appreciated, thanks for your time.
  22. Can anyone help get me started on how i can make a menu to display the contents of my sql table, but when clicking them it populates a table form. I know how to echo data on a php page but i dont know how to make it dynamic so each field on the form changes depending on what i clicked on my form <table width="100%" border="0" cellpadding="0" cellspacing="0"> <form method="post" action="http://xxx/admin/products/update.php"> <tr bgcolor="#EDF5FA"> <td width="131" class="details">ID</td> <td width="459"><input type="text" name="prodnum" size="30" /> <br /> <span class="details"><em>To get product ID visit the product list page</em></span><em><br /> </em></td> </tr> <tr> <td class="details">Name</td> <td><input type="text" name="name" size="30" /></td> </tr> <tr bgcolor="#EDF5FA"> <td class="details">Product ID</td> <td><input type="text" name="id" size="15" /></td> </tr> <tr> <td class="details">Category</td> <td><select name="cat"> <option value="Garden">Garden</option> <option value="Home">Home</option> <option value="Gifts">Gifts</option> <option value="Pets">Pets</option> </select></td> </tr> <tr bgcolor="#EDF5FA"> <td class="details">Version</td> <td><span class="details">v.</span> <input type="text" name="version" size="5" /></td> </tr> <tr> <td class="details">Image Path</td> <td><input name="image2" type="text" value="" size="50" /></td> </tr> <tr bgcolor="#EDF5FA"> <td class="details">Link Path</td> <td><input name="link" type="text" value="" size="50" /></td> </tr> <tr> <td class="details">Description</td> <td><textarea name="desc" cols="50" rows="10"></textarea></td> </tr> <tr bgcolor="#EDF5FA"> <td class="details">Price</td> <td><input type="text" name="price" size="10" /></td> </tr> <tr> <td class="details">Shipping</td> <td><input type="text" name="shipping" size="10" /></td> </tr> <tr bgcolor="#EDF5FA"> <td class="details">Password</td> <td><input type="text" name="pass" size="20" /></td> </tr> <tr> <td> </td> <td> <p><em class="details"><br /> <span class="details">To update a product you must fill in every field. If a field is left blank it will save as blank</span></em><br /> <br /> <input type="submit" value="Update" /> </p> </form> </td> </tr> <tr> <td> </td> <td> </td> </tr> </table> The reason im trying to do this is so i can update my products table, at the moment i have to fill in each field and keep referring back to a product list on a different page to fill in every detail again, i just want it to automatically fill in the field and i just change what is needed then hit the submit button. Thanks for any help.
  23. I would prefer to add the news to a database but i never got it too work properly. It currently listing the newest listing at the bottom ill have a look into that array reverse
  24. This is the script i wrote to post news. How can i alter this script so it lists contents with the newest post at the the top? At the moment its posting post 1 post 2 post 3 I want it to post like; post3 post2 post1 so the last post i made is at the top, not the bottom, if that makes sense. <?php function getNewsList(){ $fileList = array(); // Open the actual directory if ($handle = opendir("news")) { // Read all file from the actual directory while ($file = readdir($handle)) { if (!is_dir($file)) { $fileList[] = $file; } } } rsort($fileList); return $fileList; } ?> <table width="500px"> <?php $list = getNewsList(); foreach ($list as $value) { $newsData = file("news/".$value); $newsTitle = $newsData[0]; $submitDate = $newsData[1]; unset ($newsData['0']); unset ($newsData['1']); $newsContent = ""; foreach ($newsData as $value) { $newsContent .= $value; } echo "<tr><th align='left'><h2>$newsTitle</h2></th><th align='right'>$submitDate</th></tr>"; echo "<tr><td colspan='2'>".$newsContent."<br/><hr size='1'/></td></tr>"; } ?> </table> thank you.
  25. The path i wrong with that code, the variable $file holds the path to the existing file, how can i make a new variable with the new file path? i know i can do something like $new = ../edit/news/archives/ but i don't know ho to get the file name on the end, all the variable seem to be holding the path as well
×
×
  • 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.