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 Quote Link to comment 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']; Quote Link to comment Share on other sites More sharing options...
leijae Posted June 27, 2011 Author Share Posted June 27, 2011 it still writes 0 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.