0

Hello everybody, am working on a small php project and in some pages i have dynamic table to read date from another table in MySql database and i added into same table a javascript code for inserting new row. the fields in the table is:
Value (input type="text")
time (generated)
date (generated)
my issue here is how i can insert this new row to database table with this fields
INDEX (auto increment)
Value
time
date
pat_id (foreign key)

this is javascript function i use:

<script type="text/javascript">
function addRow(patInfo) {
			var currentTime = new Date();
			var hours = currentTime.getHours();
			var minutes = currentTime.getMinutes();
			var month = currentTime.getMonth() + 1;
			var day = currentTime.getDate();
			var year = currentTime.getFullYear();
 
            var table = document.getElementById(patInfo);
 
            var rowCount = table.rows.length;
            var row = table.insertRow(rowCount);
 
            var cell1 = row.insertCell(0);
            var element1 = document.createElement("input");
            element1.type = "text";
			element1.size = "3";
			element1.name = "value";
            cell1.appendChild(element1);
 
            var cell2 = row.insertCell(1);
            var element2 = document.createElement("span");
			element2.name = "time";
            element2.innerHTML = hours + ":" + minutes;
            cell2.appendChild(element2);
 
            var cell3 = row.insertCell(2);
            var element3 = document.createElement("span");
			element3.name = "date";
            element3.innerHTML = day + "-" + month + "-" + year
            cell3.appendChild(element3);
 
        }
</script>

and this is the table:

<?php
$InsertTemp = $_SERVER['PHP_SELF'];
         mysql_query("INSERT INTO ptemperature (INDEX, value, time, date, pat_id)
		VALUES ('','$_GET[value]', '$_GET[time]', '$_GET[date]', 'a')");
?>
<form action="<?php echo $InsertTemp ?>" method="get">
<table id="patInfo" style="width:auto; display:inline; float:left;" cellspacing="0">
	<tr><th colspan="2">Temperature &ordm;C</th><th><img onClick="addRow('patInfo')" width="20px" height="20px" src="images/add_32.png"/></th></tr>
	<tr><th style="border-top:1px solid #e0e0e0;">Value</th><th style="border-top:1px solid 	#e0e0e0;">Time</th><th style="border-top:1px solid #e0e0e0;">Date</th></tr>
	<?php do { ?>
    <tr>
      <td><?php echo $row_Recordset2['value']; ?></td>
      <td><?php echo $row_Recordset2['time']; ?></td>
      <td><?php $sqldate=date('d-m-Y',strtotime($row_Recordset2['date']));
	  			echo $sqldate; ?></td>
    </tr>
    <?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?>
</table>
<input type="submit" value="submit" />
</form>

pleeease i need very quick help...

4
Contributors
11
Replies
12
Views
6 Years
Discussion Span
Last Post by Stefano Mtangoo
0

pleeease i need very quick help...

Why?

0

You make out that it's urgent. If it's not, you shouldn't say it is. But if it is, why is it? Or is it a secret?

0

NO NO it's not a secret at all. am a student and this is my final project in web development course.
This project should submit before next week. that's why am urgent :)

0

It's not completely clear to me what your question is. Are you asking what SQL command you should use, are you asking what Javascript code you should use, or are you asking something else?

0

my question is how i can insert the new record values into DB while the second and third fields (time & date) are generated by javascript code inside dynamic table. should i modify javascript code? or is there php trick to solve this problem ???

0

Have you ever heard of a beast called AJAX? If not try learn it here

I don't know so much about AJAX but it's on my plan.
I think this would be solve with javascript or php code.

0

I don't know so much about AJAX but it's on my plan.
I think this would be solve with javascript or php code.

Your problem is likely AJAX one and there is no shortcut but learn it. Do not be afraid, it you know JS/SSL like PHP then Ajax is just learning the magic of XMLHttp object and bem! you have it :)
All the best!

0

:) Ajax is on your plan and you have to hand your work in on Monday??

I think you'll need more time. You may find some shortcuts through jQuery. You won't be an expert in a day, but you might be able to scrape your way home.

0

:) Ajax is on your plan and you have to hand your work in on Monday??

I think you'll need more time. You may find some shortcuts through jQuery. You won't be an expert in a day, but you might be able to scrape your way home.

Agree! +1

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.