0

I have an index.html file and a savetodatabase.php file. Quite simply I want the form data to store in the db on submit. At the moment nothing happens, no error messages.

In basic_upload there are 5 columns assigned_group, img (not yet implemented), about, and date (not yet implemented). Img and date I haven't completed yet - mostly as i'm still working out file upload and date picker.

Background: I'm running xampp on windows and created the database in phpmyadmin.

Can anyone tell me how to get it to store in the db?

savetodatabase.php

<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <?php
$connection = mysql_connect("localhost", "root", ""); // Establishing Connection with Server
$db = mysql_select_db("timelineinfo", $connection); // Selecting Database from Server
if(isset($_POST['submit'])){ // Fetching variables of the form which travels in URL
$group = $_POST['group'];
//$img = $_POST['img'];
$about = $_POST['about'];
//$date = $_POST['date'];
if($group !=''||$img !='' ||$date !=''||$about !=''){
//Insert Query of SQL
$query = mysql_query("insert into basic_upload(assigned_group, about) values ('$group', '$about')");
echo "<br/><br/><span>Data Inserted successfully...!!</span>";
}
else{
echo "<p>Insertion Failed <br/> Some Fields are Blank....!!</p>";
}
}
mysql_close($connection); // Closing Connection with Server
?>
 </body>
</html>

index.html

<form action="saveToDatabase.php" method="post" >

<p>What group does the event belong to? </p>

<select name="group" class="form-control">
  <option>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
  <option>5</option>
</select>

   <h3>Upload a Picture</h3>

//to be completed

    <br>
   <h3>Description</h3>

<p>Please enter text to describe the achievement (300 Characters Max) </p>
<div class="form-group">
  <label for="comment">Comment:</label>
  <textarea class="form-control" rows="5" id="comment" name="about" ></textarea>
</div>
 <input type="submit" class="btn btn-info" value="Submit Button" name="submit">



</form>
stark
  • 287
  • 4
  • 9
  • 20
  • Consult these following links http://php.net/manual/en/function.mysql-error.php and http://php.net/manual/en/function.error-reporting.php and apply that to your code. You will see a few notices. – Funk Forty Niner Nov 18 '15 at 17:15

1 Answers1

2

As a beginner, i would suggest you to use error_reporting(E_ALL);.You will get to know about the errors.

Change this condition

if($group !=''||$img !='' ||$date !=''||$about !=''){

To

if($group !=''||$about !=''){

This is because, $img and $date will always have empty, and acually you should get error undefined variable.

Niranjan N Raju
  • 12,047
  • 4
  • 22
  • 41