Jump to content

Recommended Posts

Im working on a database hosted by ipowerweb and I am having problems interacting with the database. I can view the data in the tables, delete the data, but I cant edit the data or add new data from my php form. I have used this script on other servers and it has worked like a champ. I called the host's tech support line and after 20 minutes of waiting they are saying its my script that has the problem. Im not an expert php programmer but this script works fine on my site that is hosted by another company. I gave the login im using full access to the database, but I still cant edit or add data to the table. Any suggestions?? :'(

Link to comment
https://forums.phpfreaks.com/topic/80659-solved-connection-problems-phpmysql/
Share on other sites

i use the same id/pw that gets me into phpMyAdmin in my script. the following script populates the text fields with the table data but when i make a change and submit the for after a second or so I get the "page cannot be found" error.

 

<html>
<head>
<link href="css/StyleSheet1.css" rel="stylesheet" type="text/css">
<body>
<!-- standard page header begins -->
<table width="100%" class="table1">
  <tr> 
    <td><div align="center" class="text2">EDIT NEWS ARTICLE</div></td>
  </tr>
</table>
<br>
<!-- standard page header ends -->

<?php
// includes
include('includes/PXS_Conf.php');
include('includes/PXS_Functions.php');

// form not yet submitted
// display initial form with values pre-filled
if (!$_POST['submit'])
{
     // check for record ID
     if ((!isset($_GET['id']) || trim($_GET['id']) == '')) 
     { 
         die('Missing record ID!'); 
     }

    // open database connection
    $connection = mysql_connect($host, $user, $pass) or die ('Unable to connect to MySql server!');

    // select database
    mysql_select_db($db) or die ('Unable to select database!');

    // generate and execute query
    $id = $_GET['id'];
    $query = "SELECT Title, Content FROM PXS_News WHERE id = '$id'";	
    $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
    
    // if a result is returned
    if (mysql_num_rows($result) > 0)
    {
        // turn it into an object
        $row = mysql_fetch_object($result);

        // print form with values pre-filled
?>
<table cellpadding="5" cellspacing="5" class="table1">
  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    <input type="hidden" name="id"  value="<?php echo $id; ?>">
    <tr> 
      <td valign="top"><b class="text5">Title</b></td>
      <td> <input name="Title" type="text" class="table2" id="Title" 
value="<?php echo $row->Title; ?>" size="50" maxlength="250"> </td>
    </tr>
    <tr> 
      <td valign="top"><b class="text5">Content</b></td>
      <td> <textarea name="Content" cols="47" rows="10" class="table2" id="Content"><?php echo $row->Content; ?></textarea> 
      </td>
    </tr>
    <tr> 
      <td colspan=2> <input type="Submit" name="submit" value="Update"> </td>
    </tr>
  </form>
</table>
<?php
    }
    // no result returned
    // print graceful error message
    else
    {
        echo 'That news article could not be located in the database';
    }
}
// form submitted
// start processing it
else
{
    // set up error list array
    $errorList = array();
    
    $title = ucfirst($_POST['Title']);
    $content = ucfirst($_POST['Content']);
    $id = $_POST['id'];
        
    // check for record ID
    if ((!isset($_POST['id']) || trim($_POST['id']) == '')) 
    { 
      die ('Missing record ID!'); 
    }

    // validate text input fields
    if (trim($_POST['Title']) == '') 
    { 
      $errorList[] = 'Please enter an article title'; 
    }
    
    if (trim($_POST['Content']) == '') 
    { 
      $errorList[] = "Please enter article content"; 
    }
    
    
    // check for errors
    // if none found...
    if (sizeof($errorList) == 0)
    {

        // generate and execute query
        $query = "UPDATE PXS_News SET Title = '$title', Content = '$Content' WHERE id = '$id'";
        $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());

        // close database connection
        mysql_close($connection);

        // print result
        echo '<center><a href=PXS_ListNews.php>Update successful click here to go back to the article list</a></center>';		
    }
    else
    {
        // errors occurred
        // print as list
        echo 'The following errors were encountered:'; 
        echo '<br>';
        echo '<ul>';
        for ($x=0; $x<sizeof($errorList); $x++)
        {
            echo "<li>$errorList[$x]";
        }
        echo '</ul>';
    }
}
?>
<!-- standard page footer begins -->
<br>
<table width="100%" class="table1">
  <tr> 
    <td><div align="center" class="text1"><font size="2">Copyright © 2006 
        All Rights Reserved </font></div></td>
  </tr>
</table>
  <!-- standard page footer ends -->
</body>
</html>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.