Jump to content

MySQL issues


rdwinder

Recommended Posts

Hey Guys

 

Im having some problem with my MYSQL, Here is the source code for my content

 

<?php
    $db = new sql();
    $id = $_GET['edit'];

    $db->sql_query("SELECT * FROM `content` WHERE `id` = '$id'");
    $mysql_array = $db->fetch_array();
    
    ?>
    
    <form id="form2" name="form1" method="post" onsubmit="return submitForm();" action="?content&update=<?php echo $_GET['edit']; ?>">
      <p> Page name<br />
        <span id="sprytextfield2">
        <input name="name" type="text" value="<?php echo $mysql_array['pagename']; ?>" id="name" size="85" />
        <span class="textfieldRequiredMsg">A value is required.</span></span></p>
      <p>Page content<br />
          <script language="JavaScript" type="text/javascript">

            //<!--

            //Usage: writeRichText(fieldname, html, width, height, buttons, readOnly)

            writeRichText('rte1', '<?php echo rteSafe($mysql_array['content']); ?>', 760, 500, true, false);

            //-->

      </script>
          <br />
          <input type="submit" name="button2" id="button2" value="Submit" />
      </p>
    </form>

 

Here's the "IF" to see when to update the database.

 

if (isset($_GET['update']))
{
    echo updateContent($_POST['name'], $_POST['rte1'], $_GET['update']);
    echo "updating";
}

 

This is my update function

 

    function updateContent($pgname, $content, $id)
    {
        $db = new sql();
        $db->sql_query("UPDATE `content` SET `pagename` = '$pgname',
                                             `content` = '$content' WHERE `id` = '$id'");
        echo mysql_error();

    }

 

Now when i submit the data, the database has no record of my data, i have uploaded my code to my webserver and it seems to do it there too..

 

Please help me i am SO  ???ed

 

Thanks,

Richard

Link to comment
Share on other sites

hey richard

 

we have no idea what the $db object is, now if we take your word for the fact that it works correctly why do you create another object for the update function...? but i guess that is how this object works...

 

now after all these that may not be wrong where do you submit the data to the db update is used to alter already existing records in the db...

Link to comment
Share on other sites

Have you tried to echo the parameters to see if the variables are even getting set before calling the function?

 

<?php
function updateContent($pgname, $content, $id) {
 
 echo $pagname . '<br />';
 echo $content . '<br />';
 echo $id;

 $db = new sql();
 // Always add error handling
 $result = $db->sql_query("UPDATE `content` SET `pagename` = '$pgname', `content` = '$content' WHERE `id` = '$id'") or trigger_error(mysql_error()); 

 if($result) 
   return $result;
 else
   return false;

}

// Then when calling your function use a condition with error handling

if(updateContent($_POST['name'], $_POST['rte1'], $_GET['update'])) {
 echo 'Updating...';
else
 echo 'Could not update!';

?>

Link to comment
Share on other sites

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.