...

View Full Version : Sorry me again....just trying to update a record



lane87
12-17-2010, 05:31 PM
Hey Guys,

Sorry to bother you, im slightly stuck on updating a record in a database, i have an edit page with a form which shows a text box with text of a certain page in. Like this:


<table width="400" border="0" align="center" cellpadding="3" cellspacing="1">
<tr>
<td><strong>Edit About Us English </strong></td>
</tr>
</table>

<table width="400" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form1" method="post" action="send_update_english.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">

<tr>
<td>Detail</td>
<td>:</td>
<td><textarea name="detail" cols="50" rows="4" id="detail">

<?php

mysql_connect("localhost", "web148", "123") or die(mysql_error());
mysql_select_db("web148") or die(mysql_error());

mysql_query("SET names 'utf8'");

$result = mysql_query("SELECT body FROM aboutenglish WHERE ID = '1'");


// get the first (and hopefully only) entry from the result
$row = mysql_fetch_array( $result );
// Print out the contents of each row into a table

echo nl2br($row['body']);


?>

</textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>

Im not sure if thats done correctly or not, but it does what i need to.

From there i can edit the text but when i click the submit button the database is blank.

The 'send form' code is like this:


<?php

// Details
$message="$detail";

mysql_connect("localhost", "web148", "123") or die(mysql_error());
mysql_select_db("web148") or die(mysql_error());

mysql_query("SET names 'utf8'");
$result = mysql_query("UPDATE aboutenglish SET body = '$message' where ID = '1'");


?>

The actual update query works fine i think its just passing the values between the two pages i mean i have:

edit page:

<td><textarea name="detail" cols="50" rows="4" id="detail">

send form page:

$message="$detail";
$result = mysql_query("UPDATE aboutenglish SET body = '$message' where ID = '1'");



If anyone could help id really appreciate it.

Cheers

bdl
12-17-2010, 05:39 PM
Assuming the second bit of code (the 'send form' code, as you put it) is the script 'send_update_english.php', let's examine what the script is doing.

$message="$detail";
Ok, so in this assignment, where does the variable $detail come from?

Read this (http://us2.php.net/manual/en/security.globals.php) and this (http://us2.php.net/manual/en/language.variables.predefined.php) before you proceed.



$result = mysql_query("UPDATE aboutenglish SET body = '$message' where ID = '1'");

How do you know that the record you want to update has the ID of '1'? You don't pass anything else to the script to allow for a specific ID value to be updated. I get that your form contains the SQL statement to pull the data from a record with ID = 1, but do you assume your application will always use that ID?

The real issue for now is "where does $detail come from". Once you get that worked out you can figure out the rest, e.g targeting different records based on ID value.

By the way, you do not need to quote "$detail" in your assignment - only use double quotes to parse variables inside a larger string. You can just assign $one_variable = $another_variable at any time.

mlseim
12-17-2010, 05:50 PM
It should look like this ....

// Details
$message=$_POST['$detail'];
$message=mysql_real_escape_string($message);







.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum