Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,679 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,202 people online right now. Registration is fast and FREE... Join Now!




Sending info via form

 
Reply to this topicStart new topic

Sending info via form

k0b13r
post 10 Aug, 2007 - 04:45 PM
Post #1


D.I.C Head

Group Icon
Joined: 18 Jul, 2006
Posts: 196



Thanked 1 times

Dream Kudos: 250
My Contributions


Hi. I have this code:
CODE

<?php
$note = mysql_fetch_row(mysql_query("SELECT MAX(id) FROM note"));
if ($note[0] == NULL)
{
    echo "Brak notek do modyfikacji!";
}
else
{
    echo '<form action="admin.php?x=edit" method="post">';
    echo "\n<select>\n";
    for($i = 1; $i <= $note[0]; $i++)
    {
        $title = mysql_fetch_row(mysql_query("SELECT title FROM note WHERE id = $i"));
        echo '<option name="'.$i.'">'.$title[0].'</option>'."\n";
    }
    echo '</select><br /><button type="submit">Wyślij</button><br />';
}
?>


I want to send $i [value of message ID] via this form, but I get errors, when I try to use it:
CODE

<?php
$edited = $_POST['i'];
$title = mysql_fetch_row(mysql_query("SELECT title FROM note WHERE id = $edited"));
$content = mysql_fetch_row(mysql_query("SELECT content FROM note WHERE id = $edited"));
$content = mysql_fetch_row(mysql_query("SELECT date FROM note WHERE id = $edited"));

if(isset($title) && isset($content))
{
    echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">
    <div>
    <table>
    <tr><td><input type="text" name="title" value="'.$title[0].'" size="40" /></td></tr>
    <tr><td><textarea name="content" cols="50" rows="15">'.$content[0].'</textarea></td></tr>
    <tr><td><input type="hidden" name="title" value="'.$date[0].'" size="19" /></td></tr>
    <tr><td><button type="submit">Wyślij</button></td></tr>
    </table>
    </div>
    </form>'."\n";
}
?>

My errors are:
CODE

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\wamp\www\blog\admin\edit.php on line 3

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\wamp\www\blog\admin\edit.php on line 4

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\wamp\www\blog\admin\edit.php on line 5


I don't know what's wrong confused.gif Thanks in advance for help

This post has been edited by k0b13r: 10 Aug, 2007 - 04:45 PM
User is offlineProfile CardPM

Go to the top of the page

MitkOK
post 10 Aug, 2007 - 05:39 PM
Post #2


D.I.C Regular

Group Icon
Joined: 9 Aug, 2007
Posts: 314



Thanked 12 times

Dream Kudos: 250
My Contributions


Hello.

First you can print $_POST value to see if it is set.

Second, if there's a value, quote the variable $edited :
CODE
$title = mysql_fetch_row(mysql_query("SELECT title FROM note WHERE id = '$edited'"));



- Mitko Kostov

This post has been edited by MitkOK: 10 Aug, 2007 - 05:43 PM
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 10 Aug, 2007 - 07:04 PM
Post #3


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,933



Thanked 118 times

Dream Kudos: 8525

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


I don't think you can use mysql_fetch_row that way, try this

CODE

<?php
$edited = $_POST['i'];
$temp = mysql_query("SELECT title FROM note WHERE id = $edited");
$title = mysql_fetch_row($temp);

$temp = mysql_query("SELECT content FROM note WHERE id = $edited");
$content = mysql_fetch_row($temp);

$temp = mysql_query("SELECT date FROM note WHERE id = $edited"))
$date = mysql_fetch_row($temp);

if(isset($title) && isset($content))
{
    echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">
    <div>
    <table>
    <tr><td><input type="text" name="title" value="'.$title[0].'" size="40" /></td></tr>
    <tr><td><textarea name="content" cols="50" rows="15">'.$content[0].'</textarea></td></tr>
    <tr><td><input type="hidden" name="title" value="'.$date[0].'" size="19" /></td></tr>
    <tr><td><button type="submit">Wyślij</button></td></tr>
    </table>
    </div>
    </form>'."\n";
}
?>


Hope this helps smile.gif

Happy Coding!
User is offlineProfile CardPM

Go to the top of the page

k0b13r
post 11 Aug, 2007 - 12:27 AM
Post #4


D.I.C Head

Group Icon
Joined: 18 Jul, 2006
Posts: 196



Thanked 1 times

Dream Kudos: 250
My Contributions


CODE

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\wamp\www\blog\admin\edit.php on line 4

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\wamp\www\blog\admin\edit.php on line 7

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\wamp\www\blog\admin\edit.php on line 10

It's looks like this $i isn't send via post confused.gif Any other ideas?

MitkOK:

I tried your hint, I don't get anything if I use 'echo $edited'. So, $i isn't send, I must have error in my form

Problem solved, I was missing <select name=""> attribute biggrin.gif

This post has been edited by k0b13r: 11 Aug, 2007 - 01:02 AM
User is offlineProfile CardPM

Go to the top of the page

snoj
post 11 Aug, 2007 - 10:26 AM
Post #5


$Null

Group Icon
Joined: 31 Mar, 2003
Posts: 3,304



Thanked 5 times

Dream Kudos: 700
My Contributions


Thats because you don't have a form element named 'i'.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 06:33AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month