Jump to content

writing info from one table to another within the same database


leijae

Recommended Posts

Here is my code, but for some reason it doesn't work.

 

$con = mysql_connect('localhost,'root','pass');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db('upgradde'); //two d's for a double dose of pimping

//this line should call a number like 1 or 5 or 23, depending on the id number of the user. so user=leija and id=1
$id = mysql_query("SELECT id FROM users WHERE username =  ' " .$_REQUEST['user']." ' ");

//this should write 1, fun, fun.com, its fun
$sql = "INSERT INTO uploads (created_by, category, url, comments) VALUES ('$id' , '$_POST[category]', '$_POST[url]', '$_POST[comments]')";
header("location:../index.php"); 
if (!mysql_query($sql,$con)) {
	die('Error: ' . mysql_error());
}
//echo "alert('You may now Sign in')";
mysql_close($con)

 

there are no error codes, the where the $sql should write:

1, fun, fun.com, fun times

 

but instead it writes:

0, fun, fun.com, fun times

try changing this:

$id = mysql_query("SELECT id FROM users WHERE username =  ' " .$_REQUEST['user']." ' ");

for something like this:

$q = mysql_query("SELECT id FROM users WHERE username =  ' " .$_REQUEST['user']." ' ");
$r = mysql_fetch_assoc($q);
$id = $r['id'];

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.