PDA

View Full Version : Form Data to MySQL Database help



llorax
05-14-2007, 04:13 AM
first off I made a form in which data can be inputted into my database. For some reason, when I submit it, the data is put in as well as a completely blank insert. Why does that happen?

Also I want to put images into the database and have images (not links) show up in the php pages. What is the best way to do this?

djr33
05-14-2007, 04:29 AM
Please use a more descriptive title for a thread.

For the first question, we would need more information such as code or a link to your page.

For both questions, you should be able to find information in older threads. I know the second question has been answered several times.

llorax
05-14-2007, 04:52 AM
<?php

include 'session.inc.php';
include 'config.inc.php';
include 'db.inc.php';


$link = db_connect();

$date = $_POST['date'];
$venue = $_POST['venue'];
$location = $_POST['location'];
$information = $_POST['information'];


$query = "INSERT INTO showdates VALUES ('$date','$venue','$location','$information')";
db_query($query, $link);
db_close(null, $link);

$link = db_connect();

db_close($result, $link);

?>

And the form action:
<form action="<?=$_SERVER['PHP_SELF']?>

Sorry about the title I can't change it.

tech_support
05-14-2007, 06:53 AM
XXXXX

For both questions, you should be able to find information in older threads. I know the second question has been answered several times.

llorax
05-14-2007, 03:14 PM
I don't know how to look about my first question though. I was not getting anything in my search..

boogyman
05-14-2007, 03:51 PM
as a side note, you shouldn't trust what a user inputs into a field. I dont know if you just took it out for testing purposes, but you should be sanitizing the data before doing anything else with it.

research trim() and htmlspecialchars() functions at the very least.


and your first question is that its inserting 2 rows into the database? I am presently learning MySQL myself, however your last few lines seem suspect? you close the connection, open it, then close it again? and also, you do not have any reference in there to the $result variable?



// edit: Image Inserts
http://www.dynamicdrive.com/forums/showthread.php?t=13327