Jump to content

[SOLVED] insert into help


mjgdunne

Recommended Posts

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.

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.

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
}
?>

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
}
?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.