Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Need help with Updating data in a Table...
Old 11-29-2009, 01:32 PM Need help with Updating data in a Table...
Junior Talker

Posts: 4
Trades: 0
Hello All,

I am a total noob, and I have been reading several threads, and I'm still stumped. I am hoping someone can help this 'old Marine, learn something new.

I am trying to create something simple, the Table has the following columns
ID, set to autonumber, Name, PicUrl, Description.

I would like to be able to update a record. For example I need to change the Description, or Name or even add a PicUrl. Below is what I have come up with so far.

Code:
<?php
$dbc = mysqli_connect("localhost","uname","pword","dbase");

$Name = $_POST['Name'];
$query = "UPDATE FROM table SET field1='$Name', field2='$PicUrl', field3-'$Description WHERE id='$_GET(Name)'";
$result = mysqli_query($dbc, $query);
echo 'Anime Updated: ';
mysqli_close ($dbc);
?>
I know I have to create an html form to point to the "Table", which I did, but not sure how to have it show the show the records before, and after the edit.

Any help, anyone could provide would be greatly appreciated.
__________________
-Semper Fi
gyrene2083
gyrene2083 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-29-2009, 07:50 PM Re: Need help with Updating data in a Table...
Extreme Talker

Posts: 181
Name: David Jackson
Trades: 0
where you have

PHP Code:
 WHERE id='$_GET(Name)'"; 
that is wrong

try

PHP Code:
$id$_GET[id]; //<< your querystring needs to contain.... id={num}



$query "UPDATE FROM table SET field1='$Name', field2='$PicUrl', field3-'$Description WHERE id='$id'"
i am asuming you are just passing an id and catching it in your GET so make sure you name it correctly

also

you are performing an UPDATE therefore there is nothing to return so you dont need..

PHP Code:
$result mysqli_query($dbc$query); 
this will do
PHP Code:
mysqli_query($dbc$query
__________________

Please login or register to view this content. Registration is FREE

Last edited by davidj; 11-29-2009 at 07:57 PM..
davidj is offline
Reply With Quote
View Public Profile
 
Old 11-29-2009, 08:04 PM Re: Need help with Updating data in a Table...
Junior Talker

Posts: 4
Trades: 0
davidj.

Thanks for the response. Seems I tried the suggestions but the table doesn't seem to be updating. I'm not getting an error msg., but I'm not getting any further either.

Could it be the HTML form?
__________________
-Semper Fi
gyrene2083
gyrene2083 is offline
Reply With Quote
View Public Profile
 
Old 11-30-2009, 02:02 AM Re: Need help with Updating data in a Table...
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Your query has some errors. Try this
PHP Code:
"UPDATE table SET field1='$Name', field2='$PicUrl', field3='$Description' WHERE id=$id
Also, make sure that all the variables exists, since we can't see them being created in your code above.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 11-30-2009, 07:10 AM Re: Need help with Updating data in a Table...
Junior Talker

Posts: 4
Trades: 0
Lizciz,

I tried what you said, and the same thing occurs. Here is what I have after, the modifications, also I'm going to post the HTML form I made. Nothing fancy, just something small.

Code:
<?php
$dbc = mysqli_connect("localhost","username","password","database");

$Name = $_POST['Name'];
$query = "UPDATE Downloads SET field1='$Name', field2='$PicUrl', field3='$Description' WHERE id=$id";  
mysqli_query($dbc, $query);
echo 'Anime Updated: ';
mysqli_close ($dbc);
?>
HTML

Code:
<html>
    <head>
        <title>Anime Update</title>
        <style type="text/css">
        body {
                background-color: #fffff;
                margin-left: 15%;
                margin-right: 15%;
                border: 1px solid gray;
                padding: 10px 10px 10px 10px;
                font-family: baar-sophia;
              }
    </style>
    </head>
    
<body>

    <p>Anime Update</p>
    <form method="post" action="112609Update.php">
    <label for="Name">Anime Name:</label>
    <input type="text" id="Name" name="Name" /><br />
    <label for="PicUrl">Picture Url:</label>
    <input type="text" id="Picture Url" name="PicUrl" /><br />
    <label for="Description">Description:</label>
    <input type="text" id="Description" name="Description" /><br />
    <input type="submit" value="Update" name="submit" />
    </form>
</body>
</html>
Not sure if you need this information, but here goes;
ID - int - autoincrement
Name - Varchar
PicUrl - Varchar
Description - Text

I sincerely appreciate all your help. I even went out and bought a book "Head First - PHP & MySql". I am reading threads, and I've been to W3Schools site as well, trying to understand the code.
__________________
-Semper Fi
gyrene2083
gyrene2083 is offline
Reply With Quote
View Public Profile
 
Old 11-30-2009, 09:49 AM Re: Need help with Updating data in a Table...
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
If that is all the code you use, it's no wonder it doesn't work, since the variables $PicUrl, $Description and $id doesn't exist. Then php will treat them as empty, so your query really says

PHP Code:
"UPDATE table SET field1='$Name', field2='', field3='' WHERE id=" 
You need to get the url and description variables in the same manner as the name, and the id would normally come from a GET-variable, session or another database query, depending on what you're doing (probably a GET-variable though).
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 11-30-2009, 04:31 PM Re: Need help with Updating data in a Table...
Junior Talker

Posts: 4
Trades: 0
Ok I'm just stumped, and it's not for the sake of not trying. I looked up the GET variable, and changed the html from;

Code:
 <form method="post" action="112609Update.php">
to
Code:
 <form action="112609Update.php" method=GET>
I got that example from here . I also, tried to test out the way they did the .php file and I just kept getting errors. So, at this point, other than throwing my laptop against the wall, I'm hoping you guys can help me out. I appreciate all your patience.
__________________
-Semper Fi
gyrene2083
gyrene2083 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Need help with Updating data in a Table...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.30739 seconds with 12 queries