[SOLVED] DB not receiveing form values
Posted: Tue Feb 22, 2005 12:04 pm
I'm trying to create a script that will allow a person to enter only 2 fields into a database. I've gotten quite far with writing the PHP script and it is actually working! but the problem is, whenever I run everything (HTML Form which posts to PHP script which sends info to DB), the auto_increment field in my DB is incremented; however, the 2 fields are empty (except 1 whitespace. Below is the script I'm using. If anyone can help, that would be very great. thanks
KK
insert.php
I also tried this for the insert.php (same error though)
feyd | please read how to post code here.
KK
Code: Select all
<html>
<head>
<title>Insert Info</title>
</head>
<body>
<h1>Insert song and its information</h1>
<form action="insert.php" method="post">
<table border="0">
<tr>
<td>Songname</td>
<td><input type=text name=songname maxlength=50" size="13"><br></td>
</tr>
<tr>
<td>filename (case sensative!)</td>
<td><input type=text name=songurl maxlength="60" size="30"><br></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Add to Database"></td>
</tr>
</table>
</form>
</body>
</html>Code: Select all
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<?
$DBhost = "localhost";
$DBuser = "root";
$DBpass = "mypassword";
$DBName = "music";
$table = "songs";
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
@mysql_select_db("$DBName") or die("Unable to select
database $DBName");
$sqlquery = "INSERT INTO $table
VALUES('".$id."','".$songname."','".$songurl."')";
$results = mysql_query($sqlquery);
mysql_close();
print "<HTML><TITLE> PHP and MySQL </TITLE><BODY
BGCOLOR="#FFFFFF"><center><table border="0"
width="500"><tr><td>";
print "<p><font face="verdana" size="+0"> <center>You
Just Entered This Information Into the
Database<p><blockquote>";
print "Song : $songname<p>FileName : $songurl</blockquote></td></tr></table>
</center></BODY></HTML>";
?>
</body>
</html>Code: Select all
<html>
<head>
<title>Insert</title>
</head>
<body>
<h1>Entry Results</h1>
<?
$songname = addslashes($songname);
$songurl = addslashes($songurl);
@ $db = mysql_pconnect("localhost", "root", "mypassword");
if (!$db)
{
echo "Error: Could not connect to database. Please try again later.";
exit;
}
mysql_select_db("$music");
$query = "INSERT INTO songs VALUES ('','$songname','$songurl')";
$result = mysql_query($query);
if ($result)
echo mysql_affected_rows()."success!";
?>
</body>
</html>feyd | please read how to post code here.