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

Link to comment
Share on other sites

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'];

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.