Jump to content

Inserting New Entry - Php/mysql


globetrottingmike

Recommended Posts

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

$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;
}

}
?>

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.