Help Please!


I’ve got this code that is inserting two blank attributes into mysql…its driving me batty and I know it is something simple…You smart folks should be able to figure this out fast!

Here are the php errors reported in the apache log file:
Undefined variable: quote
Undefined variable: author

Here is the code:

Add rows using a form Quote:&nbsp

<?php if($_POST["add"]){ $link=mysql_connect("localhost","phpuser", "phpuser1"); mysql_select_db("testdb", $link); $query="insert into quotes(quote, author)"; $query.=" values('$quote', '$author')"; $result=mysql_query($query); if ($result) echo "added one row successfully."; }




Well you were right about that at least. PHP just told you what the problem was. You are trying to use two variables that have don’t exist. Set them to something first, then call them. Set them to be blank, even, if you like.


Well, I’m missing something then because I thought that the text box’s pass the two variables to php as $author and $quote after the submit button is clicked…Sorry I still don’t understand how to fix this


PHP doesn’t just report errors for fun. If it tells you the variable isn’t initialized, you shouldn’t be looking for a reason why it isn’t initialized. In this case, a short google search would likely have turned up a problem that many people have with registered globals being set to off.

Use $_POST[‘name’] to get posted variables, not just $name. With the querystring, use $_GET[].