PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 300,455 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,624 people online right now. Registration is fast and FREE... Join Now!




sql database failing to update

 

sql database failing to update

joshuabraham

2 Jul, 2009 - 05:53 AM
Post #1

New D.I.C Head
*

Joined: 18 Nov, 2008
Posts: 36



Thanked: 3 times
My Contributions
this is the form page that sends inputs to the database update page
CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><title>patient</title></head><body><?php$state=0;$con = mysql_connect("localhost","root","");if (!$con)  {  die('Could not connect: ' . mysql_error());  }mysql_select_db("testDental", $con);$result = mysql_query("SELECT * FROM patient");echo "<table border=1>";echo "<FORM ACTION=\"patientUpdater.php\"  method=\"post\">";while($row = mysql_fetch_array($result)){if($row['name']==$_POST[name]||$row['email']==$_POST[email]){$d=$row['day'];$m=$row['month'];$y=$row['year'];$p1=$row['phonenumber1'];$p2=$row['phonenumber2'];$fn=$row['firstname'];$ln=$row['lastname'];$e=$row['email'];echo "<tr><td>replace this</td><td>$d</td><td>$m</td><td>$y</td><td>$p1</td><td>$p2</td><td>$fn</td><td>$ln</td><td>$e</td></tr>";echo "<tr><td>with this</td><td><input type=\"text\" name=\"$d\" value=\"$d\" ></td><td><input type=\"text\" name=\"$m\" value=\"$m\"></td><td><input type=\"text\" name=\"$y\" value=\"$y\"></td><td><input type=\"text\" name=\"$p1\" value=\"$p1\"></td><td><input type=\"text\" name=\"$p2\" value=\"$p2\"></td><td><input type=\"text\" name=\"$fn\" value=\"$fn\"></td><td><input type=\"text\" name=\"$ln\" value=\"$ln\"></td><td><input type=\"text\" name=\"$e\" value=\"$e\"></td></tr>";}}echo "<tr><td><input type=\"submit\" name=\"submit\"</td></tr>";echo "</table>";echo "</FORM>";?></body></html>
this is the page that is supposed to update the database.There are no errors however nothing gets updated
CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>patient</title></head>
<body>
<?php

$state=0;
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("testDental", $con);

$result = mysql_query("SELECT * FROM patient");
$err=0;

echo "<table border=1>";
echo "<FORM ACTION=\"patientUpdater.php\"  method=\"post\">";
while($row = mysql_fetch_array($result)){
$d=$row['day'];
$m=$row['month'];
$y=$row['year'];
$p1=$row['phonenumber1'];
$p2=$row['phonenumber2'];
$fn=$row['firstname'];
$ln=$row['lastname'];
$e=$row['email'];
if(isSet($_POST[$d])&&$_POST[$d]!=""){
$ind=$_POST[$d];
mysql_query("UPDATE patient SET day ='$ind'
WHERE day =' $d'");
}


if(isSet($_POST[$m])&&$_POST[$m]!=""){
$ind=$_POST[$m];
if(!mysql_query("UPDATE patient SET month ='$ind'
WHERE month =' $m'")){
echo "error";
}
}



if(isSet($_POST[$y])&&$_POST[$y]!=""){
$ind=$_POST[$y];
if(!mysql_query("UPDATE patient SET year ='$ind'
WHERE year =' $y'")){
echo "error";
}
}



if(isSet($_POST[$p1])&&$_POST[$p1]!=""){
$ind=$_POST[$p1];
if(!mysql_query("UPDATE patient SET phonenumber1 ='$ind'
WHERE phonenumber1 =' $p1'")){
echo "error";
}

}



if(isSet($_POST[$p2])&&$_POST[$p2]!=""){
$ind=$_POST[$p2];
if(!mysql_query("UPDATE patient SET phonenumber2 ='$ind'
WHERE phonenumber2 =' $p2'")){
echo "error";
}

}



if(isSet($_POST[$fn])&&$_POST[$fn]!=""){
$ind=$_POST[$fn];
if(mysql_query("UPDATE patient SET firstname ='$ind'
WHERE firstname =' $fn'")){
echo "$_POST[$fn]";
}

}



if(isSet($_POST[$ln])&&$_POST[$ln]!=""){
$ind=$_POST[$ln];
if(!mysql_query("UPDATE patient SET lastname ='$ind'
WHERE lastname =' $ln'")){
echo "error";
}

}



if(isSet($_POST[$e])&&$_POST[$e]!=""){
$ind=$_POST[$e];
if(!mysql_query("UPDATE patient SET email ='$ind'
WHERE email =' $e'")){
echo "error";
}

}


}

mysql_close($con);
?>
</body>
</html>

any help will be greatly appreciated

User is offlineProfile CardPM
+Quote Post


CTphpnwb

RE: Sql Database Failing To Update

2 Jul, 2009 - 06:00 AM
Post #2

D.I.C Lover
Group Icon

Joined: 8 Aug, 2008
Posts: 2,065



Thanked: 151 times
Dream Kudos: 100
Expert In: PHP

My Contributions
You're confusing the form to accept user input with database access. They're two different things. You need to get the user input using a form, then use that input to modify your query(s).

http://www.w3schools.com/html/html_forms.asp

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 02:02AM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month