Jump to content

Thunder_Wolf

Members
  • Posts

    28
  • Joined

  • Last visited

Everything posted by Thunder_Wolf

  1. Thank you very much that looks like its working like l need it to, would you suggest any other tutorials and web pages that will increase my knowledge? I still plan on reading through a few more php web pages. so any suggestions are always welcome and thank you again. that answer was very simple. I will be checking out tiig as well
  2. Hello, I have started a DB for simple web based inventory system, I have only dabbled in PHP before 6 weeks ago, within the last 6 weeks with some help and going through countless tutorials and asking questions when I need. At this time setup an insert, delete and update function for this db and are working perfectly, now what I need to know is there a way to display something like 'in stock' and 'out of stock' using php, based on the value of the quantity in my db next to the item in a table? Example : when the table is generated it will display: | Part number | Description | Stock | (normally Stock would show the quantity of each part, I just wish to |10-1111 | Some info | In Stock | display In or out os stock) |10-1112 | Some Info | Out of Stock | I the only code I have is the tables and just not sure what to do next to get the results I have described above. So I will include the table code I have and see where we can go from there. Or if you have some webs site that I can read through that will be great as well as long as it can give me basic instruction on how to do this. Reminder, I am self taught and still learning. <?php $con = mysqli_connect("localhost","user","pass","part_inventory"); // Check connection if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { $result = mysqli_query($con, "SELECT * FROM amp20"); echo "<table border='1'> <tr> <th>ID</th> <th>Part number</th> <th>description</th> <th>location</th> <th>Quantity</th> </tr>"; while ($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['amp20ptid'] . "</td>"; echo "<td>" . $row['partnum'] . "</td>"; echo "<td>" . $row['description'] . "</td>"; echo "<td>" . $row['location'] . "</td>"; echo "<td>" . $row['quantity'] . "</td>"; echo "</tr>"; } echo "</table>"; mysqli_close($con); } ?>
  3. Nope it was a typo, but thanks for catch it. Same times I rush and i need to tell my self to slow down. I have change to using the echo thank you again
  4. Yeah, my grammar is not the best, I live with someone that can correct it for me if I make a mistake, she calls her self a "spelling and grammar nazi". what would you suggest to replace the printf? and i did correct the grammar issue, thanks for pointed that out.
  5. I did look at it again and completed WHERE claues, which didnt make a difference and also took out the query completely, which also didnt make a difference. And either way it didnt post any errors. As for the semi-colon, it was an extra and it did fixs the end result of the code, I totally missed it. I do appreciate your help. here is the end code and as i have stated its working as it should. <?php $con = mysqli_connect("localhost","scottk","ct@1446SA","part_inventory"); // Check connection if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { // escape variables for security $amp20ptid = mysqli_real_escape_string($con, $_POST['amp20ptid']); //delete Entry from db $sql = ("DELETE FROM amp20 WHERE amp20ptid = '$amp20ptid'"); if (!mysqli_query($con, $sql)) { die('Could not delete data: ' . mysqli_error($con)); } echo "Part has been deleted to the database!!!\n"; mysqli_close($con); } ?>
  6. I just seen where I was to do the code foramting apologize, ok here is the working codes all is deleting and as you can see the ';' was removed and all is working as it should. Also i did find the code format button, again I do apologize and i did try to edit the post before you replyed states I didnt use code formate but I was to late. <?php $con = mysqli_connect("localhost","scottk","ct@1446SA","part_inventory"); // Check connection if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { $result = mysqli_query($con, "SELECT FROM amp20 WHERE amp20ptid"); // escape variables for security $amp20ptid = mysqli_real_escape_string($con, $_POST['amp20ptid']); //delete Entry from db $sql = ("DELETE FROM amp20 WHERE amp20ptid = '$amp20ptid'"); if (!mysqli_query($con, $sql)) { die('Could not delete data: ' . mysqli_error($con)); } echo "Part has been deleted to the database!!!\n"; mysqli_close($con); } ?>
  7. Here is the working code. <?php $con = mysqli_connect("localhost","user","password","part_inventory"); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { $result = mysqli_query($con, "SELECT FROM amp20 WHERE amp20ptid"); // escape variables for security $amp20ptid = mysqli_real_escape_string($con, $_POST['amp20ptid']); //delete Entry from db $sql = ("DELETE FROM amp20 WHERE amp20ptid = '$amp20ptid'"); if (!mysqli_query($con, $sql)); //{ // die('Could not delete data: ' . mysqli_error($con)); //} echo "Part has been deleted to the database!!!\n"; mysqli_close($con); } ?>
  8. To answer youe list, 1 yes it does work or i would be getting an error unable to connect 2 i have changed the code to $result = mysqli_query($con, "SELECT FROM amp20 WHERE amp20ptid"); instead of $result = mysqli_query($con, "SELECT * FROM amp20 "); made no difference. 3- that is correct 4 - i see what your saying i have changes mysqli_query($con, "DELETE FROM amp20 WHERE amp20ptid = '$amp20ptid'"); to $sql = ("DELETE FROM amp20 WHERE amp20ptid = '$amp20ptid'"); which still deletes entry in DB either way but the error has gone, it now states that the entry was not removed, but it is gone from the DB 5- if you are talking about $amp20ptid = $_POST['amp20ptid']; i have removed it completely and still still removed the entry What this is for is deleteing a row from the db, not with all this changes, it states that the entry was not deleted but the row is gone from the db has intended. Also if i remove the: { die('Could not delete data: ' . mysqli_error($con)); } it continues to the : echo "Part has been deleted to the database!!!\n"; mysqli_close($con); } and the row is gone as well so i dont know
  9. Ok this is puzzleing. I am geting "Could not delete data: 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 '1' at line 1". but its is deleting the entry that needs to be removed. The "1" is the entry. Just not sure what is causing the error. I do have another delete php but I have put that on the back burning for the time being. <?php $con = mysqli_connect("localhost","user","password","part_inventory"); // Check connection if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { $result = mysqli_query($con, "SELECT * FROM amp20 "); $amp20ptid = $_POST['amp20ptid']; // escape variables for security $amp20ptid = mysqli_real_escape_string($con, $_POST['amp20ptid']); mysqli_query($con, "DELETE FROM amp20 WHERE amp20ptid = '$amp20ptid'"); if (!mysqli_query($con, $amp20ptid)); { die('Could not delete data: ' . mysqli_error($con)); } echo "Part has been deleted to the database!!!\n"; mysqli_close($con); } ?>
  10. I have 2 issues happening, first one I need to get resolved is, line 60 is giving me a 'Notice: Undefined variable: delete'. This codes had multi issues but was able to resolve all but this one and my table not filling in with the data from my database. If you need any other info please let me know, Again I am new at this. <tr> <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete value="delete"></td> </tr> <?php // Check if delete button active, start this *line 60* -----> if ($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM $tbl_name WHERE id='$del_id'"; $result = mysqli_query($sql); } // if successful redirect to delete_multiple.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\">"; } } mysqli_close($con); ?>
  11. Sorry for admitting a mistake is practicing deceit, its fixed now can we please move on
  12. Ok yeah i know what I did, I coped and paste from an old file, this is what should have been pasted: "die('Could not enter data: ' . mysqli_error($con));" is what should have been pasted and because it looks like i had the mix of mysql and mysqli. but i am just glad its fixed none the less, and yes that is very possible when i was coding i could have missed the "i"
  13. I just got it fixed: Old code - die('Could not enter data: ' . mysql_error()); new code - die('Could not enter data: ' . mysql_error($con)); then change : old code - $sql = "INSERT INTO 'part_inventory' . 'amp_20' ('amp20ptid', 'partnum', 'description', 'location', 'quantity') to new code - $sql = "INSERT INTO amp20 (amp20ptid, partnum, description, location, quantity) i was able to put 2 new entries in to my data base.
  14. the thing is we i have giving you the form code as well as the php code and there is nothing more I can give you but what I am running, I just dont know what else to give you, I have the php the pulls from my data base without issue working, I have even taken out the php code out of the main page just to see if that was causing my issues, and i was then starting to see error once that was cleaned up and it was saying "Entered data successfully" it stilll was not updating the database, I will put the php code in was I have now. but this will be what is showing "Entered data successfully". If you need my form code please let me know: <?php $con = mysqli_connect("localhost","user","password","part_inventory"); // Check connection if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { $result = mysqli_query($con, "SELECT * FROM amp20"); // escape variables for security $amp20ptid = mysqli_real_escape_string($con, $_POST['amp20ptid']); $partnum = mysqli_real_escape_string($con, $_POST['partnum']); $location = mysqli_real_escape_string($con, $_POST['location']); $quantity = mysqli_real_escape_string($con, $_POST['quantity']); $sql = "INSERT INTO 'part_inventory' . 'amp_20' ('amp20ptid', 'partnum', 'description', 'location', 'quantity') VALUES('$amp20ptid', '$partnum', $_POST[description], '$location', '$quantity');"; if(! $result) { die('Could not enter data: ' . mysql_error()); } echo "Entered data successfully\n"; mysqli_close($con); } ?>
  15. I do appalogize to all for wastinbg your time, with my poor exuse for scripting as i states i am new at php, but after seeing that I could add a hardcodrd values to my data base and my form inputs would not work no matter what I did, I have even tried a rescripted version still did not work, I do want to thank all that tried to help, wont be bothering you all with my scripts thank you
  16. this is the only code i have to input the data to my DB and all the code i pasted is the html inputs and the PHP coding there is nothing more that handles the inputs, but here is just the php script : <?php error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); $con=mysqli_connect("localhost","scottk","ct@1446SA","part_inventory"); // Check connection if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); // escape variables for security $amp20ptid = mysqli_real_escape_string($con, $_POST['amp20ptid']); $partnum = mysqli_real_escape_string($con, $_POST['partnum']); $discription = mysqli_real_escape_string($con, $_POST['description']); $location = mysqli_real_escape_string($con, $_POST['location']); $quantity = mysqli_real_escape_string($con, $_POST['quantity']); $sql = "INSERT INTO amp_20 (amp20ptid, partnum, description, location, quantity) VALUES ('$amp20ptid', '$partnum', '$description', '$location', '$quantity')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } mysqli_close($con); } ?>
  17. Yes it is what i first typed, the description typo/misspelling was fixed but still not getting errors nor is it adding to the database like it should, i am feeling like its somethiung i am missing or something simple, but i will double check all the spelling and for typos
  18. <?php error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); // define variables and set to empty values $amp20ptidErr = $partnumErr = $locationErr = $quantityErr = ""; $amp20ptid = $partnum = $description = $location = $quantity = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["amp20ptid"])) { $amp20ptidErr = "ID is required."; } else { $amp20ptid= test_input($_POST["amp20ptid"]); } if (empty($_POST["partnum"])) { $partnumErr = "Part number is required."; } else { $partnum = test_input($_POST["partnum"]); } if (empty($_POST["description"])) { $descriptionErr = ""; } else { $description = test_input($_POST["description"]); } if (empty($_POST["location"])) { $locationErr = "A location is required."; } else { $location = test_input($_POST["location"]); } if (empty($_POST["quantity"])) { $quantityErr = "Quantity is required"; } else { $quantity = test_input($_POST["quantity"]); } } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <div id="update_form"> Please follow instructions for updating the data base.<br> 1 - Please use the part number for the ID ie. part number is 20-1234, remove the hypen, so ID would be 201234, if it has been duplacted, message will show, <br>if this is the case add a 1 or next avalible number of greater value, ID can be no longer then 11 numbers.<br/>2 - Must put ONLY numbers in the Part ID section, please use numeric values for letters, IE. a=1, b=2, c=3, etc. No hyphens, commas or period can be used!<br/> 3- All field MUST be filled out or you will get an error. The description can be lefts without any infomation in it but it is advised to enter a description before submiting.<br> <table><tr><form method="POST" action="addnewpart.php"> <td>ID: <input name="amp20ptid" type="text" value = ""><span><?php echo $amp20ptidErr; ?></span><br/><br/></td> <td>Part Number: <input name="partnum" type="text" value = ""><span><?php echo $partnumErr; ?></span><br/><br/></td> <td><label>Description: <textarea name="description" rows="1" col="1" ></textarea><br/><br/></td> <td>Location: <input name="location" type="text" value = ""><span><?php echo $locationErr; ?></span><br/><br/></td> <td>Quantity: <input name="quantity" type="text" value = ""><span><?php echo $quantityErr; ?></span><br/><br/></td><br/> <td><input type="submit" value="Submit form"></td> </form></tr></table> <?php error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); $con=mysqli_connect("localhost","scottk","ct@1446SA","part_inventory"); // Check connection if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); // escape variables for security $amp20ptid = mysqli_real_escape_string($con, $_POST['amp20ptid']); $partnum = mysqli_real_escape_string($con, $_POST['partnum']); $discription = mysqli_real_escape_string($con, $_POST['description']); $location = mysqli_real_escape_string($con, $_POST['location']); $quantity = mysqli_real_escape_string($con, $_POST['quantity']); $sql = "INSERT INTO amp_20 (amp20ptid, partnum, description, location, quantity) VALUES ('$amp20ptid', '$partnum', '$description', '$location', '$quantity')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } mysqli_close($con); } ?>
  19. there is no messages at all it like the inputed data is getting lost, as for the data being pulled from the database there are no issues and its pulling 100% correct, it just not adding new data from the input form.
  20. yes and when I do get an error it gives me line and what is expected, also the editor I am using also read flag bad syntax, and no errors what so ever has shown at this time.
  21. I have now after looking at it Ginerjm, i was missing the value in the html part and that was corrected and still no change still not inputing data to database and creating a new row
×
×
  • 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.