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

}
?>

Edited by globetrottingmike
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.