globetrottingmike Posted December 4, 2012 Share Posted December 4, 2012 Hi all, Here is my existing code for inserting a new entry into a MySQL table. What I would like to do is be abel to add the 'ccategory' from a URL parameter - such as www.mysite.com/add_image.php?cat=3 . Can you help me edit my code below to make this work. Thanks, Mike --------------------------------------------------------------- <?php // connect database $dbc = mysql_connect("localhost", "###", "###"); // select database mysql_select_db("artbyiyu_art", $dbc); if(isset($_POST)) { //echo $_POST['name']; $fileName = $_POST['name']; $time = time(); mysql_query("INSERT INTO uploadify3(filename, filedate, category) VALUES('$fileName', '$time', '$category')"); $inserted_id = mysql_insert_id($dbc); if($inserted_id > 0) { // if success echo "uploaded file: " . $fileName; } } ?> Link to comment https://forums.phpfreaks.com/topic/271585-inserting-new-entry-phpmysql/ Share on other sites More sharing options...
MDCode Posted December 4, 2012 Share Posted December 4, 2012 $category = mysql_real_escape_string($_GET['cat']); Link to comment https://forums.phpfreaks.com/topic/271585-inserting-new-entry-phpmysql/#findComment-1397483 Share on other sites More sharing options...
globetrottingmike Posted December 4, 2012 Author Share Posted December 4, 2012 $category = mysql_real_escape_string($_GET['cat']); Thanks for your assistance with this. Would my code becomes as follows? <?php // connect database $dbc = mysql_connect("localhost", "###", "###"); // select database mysql_select_db("artbyiyu_art", $dbc); if(isset($_POST)) { //echo $_POST['name']; $fileName = $_POST['name']; $time = time(); mysql_query("INSERT INTO uploadify3(filename, filedate, category) VALUES('$fileName', '$time', '$category')"); $category = mysql_real_escape_string($_GET['cat']); $inserted_id = mysql_insert_id($dbc); if($inserted_id > 0) { // if success echo "uploaded file: " . $fileName; } } ?> Link to comment https://forums.phpfreaks.com/topic/271585-inserting-new-entry-phpmysql/#findComment-1397491 Share on other sites More sharing options...
MDCode Posted December 4, 2012 Share Posted December 4, 2012 You must define the variable before you can use it in a query. Move $category = above the query. Link to comment https://forums.phpfreaks.com/topic/271585-inserting-new-entry-phpmysql/#findComment-1397496 Share on other sites More sharing options...
globetrottingmike Posted December 4, 2012 Author Share Posted December 4, 2012 Thank you I will give it a go later and let you know how I get on. Link to comment https://forums.phpfreaks.com/topic/271585-inserting-new-entry-phpmysql/#findComment-1397499 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.