0

hey i have a javascript datepicker working on my site but when i try to store the data on mysql im having trouble setting the primary key from the parent table into a new id_item. i pass the id in the url eg

somepage.php?id=1

it still doesnt store the date from the datepicker because of the date format

eg yyyyddmm, mmddyyyy, ect

here i pass the id from the previous page

<td align="centre"><a href="prices.php?id=<? echo $rows['id']; ?>">prices</a></td>

here i load prices to select a new date and store a price

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// get value of id that sent from address bar
$id=$_POST['id'];
$id=$id_item;


// Retrieve data from database 
$sql="SELECT * FROM $tbl_name  WHERE id='$id_item'";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);
?>
<html>
<head>
<script language="javascript" type="text/javascript" src="datetimepicker_css.js"> 
 </script>
</head>
<body>
<form name="price" method="post" action="update_prices.php">

 <label for="date_start">Date start&gt;&gt; </label>
     <input name="date_start" type="text" id="date_start" maxlength="25" size="25"/>
     <img src="images/cal.gif" onclick="javascript:NewCssCal('date_start')" style="cursor:pointer"/>
<br>
 <label for="date_end">date end &gt;&gt; </label>
     <input name="date_end" type="text" id="date_end" maxlength="25" size="25"/>
     <img src="images/cal.gif" onclick="javascript:NewCssCal('date_end')" style="cursor:pointer"/>
<br>
price <textarea name="price" rows="1" cols="40" wrap="virtual"   id="price" ><? echo $rows['price']; ?></textarea>
<br>
<input name="id_item" type="hidden" id="id_item" value="<? echo $rows['id_item']; ?>">

<input type="submit" name="Submit" value="Submit">

</form>
<?

// close connection 
mysql_close();

?>
		</div>
			</article>
<!-- / content -->
	</div>
		<div class="block"></div>
</div>
<script type="text/javascript"> Cufon.now(); </script>
</body>
</html>

on submit it loads updateprices.php, it stores the price bt doesnt update the id_item or store the date.
my database table is very simple just
`id` ,
`id_item` ,
`date_start` ,
`date_end` ,
`price`
);

Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$id_item=$_POST['id_item'];

$date_start=$_POST['date_start'];
$date_end=$_POST['date_end'];
$price=$_POST['price'];

// update data in mysql database 
$sql="INSERT INTO prices VALUES('id','$id_item','$date_start','$date_end','$price') ";
$result=mysql_query($sql);

// if successfully updated. 
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='list_records.php'>View result</a>";
}

else {
die (mysql_error().' <br />SQL statement: '.$sql);
}
?>

ive tried it lots of ways and it still wont change the id_item

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by hari.sarvothama
0

hey,
First, in line 7 in ur somepage.php u seem to have gotten the variable assignment reversed causing the $_POST value to be not stored in $id which might cause problems in ur query in line 11.

and date <input> u hav used seem to hav no value attribute, which shld be there for uploadprice.php to recive in $_POST[]

Also try echo or isset() the post variables to find whether or not post value is available in uploadprice.php page.

Edited by hari.sarvothama: Add solution

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.