PDA

View Full Version : php sending blank data to database



nobody
March 27th, 2004, 09:25 PM
Well I just starting PHPing and I'm having massive problems.

I followed a very faulty tutorial and spent like 2 hours just trying to figure out what they left out and how to fix it. After accomplishing that I realized that this thing barely works.
Basically this code is supposed to enter a new row in a table called links but it just enters a blank row every time, so I'm pretty sure it's the mysql query that's messing it up, but I don't know how to fix it.. i've been php.net-ing and toying for a good hour but just cant get it
here's my code


<?php
if($_POST['wasPressed']) //If submit is hit
{
mysql_connect("localhost","removed","removed"); //then connect as user
mysql_select_db("removed"); //select which database you want to edit
$_POST['name'] = $name;
$_POST['href'] = $href;
$_POST['alt'] = $alt;
$_POST['class'] = $class;
$result = MYSQL_QUERY("INSERT INTO links (ID,name,href,alt,class) VALUES ('NULL','$name','$href','$alt','$class')");
if (!$result) {
die('Invalid query: ' . mysql_error());
}
//Insert the values into the correct database
print "<p>Information Succesfully Sent to Database</p>";
//Get a conformation that it has been uploaded
} else {
?>
<form method="post" action="linkForm.php">
<TABLE>
<TR>
<TD>Title of Link:</TD>
<TD><INPUT TYPE="hidden" VALUE="1" NAME="wasPressed"><INPUT TYPE='TEXT' NAME='name' size=60></TD>
</TR>
<TR>
<TD>Link href:</TD>
<TD><INPUT TYPE='TEXT' NAME='href' size=60></TD>
</TR><br>
<TR>
<TD>Alternate Text:</TD>
<TD><INPUT TYPE='TEXT' NAME='alt' size=60></TD>
</TR>
<TR>
<TD>Class:</TD>
<TD><INPUT TYPE='TEXT' NAME='class' size=60></TD>
</TR><br>
<TR>
<TD></TD><br>
<TD><p><INPUT TYPE="SUBMIT" value="Send Information"></TD>
</TR>
</TABLE>
</form>
<?php
} //close the else statement
?>

nobody
March 27th, 2004, 09:41 PM
Well I figured it out.. I always make the most stupid mistakes

in case anyone wants to use this as a learning experience, this is what to do

$_POST['name'] = $name;

//that part is backwards, it should actually be

$name = $_POST['name'];

//it should be the second way because you are setting the variable to equal the post data, not the other way around.. duh

tucker
March 27th, 2004, 10:19 PM
he he, i was about to say that ur just making long variables the same instead of making them shorter.

plus my 900 page book told me so = D