Jump to content
Killersites Forums

guys need help with Wampserver


phpboy
 Share

Recommended Posts

  • Replies 106
  • Created
  • Last Reply

Top Posters In This Topic

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

Link to comment
Share on other sites

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>?&gt

 

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

Link to comment
Share on other sites

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 by phpboy
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share


×
×
  • Create New...