www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 21

Thread: PHP script problem.

  1. #1
    Join Date
    Sep 2006
    Posts
    17

    PHP script problem.

    I'm not sure where the error in these scripts are. Edit.php seems to work fine.
    The problem comes in at edit_form.php witch uses edit_data.php .

    There is 1 table field i dont have listed and it stores IP addresses.

    So can someone point out the error for me please.



    edit.php
    PHP Code:
    <html>
    <body>
    <table>
      <tr>
        <td align="center">EDIT DATA</td>
      </tr>
      <tr>
        <td>
          <table border="1">
          <?
          mysql_connect("localhost", "*****", "******") or die(mysql_error());
          mysql_select_db("*****") or die(mysql_error());

          $order = "SELECT id, eventname, host, time, date FROM event";
          $result = mysql_query($order);
            echo ("<tr> <th>Event Name</th> <th>Host</th> <th>Time</th> <th>Date</th> <th>Edit</th></tr>");
          while ($row=mysql_fetch_array($result)){
            echo ("<tr><td>$row[eventname]</td>");
            echo ("<td>$row[host]</td>");
            echo ("<td>$row[time]</td>");
            echo ("<td>$row[date]</td>");
            echo ("<td><a href=\"edit_form.php?id=$row[id]\">Edit</a></td></tr>");
          }
          ?>
          </table>
        </td>
       </tr>
    </table>
    </body>
    </html>
    edit_form.php
    PHP Code:
    <html>
    <head>
    <title>Form Edit Data</title>
    </head>

    <body>
    <table border=1>
      <tr>
        <td align=center>Form Edit Employees Data</td>
      </tr>
      <tr>
        <td>
          <table>
          <?
          mysql_connect("localhost", "******", "******") or die(mysql_error());
          mysql_select_db("******") or die(mysql_error());
          
          $order = "SELECT id, eventname, host, time, date FROM event 
    where id='$id'";
          $result = mysql_query($order);
          $row = mysql_fetch_array($result);
          ?>
          <form method="post" action="edit_data.php">
          <input type="hidden" name="id" value="<? echo "$row[id]"?>">
            <tr>        
              <td>Event Name</td>
              <td>
                <input type="text" name="eventname" 
            size="24" value="<? echo "$row[eventname]"?>">
              </td>
            </tr>
            <tr>
              <td>Host</td>
              <td>
                <input type="text" name="host" size="24" 
              value="<? echo "$row[host]"?>">
              </td>
            </tr>
                    <tr>
              <td>Time</td>
              <td>
                <input type="text" name="time" size="24" 
              value="<? echo "$row[time]"?>">
              </td>
            </tr>        
            <tr>
              <td>Date</td>
              <td>
                <input type="text" name="date" size="24" 
              value="<? echo "$row[date]"?>">
              </td>
            </tr>
            <tr>
              <td align="right">
                <input type="submit" 
              name="submit value" value="Edit">
              </td>
            </tr>
          </form>
          </table>
        </td>
      </tr>
    </table>
    </body>
    </html>
    Edit_data.php
    PHP Code:
    <?
    mysql_connect("localhost", "*****", "******") or die(mysql_error());
    mysql_select_db("******") or die(mysql_error());
    $order = "UPDATE event 
              SET eventname='$eventname', 
                    host='$host',
                time='$time',
                date='$date' 
              WHERE 
              id='$id'";
    mysql_query($order);
    header("location:edit.php");
    ?>

  2. #2
    Join Date
    Aug 2008
    Posts
    45
    I noticed in your <?php echo "...." ?> pieces, you don't have a semicolon after the echo statement, i.e. <?php echo "....";?>. Maybe that's it?

  3. #3
    Join Date
    Sep 2006
    Posts
    17
    I added semicolans to the echos on edit_form.php The script still isnt functioning corectly

  4. #4
    Join Date
    Aug 2006
    Location
    Michigan
    Posts
    1,046
    whats the error you get? also when you view the generate source, does it display correctly?

  5. #5
    Join Date
    Sep 2006
    Posts
    17
    There is no error, thats why it confuses me. Its just not editing the row at all. My Delete also is not working correctly. I cant figure out my problem because its not giving me a error message.


    Location: Here

  6. #6
    Join Date
    Aug 2006
    Location
    Michigan
    Posts
    1,046
    I do notice one thing that might be the cause, in all of your array calls you call them like this

    PHP Code:
    $row[eventname
    try this

    PHP Code:
    $row['eventname'
    I think you can only use the array variable without the quotes for numeric values like 0-9, not string values. they need to be in quotes.

    PHP Code:
    $row[1]

    // or

    $row[$i

  7. #7
    Join Date
    Sep 2006
    Posts
    17
    I tryed changing them like you said and it only gave me actual errors.

  8. #8
    Join Date
    Aug 2006
    Location
    Michigan
    Posts
    1,046
    what errors?

  9. #9
    Join Date
    Sep 2006
    Posts
    17
    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

    Was the error I received.

  10. #10
    Join Date
    Aug 2006
    Location
    Michigan
    Posts
    1,046
    Does it tell you what script the error is in? Line number?

    Could you repost your code for review?

  11. #11
    Join Date
    Sep 2006
    Posts
    17
    This is the edits you told me to make.

    Edit.php (Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/coders/public_html/phptesting/edit.php on line 22)
    PHP Code:
    <html>
    <body>
    <table>
      <tr>
        <td align="center">EDIT DATA</td>
      </tr>
      <tr>
        <td>
          <table border="1">
          <?
          mysql_connect("localhost", "coders_phptest", "051092") or die(mysql_error());
          mysql_select_db("coders_phptest") or die(mysql_error());

          $order = "SELECT id, eventname, host, time, date FROM event";
          $result = mysql_query($order);
            echo ("<tr> <th>Event Name</th> <th>Host</th> <th>Time</th> <th>Date</th> <th>Edit</th> <th>Delete</th></tr>");
          while ($row=mysql_fetch_array($result)){
            echo ("<tr><td>$row['eventname']</td>");
            echo ("<td>$row['host']</td>");
            echo ("<td>$row['time']</td>");
            echo ("<td>$row['date']</td>");
            echo ("<td><a href=\"edit_form.php?id=$row[id]\">Edit</a></td>");
            echo ("<td><a href=\"delete.php?id=$row[id]\">Delete</a></td></tr>");
          }
          ?>
          </table>
        </td>
       </tr>
    </table>
    </body>
    </html>
    edit_form.php (Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/coders/public_html/phptesting/edit_form.php on line 26)
    PHP Code:
    <body>
    <table border=1>
      <tr>
        <td align=center>Form Edit Employees Data</td>
      </tr>
      <tr>
        <td>
          <table>
          <?
          mysql_connect("localhost", "coders_phptest", "051092") or die(mysql_error());
          mysql_select_db("coders_phptest") or die(mysql_error());
          
          $order = "SELECT id, eventname, host, time, date FROM event 
    where id='$id'";
          $result = mysql_query($order);
          $row = mysql_fetch_array($result);
          ?>
          <form method="post" action="edit_data.php">
          <input type="hidden" name="id" value="<? echo "$row['id']"; ?>">
            <tr>        
              <td>Event Name</td>
              <td>
                <input type="text" name="eventname" 
            size="24" value="<? echo "$row['eventname']"; ?>">
              </td>
            </tr>
            <tr>
              <td>Host</td>
              <td>
                <input type="text" name="host" size="24" 
              value="<? echo "$row['host']"; ?>">
              </td>
            </tr>
                    <tr>
              <td>Time</td>
              <td>
                <input type="text" name="time" size="24" 
              value="<? echo "$row['time']"; ?>">
              </td>
            </tr>        
            <tr>
              <td>Date</td>
              <td>
                <input type="text" name="date" size="24" 
              value="<? echo "$row['date']"; ?>">
              </td>
            </tr>
            <tr>
              <td align="right">
                <input type="submit" 
              name="submit value" value="Edit">
              </td>
            </tr>
          </form>
          </table>
        </td>
      </tr>
    </table>
    </body>
    </html>
    edit_data.php
    PHP Code:
    <?
    mysql_connect("localhost", "coders_phptest", "051092") or die(mysql_error());
    mysql_select_db("coders_phptest") or die(mysql_error());
    $order = "UPDATE event 
              SET eventname='$eventname', 
                  host='$host',
                  time='$time',
                  date='$date' 
              WHERE 
              id='$id'";
    mysql_query($order);
    header("location:edit.php");
    ?>

    My delete is also malfunctioning. It doesnt delete at all

    delete.php
    PHP Code:
    <?

          mysql_connect("localhost", "coders_phptest", "051092") or die(mysql_error());
          mysql_select_db("coders_phptest") or die(mysql_error());
          
    $order = "DELETE FROM event 
              WHERE id='$id'";
    mysql_query($order);
    header("location:edit.php");
    ?>

  12. #12
    Join Date
    Aug 2007
    Posts
    3,767
    You have two extra brackets, maybe that's it.
    Code:
          mysql_connect("localhost", "coders_phptest", "051092") or die(mysql_error());
          mysql_select_db("coders_phptest") or die(mysql_error());
    Just one other point, echo shouldn't have brackets, it's not really a function. You are better off to use
    PHP Code:
    echo "string"
    than
    PHP Code:
    echo("string"); 

  13. #13
    Join Date
    Aug 2008
    Posts
    45
    I don't want to sound pedantic, but please proofread your code carefully when you make changes.

    Code:
            echo ("<td><a href=\"edit_form.php?id=$row[id]\">Edit</a></td>");
            echo ("<td><a href=\"delete.php?id=$row[id]\">Delete</a></td></tr>");
    You didn't add the apostrophes to the $row variables. Not surprisingly, this occurred on line 22.


    Are you posting the entirety of the edit_form.php? Line numbers don't help if we're not counting from the beginning of the file.

    Another thing - I'm assuming that you have other code somewhere because you never actually define $id, and you use it a few times in your code. Could that be a problem?

    One last thing -- if you accidentally forgot to star out your login information, I suggest you change it.

  14. #14
    Join Date
    Sep 2006
    Posts
    17
    Thats my whole code. and I added the thing to the cut out you posted.

    the errors started when i added the ' ' into my code other then that the script didnt function. and on edit.php id is a variable for my db table field
    Last edited by CA-Taylor; 08-22-2008 at 02:31 PM.

  15. #15
    Join Date
    Aug 2008
    Posts
    45
    What I meant was where is $id defined? I don't see a place where you put:

    PHP Code:
    $id /*something*/
    Is it part of a url query string (e.g. edit_form.php?id=MY_ID), because if so, you need to use $_GET["id"] instead of $id.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.18577 seconds
  • Memory Usage 3,042KB
  • Queries Executed 13 (?)
More Information
Template Usage (37):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (2)bbcode_code
  • (13)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (15)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (15)postbit
  • (15)postbit_onlinestatus
  • (15)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates