4 Replies - 9422 Views - Last Post: 27 February 2010 - 09:53 PM Rate Topic: -----

#1 l_ladypearl  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 42
  • Joined: 07-October 07

save data to database

Posted 27 February 2010 - 04:25 PM

My form:


<form name="chooseDateForm" id="chooseDateForm" action="confirm.php">
<table>
<tr>
 <td> <label for="start_date">Check In Date:</label> </td>
 <td> <input name="start_date" id="start_date" class="date-pick" /> </td>
</tr>
<tr>
 <td> <label for="end_date">Check Out Date:</label> </td>
 <td> <input name="end_date" id="end_date" class="date-pick" /> </td>
</tr>
<tr>
 <td> <input type="submit" value="Continue"> </td>
</tr>
</table>
</form>




my php code to save data to database:

<?php
	include("db_connect.php");
	
	$sql_insert = "INSERT INTO availability (start_date, end_date) values ('$_POST[start_date]', '$_POST[end_date]')";
	
	if (!mysql_query($sql_insert,$con))
	{
		die('Error: ' . mysql_error());
	}
	
	mysql_close($con);
?>




I'm using a popup calendar for the Check-in and check-out fields. Upon clicking on the dates in the calendar, the dates appear in the text field.
On submitting the form, there are no errors.
I'm having problems with this part: the dates won't appear in my database. In my database, I've tried to change the data type to text, but it's still not working. Can anyone help please?

Is This A Good Question/Topic? 0
  • +

Replies To: save data to database

#2 moopet  Icon User is offline

  • binary decision maker
  • member icon

Reputation: 339
  • View blog
  • Posts: 1,185
  • Joined: 02-April 09

Re: save data to database

Posted 27 February 2010 - 04:56 PM

Well I don't know if you're doing anything else wrong, but you don't set the form method to POST, so $_POST isn't going to have anything in it. Either use
<form method="post" ... >

or use $_REQUEST instead of $_POST in your PHP?
Was This Post Helpful? 2
  • +
  • -

#3 l_ladypearl  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 42
  • Joined: 07-October 07

Re: save data to database

Posted 27 February 2010 - 05:05 PM

I added the method post, it's still not working.

I think there are no mistakes with my php code.

See, this is what I do: I click on the text field, then the calendar pops up. I choose a date, which is then displayed in the text field. The issue is that the date is not being saved in my database. I don't know if it's been properly captured in the text field or not, before being submitted to the database. You know what I mean?
Was This Post Helpful? 0
  • +
  • -

#4 moopet  Icon User is offline

  • binary decision maker
  • member icon

Reputation: 339
  • View blog
  • Posts: 1,185
  • Joined: 02-April 09

Re: save data to database

Posted 27 February 2010 - 05:48 PM

View Postl_ladypearl, on 27 February 2010 - 11:05 PM, said:

I added the method post, it's still not working.

I think there are no mistakes with my php code.

See, this is what I do: I click on the text field, then the calendar pops up. I choose a date, which is then displayed in the text field. The issue is that the date is not being saved in my database. I don't know if it's been properly captured in the text field or not, before being submitted to the database. You know what I mean?


I know what you mean. If you put
echo $sql_insert;

in there, does it display your INSERT statement with the values you'd expect? That would tell you if it was a problem with the form variables or the database connection.
I can't see anything wrong with your code, either.
Was This Post Helpful? 1
  • +
  • -

#5 l_ladypearl  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 42
  • Joined: 07-October 07

Re: save data to database

Posted 27 February 2010 - 09:53 PM

Ah it's working perfectly now! Just a little something that I corrected when I posted my code here, but forgot to remove on the codes I've been working on:
<form name="chooseDateForm" id="chooseDateForm">
<table>
<tr>
 <td> <label for="start_date">Check In Date:</label> </td>
 <td> <input name="start_date" id="start_date" class="date-pick" /> </td>
</tr>
<tr>
 <td> <label for="end_date">Check Out Date:</label> </td>
 <td> <input name="end_date" id="end_date" class="date-pick" /> </td>
</tr>
</table>
</form>   <!-- had to remove this -->

<form action="confirm.php" method="post"> <!-- and remove this form tag, 'action' and 'method' go up in the first form tag  -->
<input type="submit" value="Continue">
</form>



I had two forms originally. It's painfully obvious why this wasn't working.
Thank you for your help Moopet.

This post has been edited by l_ladypearl: 27 February 2010 - 09:56 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1