mjgdunne Posted May 9, 2008 Share Posted May 9, 2008 Hi i am having a problem, i am trying to update a field in my database with info from a textarea 'mynotes', the field in the database is called notes. Here is my code where i am displaying results and printing a text area for the user to add notes: $pid = $_GET['pid']; $sql = "SELECT * FROM reff WHERE `pid` = '$pid'"; $result = mysql_query($sql) or die(mysql-error()); $row = mysql_fetch_assoc($result); echo "<table border=\"1\" align=\"center\">"; echo "<tr><th>ID</th>"; echo "<td>"; echo $row['pid']; echo "</td>"; echo "<tr><th>Make</th>"; echo "<td>"; echo $row['make']; echo "</td>"; echo "<tr><th>Model</th>"; echo "<td>"; echo $row['model']; echo "</td>"; echo "<tr><th>Registration</th>"; echo "<td>"; echo $row['registration']; echo "</td>"; echo "<tr><th>Image</th>"; echo "<td>"; echo "<img src='upload/".$row['image']."' width='250' height='250'/>"; echo "</td>"; echo "<tr><th>Image</th>"; echo "<td>"; echo "<img src='upload/".$row['image2']."' width='250' height='250'/>"; echo "</td>"; echo "<tr><th>Image</th>"; echo "<td>"; echo "<img src='upload/".$row['image3']."' width='250' height='250'/>"; echo "</td>"; echo "<tr><th>Image</th>"; echo "<td>"; echo "<img src='upload/".$row['image4']."' width='250' height='250'/>"; echo "</td>"; echo "<tr><th>Damage Report</th>"; echo "<td>"; echo "<a href='upload/".$row['report']."' target='_blank'>Click Here to view damage report</a>"; echo "</td>"; echo "<tr><th>Notes on Caes</th>"; echo "<td>"; echo "<textarea cols=80 rows=10 name=mynotes></textarea>"; echo "</td>"; echo "<tr><th></th>"; echo "<td>"; echo "<button onclick=\"window.location.href='save.php?pid=".$row['pid']."'\">Save</button>"; echo "</td>"; ?> Here is my code for updating: $pid = $_GET['pid']; $mynotes=$_GET['mynotes']; $sql = "UPDATE reff SET notes = '" . $_POST['mynotes'] . "'WHERE `pid` ='$pid'"; mysql_query($sql) or die(mysql_error()); echo '<br />Query was:'.$sql; ?> Quote Link to comment Share on other sites More sharing options...
micah1701 Posted May 9, 2008 Share Posted May 9, 2008 are you getting any specific error message? you might want try: $sql = "UPDATE reff SET notes = '$_POST[mynotes]' WHERE `pid` = '$pid' "; Quote Link to comment Share on other sites More sharing options...
mjgdunne Posted May 9, 2008 Author Share Posted May 9, 2008 The text contained in 'mynotes' does not seem to be getting passed through $pid = $_GET['pid']; $mynotes=$_POST['mynotes']; mysql_select_db("test"); $sql = "UPDATE reff SET notes = '" . $_POST['mynotes'] . "'WHERE `pid` ='$pid'"; mysql_query($sql) or die(mysql_error()); echo '<br />Query was:'.$sql; echo 'Notes are:'.$mynotes; Quote Link to comment Share on other sites More sharing options...
micmania1 Posted May 9, 2008 Share Posted May 9, 2008 I think the error is in your form. When the button is pressed, you are simply using it as a link, instead of using an actual form. echo '<form action="save.php" method="GET"> <textarea name="mynotes"></textarea> <input type="hidden" name="pid" value="'.$row['pid'].'" /> </form>'; I don't think the GET method is suitable for submitting a textarea because I the URL has a character limit meaning some of the submitted data may not be passed to the next page. Try post. echo '<form action="save.php?pid='.$row['pid'].'" method="post"> <textarea name="mynotes"></textarea> </form>'; Quote Link to comment Share on other sites More sharing options...
mjgdunne Posted May 9, 2008 Author Share Posted May 9, 2008 Hi thanks for your reply do you mean something like this: echo "<tr><th>Notes on Case</th>"; echo "<td>"; echo '<form action="save.php?pid='.$row['pid'].'" method="post"> <textarea name="mynotes"></textarea> </form>'; echo "</td>"; echo "<tr><th></th>"; echo "<td>"; echo "<button onclick=\"window.location.href='save.php'\">Save</button>"; echo "</td>"; ?> Quote Link to comment Share on other sites More sharing options...
peranha Posted May 9, 2008 Share Posted May 9, 2008 yes, method="POST" and on the save.php page, you would use $pid = $_GET['pid']; $mynotes=$_POST['mynotes']; Quote Link to comment Share on other sites More sharing options...
mjgdunne Posted May 9, 2008 Author Share Posted May 9, 2008 Hi i have tried this but it is not working here is my full code: <?php session_start(); if($_SESSION['loggedin'] != "true") { header("Location: main_login.html"); } else { ?> <html> <head> <title>Car Rentals & Returns</title> <meta http-equiv="Content-Type" content="text/html" /> <link href="style2.css" rel="stylesheet" type="text/css" /> <SCRIPT LANGUAGE="JavaScript"> document.write(Date()); </SCRIPT> </head> <body> <div id="wrapper3"> <img src="images/cars.jpg" width="996" height="100"></a> <TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=100%> <tr> <td align="center"> <H1>View Cases:</H1> </td> </table> <TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=100%> <tr> <TD ALIGN=CENTER> <?php $host="localhost"; // Host name $username="root"; // Mysql username $password="root"; // Mysql password $db_name="test"; // Database name $tbl_name="reff"; // Table name // Connect to server and select databse. mysql_connect("$host", "root", "root")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $pid = $_GET['pid']; $sql = "SELECT * FROM reff WHERE `pid` = '$pid'"; $result = mysql_query($sql) or die(mysql-error()); $row = mysql_fetch_assoc($result); echo "<table border=\"1\" align=\"center\">"; echo "<tr><th>ID</th>"; echo "<td>"; echo $row['pid']; echo "</td>"; echo "<tr><th>Make</th>"; echo "<td>"; echo $row['make']; echo "</td>"; echo "<tr><th>Model</th>"; echo "<td>"; echo $row['model']; echo "</td>"; echo "<tr><th>Registration</th>"; echo "<td>"; echo $row['registration']; echo "</td>"; echo "<tr><th>Image</th>"; echo "<td>"; echo "<img src='upload/".$row['image']."' width='250' height='250'/>"; echo "</td>"; echo "<tr><th>Image</th>"; echo "<td>"; echo "<img src='upload/".$row['image2']."' width='250' height='250'/>"; echo "</td>"; echo "<tr><th>Image</th>"; echo "<td>"; echo "<img src='upload/".$row['image3']."' width='250' height='250'/>"; echo "</td>"; echo "<tr><th>Image</th>"; echo "<td>"; echo "<img src='upload/".$row['image4']."' width='250' height='250'/>"; echo "</td>"; echo "<tr><th>Damage Report</th>"; echo "<td>"; echo "<a href='upload/".$row['report']."' target='_blank'>Click Here to view damage report</a>"; echo "</td>"; echo "<tr><th>Notes on Case</th>"; echo "<td>"; echo '<form action="save.php?pid='.$row['pid'].'" method="post"> <textarea name="mynotes"></textarea> </form>'; echo "</td>"; echo "<tr><th></th>"; echo "<td>"; echo "<button onclick=\"window.location.href='save.php'\">Save</button>"; echo "</td>"; ?> <TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=30%> <tr> </td> <form method="post" action="login_success2.php"> <td align="center"> <input type="submit" value="Home"/></form> </tr> </table> </table> </td> </tr> </table> </BODY> </HTML> <?php } ?> <?php session_start(); if($_SESSION['loggedin'] != "true") { header("Location: main_login.html"); } else { ?> <html> <head> <title>Car Rentals & Returns</title> <meta http-equiv="Content-Type" content="text/html" /> <link href="style2.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="wrapper3"> <img src="images/cars.jpg" width="996" height="100"></a> <TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=100%> <tr> <td align="center"> <H1>Notes Added</H1> <form action="login_success2.php" method="post"> </td> </table> <TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=100%> <tr> <TD ALIGN=CENTER VALIGN=TOP WIDTH=50> </TD> <TD ALIGN=LEFT VALIGN=TOP WIDTH=83%> </table> <?php $host="localhost"; // Host name $username="root"; // Mysql username $password="root"; // Mysql password $db_name="test"; // Database name $tbl_name="reff"; // Table name // Connect to server and select databse. mysql_connect("$host", "root", "root")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $pid = $_GET['pid']; $mynotes=$_POST['mynotes']; mysql_select_db("test"); $sql = "UPDATE reff SET notes = '" . $_POST['mynotes'] . "'WHERE `pid` ='$pid'"; mysql_query($sql) or die(mysql_error()); echo '<br />Query was:'.$sql; echo 'Notes are:'.$mynotes; ?> <TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=100%> <tr> <td align="center"><input type="submit" value="Home"/></td> </tr> </table> </table> </td> </tr> </table> </BODY> </HTML> <?php } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.