mjgdunne Posted May 9, 2008 Share Posted May 9, 2008 Hi can anyone tell me where im going wrong with this: $pid = $_GET['pid']; $mynotes=$_POST['mynotes']; mysql_select_db("test"); mysql_query("INSERT INTO reff(notes) VALUES ('$mynotes') WHERE `pid`= '$pid'");[code] [/code] Link to comment https://forums.phpfreaks.com/topic/104891-solved-insert-into-help/ Share on other sites More sharing options...
GingerRobot Posted May 9, 2008 Share Posted May 9, 2008 You can't have a WHERE clause with an INSERT statement. Your inserting a new row, so there's nothing to compare pid with. Perhaps you wanted to UPDATE a row? UPDATE reff SET notes = '$mynotes' WHERE pid='$pid'; Link to comment https://forums.phpfreaks.com/topic/104891-solved-insert-into-help/#findComment-536811 Share on other sites More sharing options...
mjgdunne Posted May 9, 2008 Author Share Posted May 9, 2008 Hi thanks for your reply, i am trying, $pid = $_GET['pid']; $mynotes=$_POST['mynotes']; mysql_select_db("test"); mysql_query("UPDATE reff SET notes = '" . $_POST['mytitle'] . "'WHERE pid='" . $_POST['pid'] . "'"); But it doesnt seem to be working, any help would be great. Link to comment https://forums.phpfreaks.com/topic/104891-solved-insert-into-help/#findComment-536843 Share on other sites More sharing options...
BlueSkyIS Posted May 9, 2008 Share Posted May 9, 2008 add or die(mysql_error()) after your mysql_query: mysql_query("SELECT ...") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/104891-solved-insert-into-help/#findComment-536850 Share on other sites More sharing options...
mjgdunne Posted May 9, 2008 Author Share Posted May 9, 2008 hi i added that line, still not putting the details into the database Link to comment https://forums.phpfreaks.com/topic/104891-solved-insert-into-help/#findComment-536854 Share on other sites More sharing options...
BlueSkyIS Posted May 9, 2008 Share Posted May 9, 2008 to insert a new record you have to use an INSERT statement. INSERT INTO some_table (field1, field2, field3) VALUES ('$val1', '$val2', '$val3'); Link to comment https://forums.phpfreaks.com/topic/104891-solved-insert-into-help/#findComment-536857 Share on other sites More sharing options...
mjgdunne Posted May 9, 2008 Author Share Posted May 9, 2008 hi i am trying to update one field in the database. Link to comment https://forums.phpfreaks.com/topic/104891-solved-insert-into-help/#findComment-536863 Share on other sites More sharing options...
GingerRobot Posted May 9, 2008 Share Posted May 9, 2008 I suspect $_POST['pid'] is empty. Try this to check: $sql = "UPDATE reff SET notes = '" . $_POST['mytitle'] . "'WHERE pid='" . $_POST['pid'] . "'"; mysql_query($sql) or die(mysql_error()); echo '<br />Query was:'.$sql; Link to comment https://forums.phpfreaks.com/topic/104891-solved-insert-into-help/#findComment-536866 Share on other sites More sharing options...
mjgdunne Posted May 9, 2008 Author Share Posted May 9, 2008 Hi ya it seems to be empty, uery was:UPDATE reff SET notes = ''WHERE pid='' Here is the code i am using on the page before, is there any way of sending the pid to the next page for use? 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>"; ?> <tr> <TD ALIGN=RIGHT>Notes on Case:</td> <TD ALIGN=LEFT><textarea rows="10" name="mynotes" cols="30"></textarea> </tr> I am taking the information from the textarea named mynotes. Link to comment https://forums.phpfreaks.com/topic/104891-solved-insert-into-help/#findComment-536873 Share on other sites More sharing options...
mjgdunne Posted May 9, 2008 Author Share Posted May 9, 2008 Sorry i cut off the end bit: <tr> <TD ALIGN=RIGHT>Notes on Case:</td> <TD ALIGN=LEFT><textarea rows="10" name="mynotes" cols="30"></textarea> </tr> <TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=30%> <tr><form method="post" action="login_success2.php"> <td align="center"> <input type="submit" value="Home"/></form> <form method="post" action="save.php"> <td align="center"><input type="submit" value="Save"/><form></td> </tr> </table> </table> </td> </tr> </table> </BODY> </HTML> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/104891-solved-insert-into-help/#findComment-536877 Share on other sites More sharing options...
BlueSkyIS Posted May 9, 2008 Share Posted May 9, 2008 i would add a hidden form field to your form: <INPUT TYPE='hidden' NAME='pid' VALUE='<?=$row['pid'];?>'> Link to comment https://forums.phpfreaks.com/topic/104891-solved-insert-into-help/#findComment-536891 Share on other sites More sharing options...
mjgdunne Posted May 9, 2008 Author Share Posted May 9, 2008 Do you think i could use: <form method="post" action="save.php?pid=".$row['pid']."'\"> Link to comment https://forums.phpfreaks.com/topic/104891-solved-insert-into-help/#findComment-536902 Share on other sites More sharing options...
BlueSkyIS Posted May 9, 2008 Share Posted May 9, 2008 yes, but then you'll need to use $_GET['pid'] instead. Link to comment https://forums.phpfreaks.com/topic/104891-solved-insert-into-help/#findComment-537020 Share on other sites More sharing options...
mjgdunne Posted May 9, 2008 Author Share Posted May 9, 2008 Hi i have the picture id part working when i do an echo on the query - i get the following. Query was:UPDATE reff SET notes = ''WHERE `pid` =''Notes are: So it seems the notes are not being passed, any ideas would be great. Link to comment https://forums.phpfreaks.com/topic/104891-solved-insert-into-help/#findComment-537030 Share on other sites More sharing options...
BlueSkyIS Posted May 9, 2008 Share Posted May 9, 2008 can see see the latest code? Link to comment https://forums.phpfreaks.com/topic/104891-solved-insert-into-help/#findComment-537043 Share on other sites More sharing options...
mjgdunne Posted May 9, 2008 Author Share Posted May 9, 2008 Hi thanks for your reply, this is the search results with the textarea 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 '<textarea name="mynotes"></textarea>'; echo "</td>"; echo '<form action="save.php?pid='.$row['pid'].'" method="post">'; echo "<tr><th></th>"; echo "<td>"; echo "<button onclick=\"window.location.href='save.php?pid=".$row['pid']."'\">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 } ?> Here is my code for saving to the database: <?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 } ?> Link to comment https://forums.phpfreaks.com/topic/104891-solved-insert-into-help/#findComment-537049 Share on other sites More sharing options...
GingerRobot Posted May 9, 2008 Share Posted May 9, 2008 The problem is that you're trying to send post data, but as far as i can see you dont actually have a form. You need a form and you need to replace your button with the javascript onclick event with a submit button. To pass on the id, either use a hidden field or add it to the url of the form's action. Link to comment https://forums.phpfreaks.com/topic/104891-solved-insert-into-help/#findComment-537092 Share on other sites More sharing options...
mjgdunne Posted May 9, 2008 Author Share Posted May 9, 2008 Hi i have added the following: echo '<form action="save.php?pid='.$row['pid'].'" method="post"> <textarea name="mynotes"></textarea> </form>'; I am new to php and my knowledge is very basic, so any help would be great. Link to comment https://forums.phpfreaks.com/topic/104891-solved-insert-into-help/#findComment-537097 Share on other sites More sharing options...
mjgdunne Posted May 9, 2008 Author Share Posted May 9, 2008 ok that worked. Thanks for your replys. Link to comment https://forums.phpfreaks.com/topic/104891-solved-insert-into-help/#findComment-537100 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.