Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Unable to update database

Codes here !

Moderators: macek, egami, gesf

Unable to update database

Postby Gamers » Tue Aug 21, 2012 3:44 am

Hi ,

My earlier problem has been solved, Thanks all for the support, now i made a new page(update.php) which is used to update information, update criteria is based on the date, so for that i first fetch the information based on the date and then i am trying to update it, but my update query does'nt seem to work.

let my explain you what my script is doing below first i am fetching the data which is based on the date
using textbox, and then i take column name "TIME" and "INITIALS" into the text box which i would like to update it ,but my update query does'nt seem to work.

Please find the code below.

<form action="update.php" method="post">

<input type=text value=search name=search >
<input type=submit name=submit value=Search>
</form>

<?php

#$dates=$_POST['search'];
#echo $dates;

if(isset($_POST['submit'])) {


date_default_timezone_set('Asia/Calcutta');
$date=date("m/d/Y");
echo "Current Date Is = ";
echo "$date";

$con = mysql_connect("localhost","root","access");
if(!$con) {
die("Unable Connect To Database Server " .mysql_error());
}

$selectdb=mysql_select_db("baltimore",$con);

if(!$selectdb)
{
die ("Database Connection Error" .mysql_error());
}

$table="baltimore";

if(isset($_POST['update'])) //if update button is pressed execute the query

{
$updatequery = "UPDATE $table SET INITIALS='$_POST[initials]', TIME='$_POST[time]' WHERE DATE='{$_POST["search"]}'"; //search is the textbox name
mysql_query($updatequery,$con);


} //End of isset function

$sql= "select DATE,JOBNAME,INITIALS,TIME from $table where DATE='{$_POST["search"]}'"; //date is enter by username into the text box its working.

$mydata=mysql_query($sql,$con);

echo "<table width=100% height=10% border=1>

<tr>
<th>DATE</th>
<th>JOBNAME</th>
<th>INITIALS </th>
<th>TIME</th>
</tr>";

while($records = mysql_fetch_array($mydata)){
echo "<form action=update.php method=post>";
echo "<tr>";
echo "<td>" . $records['DATE'] . "</td>";
echo "<td>" . $records['JOBNAME'] . "</td>";
echo "<td>" . "<input type=text name=initials value=" . $records['INITIALS'] . " </td>";
echo "<td>" . "<input type=text name=time value=" . $records['TIME'] . " </td>";
echo "<td>" . "<input type=submit name=update value=update" . " </td>";
echo "</form>";


}
echo "</table>";

}
?>


Thanks In Advance
Regards
Ashish
Gamers
New php-forum User
New php-forum User
 
Posts: 48
Joined: Mon Jun 11, 2012 9:13 am

Re: Unable to update database

Postby johnj » Tue Aug 21, 2012 9:08 pm

print your mysql update query and run it using a sql client like phpmyadmin.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Unable to update database

Postby lvidya » Tue Aug 21, 2012 10:20 pm

Hi, You are using <form action=update.php method=post> ie, the same page,
Process form action in new page
lvidya
New php-forum User
New php-forum User
 
Posts: 37
Joined: Wed Jun 20, 2012 3:20 am

Re: Unable to update database

Postby NigelRen » Wed Aug 22, 2012 1:39 am

Any time you call mysql_query - you should check this has worked. Checking the return value for FALSE indicates that some error has occurred. If you don't you may never see that the update is failing with an error.
NigelRen
php-forum Active User
php-forum Active User
 
Posts: 450
Joined: Fri Aug 05, 2011 9:53 am


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron