PDA

View Full Version : Why won't this work?



jonahholliday
January 27th, 2006, 10:58 AM
Here's the code...

<?php



if(isset($_POST['save']))
{
$sitename = $_POST['sitename'];

if(!get_magic_quotes_gpc())
{
$sitename = addslashes($sitename);

}

include("config.inc.php");
$dbh=mysql_connect ("$server", "$user", "$pass") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("$database");

$query = "INSERT INTO site (sitename) ".
"VALUES ('$sitename')";
mysql_query($query, $dbh) or die('Error, query failed');

mysql_close($dbh);

echo "Site - '$sitename' - Has Been Added";
}
?>
Add A Site
<form method="POST">
<table width="700" border="0" cellpadding="2" cellspacing="1" class="box" align="center">
<tr>
<td width="100">Site Name</td>
<td><input name="sitename" type="text" class="box" id="sitename"></td>
</tr>
<td width="100">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="center"><input name="save" type="submit" class="box" id="save" value="Save Site"></td>
</tr>
</table>
</form>

I get the Error, query failed,

I can't seem to figure out what went wrong....

I am running...

PHP ver. 4.4.1
Mysql ver. 4.1.13-standard-log

Cheers,

Jonahholliday

Sliker_Hawk
January 27th, 2006, 11:04 AM
You only get 'Error: query failed' because of this line:
mysql_query($query, $dbh) or die('Error, query failed');

Change that to:
mysql_query($query, $dbh) or die(mysql_error());
And it'll be much more help.

jonahholliday
January 27th, 2006, 11:12 AM
Thanks so much,

** I had an error in my table.

Jonahholliday