PDA

View Full Version : FAO anyone who knows PHP/mySQL



wisewood
30-05-03, 05:19 PM
HELP ME!!!
I am trying to get this to work - http://www.wisew.com/tests/update2.php
So far it works right up to the point where it has to update the database and then it takes me back to the list as it should do, but doesnt alter the entry on the database.

Here is the code:


<form action="<? echo $PHP_SELF ?>" method="post">
<?
mysql_pconnect&#40;"localhost","db_username","db_password"&#41;;
mysql_select_db&#40;"db_name"&#41;;
if&#40;!$cmd&#41;
&#123;
$result = mysql_query&#40;"select * from table_name"&#41;;
while&#40;$r=mysql_fetch_array&#40;$result&#41;&#41;
&#123;
$who=$r&#91;"who"&#93;;
$email=$r&#91;"email"&#93;;
$title=$r&#91;"title"&#93;;
$body=$r&#91;"body"&#93;;
$id=$r&#91;"ID"&#93;;
?>
<INPUT TYPE="RADIO" NAME="id" VALUE="<?php echo $id;?>"><? echo $id;?> <? echo $title ?>

<? &#125; ?>
<input type="submit" name="cmd" value="edit"></form>
<? &#125; ?>

<?
if&#40;$cmd=="edit"&#41;
&#123;
if &#40;!$submit&#41;
&#123;
$sql = "SELECT * FROM table_name WHERE ID=$id";
//replace news with your table name above
$result = mysql_query&#40;$sql&#41;;
$myrow = mysql_fetch_array&#40;$result&#41;;
?>
<input type=hidden name="ID" value="<?php echo $myrow&#91;"ID"&#93; ?>">
Who&#58;<INPUT TYPE="TEXT" NAME="who" VALUE="<?php echo $myrow&#91;"who"&#93; ?>" SIZE=30>

email&#58;<INPUT TYPE="TEXT" NAME="email" size="30" VALUE="<? echo $myrow&#91;"email"&#93; ?>">

title&#58;<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow&#91;"title"&#93; ?>" SIZE=30>

body&#58;<TEXTAREA NAME="body" ROWS=10 COLS=50><?php echo $myrow&#91;"body"&#93; ?>
</TEXTAREA>

<input type="hidden" name="cmd" value="edit">
<input type="Submit" name="submit" value="Post Comment">
</form>
<? &#125; ?>

<?
if&#40;$submit&#41;
&#123;
$sql = "UPDATE table_name SET who='$who',email='$email',title='$title', body='$body' WHERE ID=$id";
$result = mysql_query&#40;$sql&#41;;
echo "Thank you! Information updated.";
&#125;
&#125;
?>


I have been trying for a couple of days to figure this out, but i just cant make it work and its doing my head in!!!

I have checked more times than i could count that i am using the right username/password/database/table/field names... someone must be able to make this code work for me... PLEASE!!!