inserting "name" inseat of the value for $name

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Ne0
Forum Commoner
Posts: 60
Joined: Sat Feb 14, 2004 11:48 am

inserting "name" inseat of the value for $name

Post by Ne0 »

ok, this works absolutly fine, except instead of inserting the value for $name, it physically inserts the word "name". the wierd thing is it didnt do anything like this for the other values, just $name.

o yea, i guess the code would help:

Code: Select all

<?php
page = $_POST['page'];
                $name = $_POST['name'];
                $url = $_POST['url'];
                $author = $_POST['author'];
                $authorurl = $_POST['authorurl'];
                $content = $_POST['content'];
                $sql = mysql_query("INSERT INTO tbl_content (id,page,name,url,clicks,description,author,authorurl) VALUES('','$page','$name','$url','','$content','$author','$authorurl')") or die ("Error ".mysql_errno().": ".mysql_error()."\nQuery: $sql");
                echo "Your content has been added succesfully.<br><center><a href='admini.php'></center></a>";
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

maybe the case is wrong or something.. try print_r($_POST); see what that kicks out..
Ne0
Forum Commoner
Posts: 60
Joined: Sat Feb 14, 2004 11:48 am

Post by Ne0 »

ok, i got back:
Array ( [page] => examples [name] => name [url] => asd [author] => asd [authorurl] => asd [content] => asd )
that doesnt look good...it sais name is name...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

well.. at least the variable is working right.. now just to figure out why $_POST['name'] contains name, instead of what you are expecting.. :)
Ne0
Forum Commoner
Posts: 60
Joined: Sat Feb 14, 2004 11:48 am

Post by Ne0 »

yea, i rele dont understand it, could it have to do with the form?

Code: Select all

<form action='admini.php?a=addcontent' method='post'>Add Content:<br>Page:<input type='text' class='text1' name='page'><br>
                Name:<input type='text' class='text1' name='name'><br>
                URL:<input type='text' class='text1' name='url'><br>
                Author:<input type='text' class='text1' name='author'><br>
                Auth. URL:<input type='text' class='text1' name='authorurl'><br>
                Description:<textarea name='content' cols='40' rows='4' class='text1'></textarea><br>
                <input type='submit' class='text1' value='Add'>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yeah, try changing it..
Ne0
Forum Commoner
Posts: 60
Joined: Sat Feb 14, 2004 11:48 am

Post by Ne0 »

yea, but to what? i mean i havent seen one thing wrong yet, nothing wrong at all, and nothing that would do this
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

name='name' to name='n'.. then $_POST['n'].. seems odd, but that may be the problem..
Ne0
Forum Commoner
Posts: 60
Joined: Sat Feb 14, 2004 11:48 am

Post by Ne0 »

hmm, it worked.
i wonder why it would do that.

o well, thanks for your time and help :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the browser may be getting confused..
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

feyd wrote:the browser may be getting confused..
We should also mention that the more correct way of quoting values is by using double (") quotes. Ie:

Code: Select all

Bad:
  name='name'
Better:
  name="name"
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

very true, Jam.
Ne0
Forum Commoner
Posts: 60
Joined: Sat Feb 14, 2004 11:48 am

Post by Ne0 »

do you mean in thr form? well, i put it in a echo function, so i used single. i guess i could fix that.

thanks again
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

I personally meant the form (any html for that matter). It doesn't matter if you echo it out or use html itself, aways quote.

Code: Select all

echo '<input type="text" name="foo" value="'. $variable .'" />';
echo "<input type="text" name="foo" value="{$variable}" />";
echo <<<HEREDOC
<input type="text" name="foo" value="$variable" />
HEREDOC;
Should all create the same result (minus the spelling errors, im on a coffeebreak).
Post Reply