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"); 
    Great wit and madness are near allied, and fine a line their bounds divide.

  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



Recent Articles