Jump to content

Problem with storing info & associated ID


blepblep

Recommended Posts

Your code only checks for errors, it doesn't verify that the row was updated. A query can be successful even if it doesn't actually affect any rows. To ensure it was updated, you should check that mysql_affected_rows returns 1 (or > 1 in the right situation):

 

if (mysql_affected_rows() === 1) {
    echo 'Row was updated.';
}

The reason it's not updating is because the where condition isn't matching anything. Try var_dumping $post['review_id'] to ensure the value is what you expect.

Link to comment
Share on other sites

  • Replies 56
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I don't no how to multiquote sorry.

 

@Adam - Thanks, I've done this:

 

WHERE

    (review_id = '{$post['review_id']}')";
    var_dump($post['review_id']);

if (mysql_affected_rows() == 1) 
{
        	echo 'Row was updated.';
} 

 

Did you mean to put 3 === in the msql_affected_rows function? I changed it to two. My result when I var_dump()ed review_id was NULL

 

 

@Muddy, I'll send it in a PM because its wayyy too long to post here, nearly 600 lines.

Link to comment
Share on other sites

@Muddy, I'll send it in a PM because its wayyy too long to post here, nearly 600 lines.

Just the bit for the form, don't need the whole page, and if you PM me it, ill just post it in here anyway, that way everyone else can see it too and offer their help (many hands and all that :P)

 

(the S in SQL is for Simple :P ) :

 

Um, not it's not.

Yeah, yeah, we coverd that yesterday thorp ::) sheesh, I make a "Simple" mistake and everyones all over me :'( I'm going for therapy now :P
Link to comment
Share on other sites

Here it is so, just the form part. Muddy the rest of this file is what we were doing in the last thread, searching for the ID

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<link rel = "stylesheet" type = "text/css" href = "stylesheet.css" />
</head>

<script type="text/javascript" language="JavaScript"><!--
function ReverseDisplay(d) 
{
if(document.getElementById(d).style.display == "none") 
{ document.getElementById(d).style.display = "block"; }
else 
{ document.getElementById(d).style.display = "none"; }
}

//--></script>
<p></p>
<div>
<a href="javascript:ReverseDisplay('mom')">
<input type = "button" value = "Show/Hide MOM" />
</a>
</div>

<div id="mom" style="display:none;">
<p><body>

<div style = "width:100%;border:2px dotted #666666;padding:10px 10px 10px 10px;">
  <table id = "templateHeading">
  <form action = "saveMom.php" method = "post">
<tr>
	<th><h2>MOM</h2></th>
	<th><input type = "text" name = "booking_number" size = "16" value = "" readonly = "readonly"/></th>
</tr>

<tr>
	<th><u>Quality Ranking of Review</u></th>
</tr>	

<tr>
	<td>Quality ranking of Review (1-5)</td>
</tr>

<tr>
	<td>(To be completed by TC chairperson)</td>
</tr>

<tr>
	<td>1 = Undefined</td>
</tr>

<tr>
	<td>2 = Document not of sufficient quality to review, missing chapters, clear competence or schedule issue apparent in the review.</td>
</tr>	

<tr>
	<td>3 = Insufficient participants in the review or insufficient preparation from participants.</td>
</tr>

<tr>
	<td>4 = Proper review with some major open issues but in control.</td>
</tr>

<tr>
	<td>5 = Proper review with no major open issues.</td>
</tr>

<tr>
	<td><input type = "text" name = "quality_ranking_review" size = "1"/></td>
</tr>

<tr>
	<th><u>Quality ranking of input document (1-10):</u></th>
</tr>

<tr>
	<td><size = "2"><b>Criteria: Score - 1 = Yes or 0 = No</b></td>

	<td><input type = "text" name = "input_doc_rank" size = "1"/></td>
</tr>

<tr>
	<td><size = "2"><b>___________________________</b></td>
</tr>

<tr>
	<td>To be completed by TC chairperson using TCOSSRC document checklist</td>
</tr>

<!-- SET THIS TO BOOL IN DATABASE -->
<tr>
	<td>Has the correct document instruction/template been followed?</td>
	<td><input type = "text" name = "correct_doc" size = "1"/>
</tr>

<tr>
	<td>Has the document been internally reviewed?</td>
	<td><input type = "text" name = "internally_reviewed" size = "1"/>
</tr>

<tr>
	<td>Does the requirements chapter state whether all requirements have been covered, and explain why specific requirements<br /> are not covered?</td>
	<td><input type = "text" name = "reqs_covered" size = "1"/>
</tr>

<tr>
	<td>Is the document stored in the correct storage library with the correct status?</td>
	<td><input type = "text" name = "correct_storage_library" size = "1"/>
</tr>

<tr>
	<td>Have all trouble reports for faults corrected by the system modifications been described? It should	be obvious which<br /> applications were investigated to find all relevant trouble reports</td>
	<td><input type = "text" name = "reports_described" size = "1"/>
</tr>

<tr>
	<td>Have all approved change requests been included?</td>
	<td><input type = "text" name = "approved_change_requests_included" size = "1"/>
</tr>

<tr>
	<td>Are all open issues addressed?</td>
	<td><input type = "text" name = "issues_addressed" size = "1"/>
</tr>

<tr>
	<td>Has the document been available at least 5 working days before the review date?</td>
	<td><input type = "text" name = "doc_available" size = "1"/>
</tr>

<tr>
	<td>Does the Technical Solution chapter describe the solution to the problems described in the Statement of Problem chapter?</td>
	<td><input type = "text" name = "statement_problem_chapter" size = "1"/>
</tr>

<tr>
	<td>Are there more than 50% major comments? <b>Yes = 0 No = 1</b></td>
	<td><input type = "text" name = "major_comments" size = "1"/>
</tr>

<tr>
	<th><u>Review Summary<u></th>
</tr>

<tr>
	<td>Result</td>
	<td><select name = "result">
		<option value = '' SELECTED>-Please Select-</option>
		<option value = "Approved">Approved</option>
		<option value = "Not Approved">Not Approved</option>
		<option value = "Cancelled">Cancelled</option>
		</select>
	</td>
</tr>

<tr>
	<td>No. of Major Comments</td>
	<td><input type = "text" name = "num_of_major_comments" size = "1"/>
</tr>

<tr>
	<td>No. of Minor Comments</td>
	<td><input type = "text" name = "minor_comments" size = "1"/>
</tr>

<tr>
	<td>Next Review Forum</td>
	<td><select name = "next_review_forum">
			<option value = '' SELECTED>-Please Select-</option>
			<option value = "N/A">N/A</option>
			<option value = "Re Review Full">Re-Review Full</option>
			<option value = "Re Review Simplified">Re-Review Simplified</option>
		</select>
	</td>
</tr>

<tr>
	<th><u>Particulars of Meeting</u></th>
</tr>

<tr>
	<td>Date</td>
	<td><input type = "text" name = "date" size = "4"/>
</tr>

<tr>
	<td>Time</td>
	<td><select name = "time">
		<option value = '' SELECTED>-Please Select a Time-</option>
		<option value = "0800">08:00</option>
		<option value = "0900">09:00</option>
		<option value = "1000">10:00</option>
		<option value = "1100">11:00</option>
		<option value = "1200">12:00</option>
		<option value = "1300">13:00</option>
		<option value = "1400">14:00</option>
		<option value = "1500">15:00</option>
		<option value = "1600">16:00</option>
		<option value = "1700">17:00</option>
		<option value = "1800">18:00</option>
		<option value = "1900">19:00</option>
		</select>
	</td>
</tr>

<tr>
	<td>Venue</td>
	<td><select name = "venue">
		<option value = '' SELECTED>-Please Select-</option>
		<option value = "Lough Mask">Lough Mask</option>
		<option value = "Lough Neagh">Lough Neagh</option>
		<option value = "Lough Sheelin">Lough Sheelin</option>
		<option value = "Lough Allen">Lough Allen</option>
		<option value = "Shaw">Shaw</option>
		<option value = "Beckett">Beckett</option>
		<option value = "Yeats">Yeats</option>
		<option value = "Heaney">Heaney</option>
		<option value = "Tyndall">Tyndall</option>
		<option value = "Lilliput">Lilliput</option>
		<option value = "Lough Ree">Lough Ree</option>
		<option value = "Goldsmith">Goldsmith</option>
		<option value = "Kelvin Meeting Room">Kelvin Meeting Room</option>
		<option value = "Blyry">Blyry</option>
		<option value = "Lough Conn">Lough Conn</option>
		<option value = "Lough Corrib">Lough Corrib</option>
		<option value = "Lough Derg">Lough Derg</option>
		<option value = "Lough Owell">Lough Owell</option>
		<option value = "OSS Demo Room">OSS Demo Room</option>
		<option value = "Synge Conference Room">Synge Conference Room</option>
		<option value = "Annexe Conference Room">Annexe Conference Room</option>
		<option value = "Lars Magnus">Lars Magnus</option>
		<option value - "Office">Office</option>
		</select>
	</td>		
</tr>

<tr>
	<th><u>Actions<u></th>
</tr>

<tr>
	<td>Type</td>
	<td><select name = "type">
		<option value = '' SELECTED>-Please Select-</option>
		<option value = "remark">Remark</option>
		<option value = "action">Action</option>
		</select>
	</td>		
</tr>

<tr>
	<td>Time</td>
	<td><select name = "time">
		<option value = '' SELECTED>-Please Select a Time-</option>
		<option value = "0800">08:00</option>
		<option value = "0900">09:00</option>
		<option value = "1000">10:00</option>
		<option value = "1100">11:00</option>
		<option value = "1200">12:00</option>
		<option value = "1300">13:00</option>
		<option value = "1400">14:00</option>
		<option value = "1500">15:00</option>
		<option value = "1600">16:00</option>
		<option value = "1700">17:00</option>
		<option value = "1800">18:00</option>
		<option value = "1900">19:00</option>
		</select>
	</td>
</tr>

<tr>
	<td>Location</td>
	<td><input type = "text" name = "location" size = "10"/>
</tr>

<tr>
	<td>Severity</td>
	<td><input type = "text" name = "severity" size = "10"/>
</tr>

<tr>
	<td>Resp</td>
	<td><input type = "text" name = "resp" size = "10"/>
</tr>

<tr>
	<td>Status</td>
	<td><input type = "text" name = "Status" size = "10"/>
</tr>

<tr>
	<td>Comment</td>
	<td><textarea name = "comment" cols = 40 rows = 6/></textarea></td>
</tr>

<tr>
	<td>Remark</td>
	<td><select name = "remark">
		<option value = '' SELECTED>-Please Select-</option>
		<option value = "Remark">Remark Acted</option>
		<option value = "Action">Remark Not ccepted</option>
		</select>
	</td>		
</tr>

<tr>
	<td>Miscellaneous</td>
	<td><textarea name = "miscellaneous" cols = 40 rows = 6/></textarea></td>
</tr>

<tr>
	<td>
		<input type="button" name="reset_form" value="Clear Fields" onclick="this.form.reset();">
		<input type="submit" name="save" value="Save MOM" />
	</td>
</tr>
<!-- -------------------------------------------------------------------------------- -->

</table>
</form>
</body>
</html>
</p>
</div>

Link to comment
Share on other sites

ok, the form code:

<form action = "saveMom.php" method = "post">
<tr>
	<th><h2>MOM</h2></th>
	<th><input type = "text" name = "booking_number" size = "16" value = "" readonly = "readonly"/></th>
</tr>

<!-- -------------------------------------------------------------------------------- -->	

<tr>
	<th><u>Quality Ranking of Review</u></th>
</tr>

<!-- -------------------------------------------------------------------------------- -->	

<tr>
	<td>Quality ranking of Review (1-5)</td>
</tr>

<!-- -------------------------------------------------------------------------------- -->	

<tr>
	<td>(To be completed by TC chairperson)</td>
</tr>

<!-- -------------------------------------------------------------------------------- -->	

<tr>
	<td>1 = Undefined</td>
</tr>

<!-- -------------------------------------------------------------------------------- -->	

<tr>
	<td>2 = Document not of sufficient quality to review, missing chapters, clear competence or schedule issue apparent in the review.</td>
</tr>

<!-- -------------------------------------------------------------------------------- -->	

<tr>
	<td>3 = Insufficient participants in the review or insufficient preparation from participants.</td>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>4 = Proper review with some major open issues but in control.</td>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>5 = Proper review with no major open issues.</td>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td><input type = "text" name = "quality_ranking_review" size = "1"/></td>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<th><u>Quality ranking of input document (1-10):</u></th>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td><size = "2"><b>Criteria: Score - 1 = Yes or 0 = No</b></td>

	<td><input type = "text" name = "input_doc_rank" size = "1"/></td>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td><size = "2"><b>___________________________</b></td>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>To be completed by TC chairperson using TCOSSRC document checklist</td>
</tr>

<!-- -------------------------------------------------------------------------------- -->
<!-- SET THIS TO BOOL IN DATABASE -->
<tr>
	<td>Has the correct document instruction/template been followed?</td>
	<td><input type = "text" name = "correct_doc" size = "1"/>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>Has the document been internally reviewed?</td>
	<td><input type = "text" name = "internally_reviewed" size = "1"/>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>Does the requirements chapter state whether all requirements have been covered, and explain why specific requirements<br /> are not covered?</td>
	<td><input type = "text" name = "reqs_covered" size = "1"/>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>Is the document stored in the correct storage library with the correct status?</td>
	<td><input type = "text" name = "correct_storage_library" size = "1"/>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>Have all trouble reports for faults corrected by the system modifications been described? It should	be obvious which<br /> applications were investigated to find all relevant trouble reports</td>
	<td><input type = "text" name = "reports_described" size = "1"/>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>Have all approved change requests been included?</td>
	<td><input type = "text" name = "approved_change_requests_included" size = "1"/>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>Are all open issues addressed?</td>
	<td><input type = "text" name = "issues_addressed" size = "1"/>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>Has the document been available at least 5 working days before the review date?</td>
	<td><input type = "text" name = "doc_available" size = "1"/>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>Does the Technical Solution chapter describe the solution to the problems described in the Statement of Problem chapter?</td>
	<td><input type = "text" name = "statement_problem_chapter" size = "1"/>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>Are there more than 50% major comments? <b>Yes = 0 No = 1</b></td>
	<td><input type = "text" name = "major_comments" size = "1"/>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<th><u>Review Summary<u></th>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>Result</td>
	<td><select name = "result">
		<option value = '' SELECTED>-Please Select-</option>
		<option value = "Approved">Approved</option>
		<option value = "Not Approved">Not Approved</option>
		<option value = "Cancelled">Cancelled</option>
		</select>
	</td>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>No. of Major Comments</td>
	<td><input type = "text" name = "num_of_major_comments" size = "1"/>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>No. of Minor Comments</td>
	<td><input type = "text" name = "minor_comments" size = "1"/>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>Next Review Forum</td>
	<td><select name = "next_review_forum">
			<option value = '' SELECTED>-Please Select-</option>
			<option value = "N/A">N/A</option>
			<option value = "Re Review Full">Re-Review Full</option>
			<option value = "Re Review Simplified">Re-Review Simplified</option>
		</select>
	</td>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<th><u>Particulars of Meeting</u></th>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>Date</td>
	<td><input type = "text" name = "date" size = "4"/>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>Time</td>
	<td><select name = "time">
		<option value = '' SELECTED>-Please Select a Time-</option>
		<option value = "0800">08:00</option>
		<option value = "0900">09:00</option>
		<option value = "1000">10:00</option>
		<option value = "1100">11:00</option>
		<option value = "1200">12:00</option>
		<option value = "1300">13:00</option>
		<option value = "1400">14:00</option>
		<option value = "1500">15:00</option>
		<option value = "1600">16:00</option>
		<option value = "1700">17:00</option>
		<option value = "1800">18:00</option>
		<option value = "1900">19:00</option>
		</select>
	</td>
</tr>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>Venue</td>
	<td><select name = "venue">
		<option value = '' SELECTED>-Please Select-</option>
		<option value = "Lough Mask">Lough Mask</option>
		<option value = "Lough Neagh">Lough Neagh</option>
		<option value = "Lough Sheelin">Lough Sheelin</option>
		<option value = "Lough Allen">Lough Allen</option>
		<option value = "Shaw">Shaw</option>
		<option value = "Beckett">Beckett</option>
		<option value = "Yeats">Yeats</option>
		<option value = "Heaney">Heaney</option>
		<option value = "Tyndall">Tyndall</option>
		<option value = "Lilliput">Lilliput</option>
		<option value = "Lough Ree">Lough Ree</option>
		<option value = "Goldsmith">Goldsmith</option>
		<option value = "Kelvin Meeting Room">Kelvin Meeting Room</option>
		<option value = "Blyry">Blyry</option>
		<option value = "Lough Conn">Lough Conn</option>
		<option value = "Lough Corrib">Lough Corrib</option>
		<option value = "Lough Derg">Lough Derg</option>
		<option value = "Lough Owell">Lough Owell</option>
		<option value = "OSS Demo Room">OSS Demo Room</option>
		<option value = "Synge Conference Room">Synge Conference Room</option>
		<option value = "Annexe Conference Room">Annexe Conference Room</option>
		<option value = "Lars Magnus">Lars Magnus</option>
		<option value - "Office">Office</option>
		</select>
	</td>		
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<th><u>Actions<u></th>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>Type</td>
	<td><select name = "type">
		<option value = '' SELECTED>-Please Select-</option>
		<option value = "remark">Remark</option>
		<option value = "action">Action</option>
		</select>
	</td>		
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>Time</td>
	<td><select name = "time">
		<option value = '' SELECTED>-Please Select a Time-</option>
		<option value = "0800">08:00</option>
		<option value = "0900">09:00</option>
		<option value = "1000">10:00</option>
		<option value = "1100">11:00</option>
		<option value = "1200">12:00</option>
		<option value = "1300">13:00</option>
		<option value = "1400">14:00</option>
		<option value = "1500">15:00</option>
		<option value = "1600">16:00</option>
		<option value = "1700">17:00</option>
		<option value = "1800">18:00</option>
		<option value = "1900">19:00</option>
		</select>
	</td>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>Location</td>
	<td><input type = "text" name = "location" size = "10"/>
</tr>

<!-- -------------------------------------------------------------------------------- -->	

<tr>
	<td>Severity</td>
	<td><input type = "text" name = "severity" size = "10"/>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>Resp</td>
	<td><input type = "text" name = "resp" size = "10"/>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>Status</td>
	<td><input type = "text" name = "Status" size = "10"/>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>Comment</td>
	<td><textarea name = "comment" cols = 40 rows = 6/></textarea></td>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>Remark</td>
	<td><select name = "remark">
		<option value = '' SELECTED>-Please Select-</option>
		<option value = "Remark">Remark Acted</option>
		<option value = "Action">Remark Not ccepted</option>
		</select>
	</td>		
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>Miscellaneous</td>
	<td><textarea name = "miscellaneous" cols = 40 rows = 6/></textarea></td>
</tr>

<!-- -------------------------------------------------------------------------------- -->

<tr>
	<td>
		<input type="button" name="reset_form" value="Clear Fields" onclick="this.form.reset();">
		<input type="submit" name="save" value="Save MOM" />
	</td>
</tr>

<!-- -------------------------------------------------------------------------------- -->

</table>
</form>

 

and the DB lookup from that page:

if (isset($post['searchID']) && $post['searchbyequipmenttype'] != '')
{
$id = $post['searchbyequipmenttype'];
$sql = <<<SQL
SELECT *						
FROM tc_tool.forms
WHERE
(
review_id = $id
)
SQL;

$data = mysql_query($sql) or die(mysql_error()."<br>-----------<br>$sql");
$num = mysql_num_rows($data); // <-- This line is counting the number of rows returned by the query

//=====================================================
// Prints out details related to ID entered
//=====================================================

if($num != 0)
{
while($row = mysql_fetch_assoc($data))

{
echo "<table id = \"reviewid\">
<tr>
<th>Review Forum</th>
<th>Review ID</th>
<th>Document Title</th>
<th>Document Number</th>
<th>Document Type</th>
<th>Project Name</th>
<th>Author Name</th>
<th>Chairperson</th>
</tr>";


echo "<td>".custOut($row['review_forum'])	.	"</td>" .
 "<td>".custOut($row['review_id'])		.	"</td>" .
 "<td>".custOut($row['doc_title'])		.	"</td>" .
 "<td>".custOut($row['doc_number'])		.	"</td>" .
 "<td>".custOut($row['doc_type'])		.   "</td>" .
 "<td>".custOut($row['proj_name'])		.	"</td>"	.
 "<td>".custOut($row['author_name'])	.	"</td>"	.
 "<td>".custOut($row['chairperson'])	.	"</td>"	;

echo "</table>";

 

While we get to looking through this I seen that the page you PM'd me that I lifted this from has a whole lot of short open tags on it (where you have used <? instead of <?php) You need to change these to use the full <?php open tags

Link to comment
Share on other sites

Did you mean to put 3 === in the msql_affected_rows function? I changed it to two.

 

Yeah I meant to put "===",  the 'identical' comparison operator. It isn't strictly needed here given you will always have a number returned, but identical comparison is good habit to get into.

 

My result when I var_dump()ed review_id was NULL

 

That explains it then. Looking at the form mark-up Muddy_Funster posted, you don't have a "review_id" field? Where is the ID supposed to come from?

Link to comment
Share on other sites

Thanks Muddy, I changed them there. Didn't realise there was a difference.

 

@Adam, cool thanks. The review ID is generated automatically in my database, it's the primary key and whenever a form is submitted/submit button is clicked, the review_id increments each time. Should I have something like

 

$insert_query = "UPDATE tc_tool.forms	

          SET review_id = '{$post['review_id']}',

 

in my file that I am using to save the data with the ID?

Link to comment
Share on other sites

No, I'm saying that you're trying to UPDATE an existing row where the `review_id` column matches NULL. You need to provide the ID of the row you want to update, or you should be using INSERT to insert a new row where the new ID is generated for you.

Link to comment
Share on other sites

@Adam, cool thanks I understand what you mean now. If I use INSERT though will that not create a new ID instead of saving to the ID it already has? That it was doing originally - saving the data correctly but saving it as a new review_id instead of the ID it already has.

 

@Muddy, I done this -

 

Form code-

 

  
<table id = "templateHeading">
  <form action = "saveMom.php" method = "post">
<tr>
	<th><h2>MOM</h2></th>
	<th><input type = "text" name = "booking_number" size = "16" value = "" readonly = "readonly"/></th>

	<input type="hidden" id="review_id" name="review_id" value="$id" />

 

Query in saveMom.php-

 

function sanitize_data($data) // create the function sanitize_data
{
    $data = mysql_real_escape_string(trim($data));
    return $data;
}

$post = array(); 
foreach($_POST as $key =>$value){
$post[$key] = sanitize_data($value);   // call sanitize_data using each value from the $post array
}

$id = $post['review_id'];

if(isset($post['save']))
{
$insert_query = "UPDATE tc_tool.forms

			SET	quality_ranking_review = '{$post['quality_ranking_review']}',
			.......
			WHERE

			 (review_id = '{$post['review_id']}')";

 

When I run it how it is above, I get no error but still nothing stores  :facewall:

Link to comment
Share on other sites

I get this error when I add that -

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE (review_id = '407')' at line 31

 

So theres something wrong with this I think -

 

 

 WHERE

(review_id = '{$post['review_id']}')";

 

This is so annoying why wont it work!!!! I thought this part would be easy to do

 

EDIT*

 

To clarify, I'm still doing an UPDATE yeah? Not INSERT?

 

 


$insert_query = "UPDATE tc_tool.forms

			SET quality_ranking_review = '{$post['quality_ranking_review']}',
                                ................
                                WHERE
			   (review_id = '{$post['review_id']}')";

Link to comment
Share on other sites

To clarify, I'm still doing an UPDATE yeah? Not INSERT?

 

I didn't mean to confuse you bringing that subject back up, just sounded like you might have been wanting to do an insert before. You should be able to decide for yourself though; if you're updating an existing row that's an UPDATE. If you're inserting a new row, that's an INSERT.

 

 

Can you post the query as it is now?

Link to comment
Share on other sites

Muddy_Funster where have you got the 'or die' from? Are we all looking at different code or something here? The last time I saw the insert query, it was being executing with:

 

		if (!mysql_query($insert_query, $connection))
	{
		echo "Query failed: $query<br />" . mysql_error();
	}

 

Have things changed? blepblep you need to start providing the full code you're using when you get an error (not the HTML, just relevant to the query). When you're trying to debug something like this, the code is often changed and experimented with, so when you get an error we're assuming the code is what it was 10 posts ago, when it's possibly now different and the cause of the error.

Link to comment
Share on other sites

@jesirose, no, it's just to save from posting a long amount of code each time.

 

@Adam yeah I get you, I'm updating a row so it's an UPDATE, thanks  :)

 

@Muddy, I just added in this

 

mysql_query($insert_query) or die (mysql_error()."<br>-----------------------<br>$insert_query");

 

Underneath this -

WHERE

(review_id = '{$post['review_id']}')";
//var_dump($post['review_id']);

 

And its all working now?!  :confused:

Link to comment
Share on other sites

@Adam, the code hasn't changed, I was in the middle of asking where did Muddy get the 'or die' from, thats all. The error's I'm showing you here is exactly what comes up on my screen when I try to update the record.

 

I've changed JUST my error to this -


	if (!mysql_query($insert_query, $connection))
	{
		echo "Query failed: $query<br />" . mysql_error() . "<br>-----------------------<br>$insert_query";
	}

 

It's still working, but doesnt print out 'Row was updated'.

 

When I have it like this it prints out 'Row was updated'

 

mysql_query($insert_query) or die (mysql_error()."<br>-----------------------<br>$insert_query");		 

	if (mysql_affected_rows() === 1) 
	{
			echo 'Row was updated.';
	} 

	//-----------------------------
	// Prints error if there is one
	//-----------------------------

	if (!mysql_query($insert_query, $connection))
	{
		echo "Query failed: $query<br />" . mysql_error();
	}

 

 

Link to comment
Share on other sites

ok, I'm getting really confused here.  It's working?  :confused:

 

If the message isn't showing, nothing was changed (this will happen if the information in the UPDATE is the same as the infomation already in the database -from php.net : When using UPDATE, MySQL will not update columns where the new value is the same as the old value. This creates the possibility that mysql_affected_rows() may not actually equal the number of rows matched, only the number of rows that were literally affected by the query.)

 

You could put an else{} in for the if(mysql_affected_rows() === 1) that displays something to that effect.  There is no reason that the or die() would have any effect on the outcome of the query.

Link to comment
Share on other sites

Yeah, it's updating the rows now  :confused: I didn't change anything apart from what you guys said on here so I don't no why its working all of a sudden. When I done this Muddy -

 

if (mysql_affected_rows() === 1) 
	{
			echo 'Row was updated.';
	} 
	else 
	{
	                echo "nothing affected";
	}

 

It print's out 'nothing affected' but still updates the row...  :shrug:

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • 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.