Jump to content

Data not posting to table


raggy99

Recommended Posts

Hi All,

 

I'm going stir crazy trying to find the error. I'm getting my "data inserted message". however it is not showing in phpmyadmin.

 

P.S. I'm doing this project from scratch, with no real experience. I dabbled in php years ago. I think i stopped because i got frustrated that i could not get it to work. . 

 

 

Form Code

<html>
<head>
<meta charset="utf-8">
<title>Create a Stocktakes</title>
</head>
<form action="processstocktake.php" name="createpi">

<table width="600" border="1">
  <tbody>
    <tr>
      <td align="center" colspan="2">Create a Stocktake</td>
    </tr>
    <tr>
      <td width="200"> </td>
      <td> </td>
    </tr>
    <tr>
      <td>Stocktake Name</td>
      <td><input name="stocktakename" type="text" required="required" id="stocktakename" size="50"></td>
    </tr>
    <tr>
      <td>Date (Month-Year)</td>
      <td><input name="monthyear" type="text" required="required" id="monthyear"></td>
    </tr>
    <tr>
      <td>Stocktake Status</td>
      <td><input name="active" type="text" id="active" value="Active"></td>
    </tr>
    <tr>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td><input type="reset"></td>
      <td align="right"><input type="submit"></td>
    </tr>
  </tbody>
</table>


</form>
<body>
</body>
</html>

Database connection file, when i open this file it shows a blank screen, so password it is connecting

<?php
$connect=mysql_connect('localhost','Username@localhost','password','Username_DBbase');

if(mysqli_connect_error($connect))
{
		echo 'Failed to connect, check your username and/or password';
}

?>

Post script

<?php include ('db.php'); 


$stocktakename=$_POST['StocktakeName'];
$monthyear=$_POST['MonthYear'];
$active=$_POST['Active'];

("INSERT INTO Stocktakes(StocktakeName,MonthYear,Active) VALUES('$stocktakename','$monthyear','$active')") or die(mysql_error());
				
Echo"data inserted";

mysql_close();
?>

Most of the code above i got from tutorials and customised it for my needs. 

 

I hope you can assist. 

 

be gentle i'm new.

 

 

Link to comment
Share on other sites

Hello, Thanks for the quick reply.

I made the change but it didn't seam to work. so i went hunting for a new tutorial and found what looks like a cleaner code..

I am now able to increase my autoid in the db, however now the other data does not post. 

 

form data

<html>
<head>
<meta charset="utf-8">
<title>Create a Stocktakes</title>
</head>
<form action="processstocktake.php" name="createpi">

<table width="600" border="1">
  <tbody>
    <tr>
      <td align="center" colspan="2">Create a Stocktake</td>
    </tr>
    <tr>
      <td width="200"> </td>
      <td> </td>
    </tr>
    <tr>
      <td>Stocktake Name</td>
      <td><input name="stocktakename" type="text" required="required" size="50"></td>
    </tr>
    <tr>
      <td>Date (Month-Year)</td>
      <td><input name="monthyear" type="text" required="required"></td>
    </tr>
    <tr>
      <td>Stocktake Status</td>
      <td><input name="status" type="text" value="Open"></td>
    </tr>
    <tr>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td><input type="reset"></td>
      <td align="right"><input type="submit"></td>
    </tr>
  </tbody>
</table>


</form>
<body>
</body>
</html>

<?php 
	include 'db.php'; 

$stocktakename=$_POST['stocktakename'];
$monthyear=$_POST['monthyear'];
$active=$_POST['status'];

mysql_query ("INSERT INTO Stocktakes(StocktakeID, StocktakeName, MonthYear, Active) VALUES (NULL, '$stocktakename', '$monthyear', '$active')") or die(mysql_error());
				
Echo"data inserted";
mysql_close();

?>

I think i'm missing something between the form and process script, however i even copied the name from the form to the processstocktake.php file. 

 

this is making me go insane. 

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.