falkencreative Posted January 30, 2009 Report Share Posted January 30, 2009 If you are using the above code, as I said earlier in this thread, the first thing you need to change the $_POST to a $_GET. Make the change, post your revised code, and let me know if that fixes it. Quote Link to comment Share on other sites More sharing options...
phpboy Posted January 30, 2009 Author Report Share Posted January 30, 2009 in my above codes i just change the $_POST to $_GET.... and nothing changed.. it just shows the tables but doesnt deleted the item.. i think there's something to changed a lot there.. ty Quote Link to comment Share on other sites More sharing options...
falkencreative Posted January 30, 2009 Report Share Posted January 30, 2009 Usually if a SQL query isn't working the way it is supposed to (and assuming I'm not getting any PHP errors) I open up PHPMyAdmin and plug the query directly into the SQL tab. -- it'll show the SQL errors and I have a better idea of what's going on. Quote Link to comment Share on other sites More sharing options...
phpboy Posted January 30, 2009 Author Report Share Posted January 30, 2009 i think theres something wrong here at my deleteben2.php $sql="DELETE FROM tablelibrary WHERE (id)='$_POST[id]'"; is this ryt connected the links in my deleteben.php? echo ' delete'; Quote Link to comment Share on other sites More sharing options...
phpboy Posted January 30, 2009 Author Report Share Posted January 30, 2009 bro, supposetedly my deleteben1.php is right? how will you make my deleteben2.php....(after accessing your php now.. ) what will be your codes... database name: library table name : tablelibrary id,Books,Name,Author(columns) Using only the default username and password for connecting php to sql.. after deleting of items, show directly to the deleteben.php.. and keep on processing.... I'll be waiting bro..go to go school right now....see you later with your codes hehe ty Quote Link to comment Share on other sites More sharing options...
falkencreative Posted January 30, 2009 Report Share Posted January 30, 2009 Here is the fixed version... -- there were some PHP errors that should have been showing up for you when you ran the code... were you seeing any errors? If not, you probably should edit your PHP's .ini file and turn error reporting on. If you need instructions, just do a web search for "PHP turn error reporting on .ini". Errors: -- In deleteben.php: this line " echo ' delete';" used $row['Id'] (uppercase "i" -- this is case sensitive, so it was showing an error, and wasn't passing the id via the link correctly)-- deleteben2.php: I created an $id variable and used that to get the $_GET data, rather than putting it directly in the SQL query, since that didn't appear to work. I used the database you provided, so that should be fine. deleteben.php: > $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("library", $con); $sql="SELECT * FROM tablelibrary"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } $result = mysql_query("SELECT * FROM tablelibrary"); echo "</pre> <table border="1"> Name Author Number of Books "; while($row = mysql_fetch_array($result)) { echo ""; echo "" . $row['Name'] . ""; echo "" . $row['Author'] . ""; echo "" . $row['Books'] . ""; echo 'delete'; echo ""; } echo "</table>";<br>?> deleteben2.php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("library", $con); $id = $_GET['id']; $sql="DELETE FROM tablelibrary WHERE (id)='$id'"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } header("Location: deleteben.php"); ?> And, as a side note, you probably should be using the PHP function is_numeric() to check that the id variable that is being pulled from the url is valid. You wouldn't want someone else putting their own data in the url and potentially messing things up for you. http://us.php.net/is_numeric Quote Link to comment Share on other sites More sharing options...
falkencreative Posted January 30, 2009 Report Share Posted January 30, 2009 And, also, you probably want to go through the videos on killerphp.com and at least the free videos on http://www.phpvideotutorials.com to help improve your coding. You could be using constants, includes and functions that will result in cleaner code and quicker development for you. Quote Link to comment Share on other sites More sharing options...
phpboy Posted January 30, 2009 Author Report Share Posted January 30, 2009 ty bro.. got it working just easy as that codes!!! i'll try to watch those videos... ty again .. Quote Link to comment Share on other sites More sharing options...
phpboy Posted February 2, 2009 Author Report Share Posted February 2, 2009 (edited) bro, i havent finished watching those videos... but bro can u give me your codes in "UPDATES" for my database? i thing the number of books column will i just make for updates ryt? i have finished the registration form and now working on my search page.. bro i am just confused how i will do it..or how to do it clearly... bro one more time this would be the last.... ty again bro.. Edited February 2, 2009 by phpboy Quote Link to comment Share on other sites More sharing options...
phpboy Posted February 3, 2009 Author Report Share Posted February 3, 2009 i wish some one help me >_ Quote Link to comment Share on other sites More sharing options...
falkencreative Posted February 3, 2009 Report Share Posted February 3, 2009 bro, i havent finished watching those videos...but bro can u give me your codes in "UPDATES" for my database? i thing the number of books column will i just make for updates ryt? i have finished the registration form and now working on my search page.. bro i am just confused how i will do it..or how to do it clearly... bro one more time this would be the last.... ty again bro.. Sorry, either I didn't see this earlier or I just forgot to reply... Not sure which. Look, I try to help out wherever I can, but I don't usually write people's code for them. I think I have gotten you started, and I have written more code than I usually do -- either someone else can take over and help you further, or you can read/watch tutorials on the subject and learn from them. You won't actually learn anything if everyone does everything for you. Tizag's PHP/MySQL sections probably have everything that you will need to know to do what you are attempting (http://www.tizag.com/mysqlTutorial/index.php). Just take a look at the section on "MySQL - Update" and it will explain the basic syntax you'll need to know. Basically, you can do your update statement similarly to the same way that I showed you how to do the delete statement... You'll have a form which allows users to update the entry, it'll pass the data to an update file, using POST to grab the data, update the database, and then redirect back to the previous page when everything is done. Realistically, although I am here to help, I am not here to do everything for you. You aren't going to learn PHP that way, and one of the most valuable things you can learn (as I wrote about recently on my blog) was how to understand and troubleshoot errors in your code. The resources are out there -- I've provided links to several, and the video tutorial link was especially important in getting me started -- but it will mean a little work and experimenting to understand it. Learning something like PHP isn't necessarily difficult, but it does take time, and you really have to do it yourself to understand it. Quote Link to comment Share on other sites More sharing options...
phpboy Posted February 3, 2009 Author Report Share Posted February 3, 2009 ok bro... i am just pressured to finished it this week that's why i ask for your codes But then i am watching those videos right now... and also the links you gave a while ago.. ty for advice bro.. Quote Link to comment Share on other sites More sharing options...
phpboy Posted February 3, 2009 Author Report Share Posted February 3, 2009 Number: Quote Link to comment Share on other sites More sharing options...
falkencreative Posted February 3, 2009 Report Share Posted February 3, 2009 I'm not totally sure what you are doing... wouldn't you want your edit page allow users to edit the book's details? Title, description, that sort of thing? I'm guessing you are trying to add to/remove an item for the total number of a certain title of book? I haven't tested this, but I don't believe you can do something like this: Books = Books+$add I'm pretty sure you need to get the books value first, add to it, and then include the total in your update statement. Also, this doesn't make much sense: where Name=NAme AND Author=Author remember "Name" does not equal "NAme", and don't the second instance of "Name" and "Author" need to be grabbed using $_POST or $_GET? MySQL won't know what "Name" and "Author" are supposed to equal to unless you provide it some input. Quote Link to comment Share on other sites More sharing options...
phpboy Posted February 3, 2009 Author Report Share Posted February 3, 2009 yes bro... i have there form which a user can add/subtract number of books and go to my updateneil2.php the problem is my update code.. i try to delete those codes where Name=NAme AND Author=Author but still "cannot update" which means my sql query is wrong.. Quote Link to comment Share on other sites More sharing options...
phpboy Posted February 4, 2009 Author Report Share Posted February 4, 2009 ok... i'll try to change my updateform.html to updateform.php updateform.php <?php print '';$x = $_GET['number']; echo ''; print 'Number: '; print ''; print '';?> then my updateneil2.php: <?php $conn=mysql_connect("localhost","Root",""); mysql_select_db("library") or die("unable to connect"); $old_number=$_POST['oldnumber']; $new_number=$_POST['number']; mysql_query("UPDATE tablelibrary SET Books='$new_number' where name='$old_number'") or die("ERROR:mysql_error()); header("Location: updateneil.php"); ?> I just want to have a form in every row in my updateneil.php then in that form (updateform.php) the number entered there would be updated to my updatedneil2.php and then back to the page updateneil.php.. But still that isn't work out.. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted February 4, 2009 Report Share Posted February 4, 2009 The problem with your above code -- most likely -- is the single quotes surrounding the variables in the update statement. If I remember correctly, PHP does not parse anything inside single quotes, so it treats '$test' as a string with the text "$test" inside of it, rather than the $test variable. Try this: mysql_query("UPDATE tablelibrary SET Books=$new_number where name=$old_number") or mysql_query("UPDATE tablelibrary SET Books='" . $new_number . "' where name=" . $old_number . "'") also realize that your tables are case sensitive, so "Books" is not the same as "books". You need to be consistent. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.