...

View Full Version : PHP + MySQL INSERT Problem



pippin418
01-23-2010, 04:00 AM
I have a Bookmark Service that using a SQL table. Every time you try to add a second bookmark it deletes (literally) the row. Here's the script for adding:


<?php
$name = $_POST['name'];
$url = $_POST['url'];
$desc = $_POST['desc'];
$uid = $_POST['uid'];
$con = mysql_connect('localhost','pippin','**********');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db = mysql_select_db('pippin_bookmarks');
if(!$db) {
die("Unable to select database");
}
$qry = mysql_query(
"INSERT
INTO
bookmarks(`uid`, `address`, `title`, `description`) VALUES('$uid','$url','$name','$desc')"
)or die(mysql_error());
//Check whether the query was successful or not
if($qry == true)
{
header("location: ub-index.php");
exit();
}
else
die("Query failed");
mysql_close($con);
?>

If you need any other info/data I'll be glad to post it.

masterofollies
01-23-2010, 04:02 AM
My guess would be your id isn't an auto increment, meaning it can't insert a new value.

pippin418
01-23-2010, 04:05 AM
Well I have an ID (Which is. Actually all of them are ID (Auto increment), UID (to identify the user), Title, Address, Description) but it's not in there.

It uses this to view them:

<?php
$id = $_SESSION['SESS_MEMBER_ID'];

$con = mysql_connect('localhost','pippin','********');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db = mysql_select_db('pippin_bookmarks');
if(!$db) {
die("Unable to select database");
}

$qry = "SELECT * FROM bookmarks WHERE uid='$id'";
$result = mysql_query($qry);
if($result) {
if(mysql_num_rows($result) == 0) {
echo "<b>No bookmarks. Please add some.</b>";
} else {
while ($row = mysql_fetch_object($result))
{
echo "<b>" . $row->title . "</b><br />";
echo $row->description . "<br />";
echo "<a href='" . $row->address . "'>" . $row->address . "</a><br />";
echo "<form method='post' action='delete.php'><input name='idd' type='hidden' value='" . $row->id . "'><a href='#' onclick='parentNode.submit()'>Delete</a><br><br>";
}
}
}
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum