PHP Programming > Beginners - Learning PHP
Uploading data to Mysql database using html form trouble
mdahlke:
Yes, I my database and table are stored in a variable. It creates a new entry but they are all blank, could it be something with the collation?
wilson382:
how weird because i tested with the same form you provided i dint change anything to the form and it worked.
it added new record with the data i put on the form
provide me with more codes of you project maybe i can help be sure you to replace any sensitive information with **** like this
mdahlke:
I've included pretty much everything that is needed for the form and database
--- PHP Code: ---$localhost="localhost";
$username="ThisIsWhereMyUsernameForTheDatabaseIs;
$password="*******";
$database="sale";
$table="posting";
$title=$_POST['title'];
$location=$_POST['location'];
$when=$_POST['_when'];
$mainitems=$_POST['mainitems'];
mysql_connect($localhost,$username,$password);
mysql_select_db($database) or die( "Unable to select database");
$sql = "INSERT INTO $table (title, location, _when, mainitems) VALUES
('$title','$location','$when','$mainitems')";
$result=mysql_query($sql);
if($result){
echo "<html>
<head>
<title>Post</title>
<link href='layout.css' rel='stylesheet' type='text/css'/>
</head>
<body>
<?php include 'leftSidebar.php' ?>
<section class='container'>
<?php include 'header.php' ?>
<article class='content'>
<a href='listingsPage.php'>Click to see your listing</a>
</article>
<?php include 'footer.php' ?>
</section>
</body>
</html>";
}
else {
echo "ERROR";
}
mysql_close();
?>
--- End code ---
sale-posting.php
--- PHP Code: ---<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sell My Shit</title>
<link href="layout.css" type="text/css" rel="stylesheet"/>
<link href="listingsPage.php" rel="alternate"/>
</head>
<body>
<?php require_once 'leftSidebar.php' ?>
<section class="container">
<?php require_once 'header.php' ?>
<article class="content">
<article class="home">
<p>Popular Yard sales going on now!</p>
</article>
</article>
<?php require_once 'footer.php' ?>
</section>
</body>
</html>
--- End code ---
mdahlke:
in the real code the " is not missing at the end of this line...
--- PHP Code: ---$username="ThisIsWhereMyUsernameForTheDatabaseIs;
--- End code ---
RaythXC:
--- PHP Code: ---
$sql = "INSERT INTO $table (title, location, _when, mainitems) VALUES
('$title','$location','$when','$mainitems')";
--- End code ---
Try replacing with..
--- PHP Code: ---
$sql = "INSERT INTO `{$table}` (`title`, `location`, `_when`, `mainitems`) VALUES
('$title','$location','$when','$mainitems');";
--- End code ---
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version