Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

Post update form [not working]

Links for php scripts

Moderators: macek, egami, gesf

Post update form [not working]

Postby andor1995 » Mon Jan 23, 2012 8:32 am

Hey, I started to make a cms by following a tutorial. I did everything the same way as the person in the video, but my function update_content_form($id) doesn't works. I should pull out the title and the body from the mysql database but it doesn't pulls out anything.

Here is the function code:
Code: Select all
function update_content_form($id) {
      $id = mysql_real_escape_string($id);
      $res = mysql_query("SELECT * FROM posts WHERE id = '$id'") or die(mysql_error());
      $row = mysql_fetch_assoc($res);
      
      
      ?>
        <form method="post" action="index.php">
        <div>
       <input type="hidden" name="update" value="true" />
        <input type="hidden" name="id" value="<?=$row['$id']?>" />
       <div>
       <label for="title">Title</label>
        <input type="text" name="title" id="title" value="<?=$row['title'];?>" />
       </div>
        <div>
        <label for="body">Body</label>
        <textarea name="body" id="body"  rows="8" cols="49"><?=$row['body']?></textarea>
        </div>
       
        <input name="submit" type="submit" value="Update Article" />
        <?
      }


Can anyone help me?
andor1995
New php-forum User
New php-forum User
 
Posts: 15
Joined: Mon Jan 09, 2012 11:39 pm

Re: Post update form [not working]

Postby andor1995 » Mon Jan 23, 2012 8:58 am

The $id is the id of the post. Like index.php?id=23 in this case the $id = '23' but it's different for each post.

this is how it is called on the page:

Code: Select all
  <?=$obj->update_content_form($_get['$id'])?>


And sorry for 2x posting.
andor1995
New php-forum User
New php-forum User
 
Posts: 15
Joined: Mon Jan 09, 2012 11:39 pm

Re: Post update form [not working]

Postby egami » Mon Jan 23, 2012 9:03 am

index.php?id=23 is a _GET and not a _POST
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Post update form [not working]

Postby egami » Mon Jan 23, 2012 9:04 am

and I was severly wrong about preg_replace. it's actually twice as slow as mysql_real_escape_string.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Post update form [not working]

Postby andor1995 » Mon Jan 23, 2012 9:07 am

No, you miss understood it. the index.php?=id=23 is the posts ID. But that form should get that id in the post_update_form at the $id so it selects that row which contains the title and body for that post.
andor1995
New php-forum User
New php-forum User
 
Posts: 15
Joined: Mon Jan 09, 2012 11:39 pm

Re: Post update form [not working]

Postby egami » Mon Jan 23, 2012 9:08 am

php index.php
You finished in 0.86043405532837 time!

-- This was 1,000,000 times a loop of (The quick brown fox jumped over the lazy dog 99)
using mysql_real_escape_string.


and

php index.php
You finished in 1.1681349277496 time!

using preg_replace();
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Post update form [not working]

Postby egami » Mon Jan 23, 2012 9:09 am

<?=$obj->update_content_form($_get['$id'])?>


should be..


<?=$obj->update_content_form($_GET['id'])?> // notice the CaSe and lose the $ in id.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Post update form [not working]

Postby andor1995 » Mon Jan 23, 2012 9:10 am

M8, my problem is not with that... my problem is that this form should pull out information from the MYSQL database... What is so hard to understand?
andor1995
New php-forum User
New php-forum User
 
Posts: 15
Joined: Mon Jan 09, 2012 11:39 pm

Re: Post update form [not working]

Postby egami » Mon Jan 23, 2012 9:14 am

Listen,

Since you're obviously stuck on the fact that you're right, and I'm not, but you're the one asking for help.. You can either take my advice, or go for a long walk off of a short pier.

The issue is that your function is not getting a properly formatted ID number as I stated before. the _get is NOT _GET. and [$id] is not defined, but $_GET['id'] is. So, you can try the change I suggested, or you can keep asking for help, but everyone else here will ___most___ likely, say the same thing.


Thanks, and have a wonderful day.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Post update form [not working]

Postby andor1995 » Mon Jan 23, 2012 9:16 am

I'm sorry for being such an idiot. I tried it that way many times and it didn't worked. it works now. Thanks for your help :) and sorry again
andor1995
New php-forum User
New php-forum User
 
Posts: 15
Joined: Mon Jan 09, 2012 11:39 pm


Return to PHP Scripts

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron