leijae Posted June 27, 2011 Share Posted June 27, 2011 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 https://forums.phpfreaks.com/topic/240554-writing-info-from-one-table-to-another-within-the-same-database/ Share on other sites More sharing options...
WebStyles Posted June 27, 2011 Share Posted June 27, 2011 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 https://forums.phpfreaks.com/topic/240554-writing-info-from-one-table-to-another-within-the-same-database/#findComment-1235620 Share on other sites More sharing options...
leijae Posted June 27, 2011 Author Share Posted June 27, 2011 it still writes 0 Link to comment https://forums.phpfreaks.com/topic/240554-writing-info-from-one-table-to-another-within-the-same-database/#findComment-1235624 Share on other sites More sharing options...
WebStyles Posted June 27, 2011 Share Posted June 27, 2011 are you sure $_REQUEST['user'] exists and has a valid value? echo it just to make sure. Link to comment https://forums.phpfreaks.com/topic/240554-writing-info-from-one-table-to-another-within-the-same-database/#findComment-1235643 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.