PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
//getting the form values
$item=$_GET['item'];
$tDate=$_GET['tDate'];
$price=$_GET['price'];
echo($item.' : '.$price.' : date='.$tDate);
//.....................Putting them in database......................................
$link=mysql_connect('localhost','root','') or die('Could not connect: '.mysql_error());
echo('<br>Database Server is connected successfully');
mysql_select_db('monthlyexpense') or die('Could not select database:'.mysql_error());
echo('<br>database is selected');
//performing sql querry
$query="INSERT INTO 'daily'('dt','item','price') VALUES('$tDate','$item','$price');";
mysql_close($link);
?>
actually i have in my data bse another column which is auto incremented.Do i need to pass any value to that too?or the code is fine?Please guide me in this.
thanks
<?php
//getting the form values
$item=$_GET['item'];
$tDate=$_GET['tDate'];
$price=$_GET['price'];
echo($item.' : '.$price.' : date='.$tDate);
//.....................Putting them in database......................................
$link=mysql_connect('localhost','root','') or die('Could not connect: '.mysql_error());
echo('<br>Database Server is connected successfully');
mysql_select_db('monthlyexpense') or die('Could not select database:'.mysql_error());
echo('<br>database is selected');
//performing sql querry
$query="INSERT INTO `daily` (`dt`,`item`,`price`) VALUES('$tDate','$item','$price');";
mysql_close($link);
?>
simply changed your single quotes around table names and field names to backticks.
Warning: you have SQL injection possible with your usage of $_GET variables dumping directly into SQL. Read the security forum for details of how to fix up your code.
<?php
//getting the form values
$item=$_GET['item'];
$tDate=$_GET['tDate'];
$price=$_GET['price'];
echo($item.' : '.$price.' : date='.$tDate);
//.....................Putting them in database......................................
$link=mysql_connect('localhost','root','') or die('Could not connect: '.mysql_error());
echo('<br>Database Server is connected successfully');
mysql_select_db('monthlyexpense') or die('Could not select database:'.mysql_error());
echo('<br>database is selected');
//performing sql querry
$query="INSERT INTO `daily` (`dt`,`item`,`price`) VALUES('$tDate','$item','$price');";
//........................................added this...........................................................
mysql_query($query);
///................................................................................................................
echo('<br>Data is inserted into table, successfully');
mysql_close($link);
?>
well after all this has happened, i want to take the user back to the form page.Is it possible?I mean after the data is successfully inserted into the database the user should be taken bak to the main form page.Any idea how to do this?Well, this time all the varibales have to be cleared too.
thank you so much.that worked.But is this method of redirection happens after the data has been put inside the database or it just redirects when the page loads.I mean do i need to check that all the dats are put inside the table and then redirect it or it just does that.
thanks
i have checked it and puts the data and then re-directs.
But i got confused as i thought it may or maynot put the data inside and then redirects.So to confirm i asked you masters.