Jump to content

using $_get and/or $_post


seany123

Recommended Posts

im getting slightly confused...

 

i have this textarea on my page and basically, when the submit button is clicked, i want for the text inside the textarea to be inserted into a database field "notepad".

 

<html>
<head>
<title>MafiaKillerz</title>
<link rel="stylesheet" href="/css/style.css" type="text/css" media="all" />
</head>
<body alink="#cc9900" vlink="#cc9900" link="#cc9900">

<div id="holder">
    </div>
    <div id="left_c"><div class="g_content">
      <h3 style="text-align: left">  Notepad</h3><div class="g_text">
<form action="notepad.php" method="post">
<BR><textarea name='notes' cols='70' rows='8'></textarea><br />
<br />
<br />
<input type='submit' name='update_notepad' value='Update'>
</form>

<?php
if($_GET['submit'])
{
$query = $db->execute("update `players` set `notepad`=? where `id`=?", array(, $player->id ));
}
?>

 

i dont know if ($_GET['submit']) is the correct way get the info....

 

 

its the php part where im getting confused... im not sure how i get the text from the textarea and use it in a query.

 

Link to comment
Share on other sites

well i thought that because notepad may already have a text in it, you would want to update it with the new text in the textarea.

 

and what would i put in the array part of this query?

 

$query = $db->execute("update `players` set `notepad`=? where `id`=?", array(, $player->id )); 

Link to comment
Share on other sites

The form method is post, so you should use $_POST and not $_GET.

 

Also, if you're inserting something, why are you using UPDATE?

Allow me to quote myself. In your form, you set the method to post, right? So why did you use $_GET in your if conditional instead of $_POST?

 

 

Link to comment
Share on other sites

First change to $_POST['update_notepad']

 

I always like to use the name of the submit button to check against.

 

Then for your DB, you need to INSERT, and if it's already there, then ON DUPLICATE KEY UPDATE...

 

This way if the record isn't there, you INSERT a new one, if it is, you just 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.