MySQL Forums
Forum List  »  PHP

Using $_GET in INSERT mysql
Posted by: Bob C
Date: April 10, 2014 08:54AM

I want to GET an ID from the url e.g.: www.example.com/upload.php?sc=1

and input the ID into my database. I have attached my code, however the ID does not get inserted in the database. Kindly help me in order to get the ID also stored in the database.


<?php require_once '../database.php'; ?>
<?php $eventid = $_GET['event']; ?>
<?php $sc = $_GET['sc']; ?>
</head>

<body>
<?php
$result = mysql_query("SELECT * FROM category");
while($row = mysql_fetch_array($result)){
echo "<a href=?event=" . $row['id'] .">" . $row['category'] . "</a>&nbsp;";
}
?><br>
<?php
$result = $db->query("SELECT * FROM sub_category WHERE category_id LIKE '" . $eventid . "';");
$event = $result->fetch();
?>
<?php
echo "<a href=?event=" . $row['id'] .">" . $row['category'] . "</a>&nbsp;";
?>
<?php
echo "<a href=?sc=" . $event['id'] .">" . $event['sub_category'] . "</a>&nbsp;";
?>
<form method="POST" action="upload1.php" enctype="multipart/form-data" id="subForm">
<b>Upload your file here</b>
<br/>
<span>Name:*</span>&nbsp;<input name="name" type="text" class="required"><br/>
Description:* <input name="description" type="text" class="required"><br/><br/>
Thumbnail Size: 400px X 400px | Featured Image Size: 2100px X 525px<br><br>
Browse:*<input name="userfile" type="file" class="required">&nbsp;<br>
<br/>
<input type="submit" value="Upload" style="width: 150px">
</form>
<?php
$name = $_POST['name'];
$description = $_POST['description'];
$sc = $_GET['sc'];
$kj=$sc;
if(empty($name)) {
echo("<br>All the above details must filled in! We dont want monkeys on the page!");
}
else {
$target="images/";
$target.=$_FILES['userfile']['name'];
move_uploaded_file($_FILES['userfile']['tmp_name'],$target);
move_uploaded_file($_FILES['userfile']['tmp_name'],$target);
mysql_query("INSERT INTO upload(upload, name, description, sub_category_id) VALUES ('".$target."', '$_POST[name]', '$_POST[description]', '".$sc."')") or die( mysql_error());
echo "<br>File Successfully Uploaded!";
}
?>

Options: ReplyQuote


Subject
Written By
Posted
Using $_GET in INSERT mysql
April 10, 2014 08:54AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.