Jump to content

Need Help Please


Elcar

Recommended Posts

Hi I am a amature at php coding I have tried all I know to get this to work, its a code to update the data in a MYSQL Data Base, the code to add, view and delete stuff works just not the edit script although it says it was Successful.

 

here is the code I am using one is for the update.php and the other is for the update_ac.php

 

update.php code

<?PHP

include_once("navigation.php");

?>

<!-- Update Code -->

<?php

$host="localhost"; // Host name

$username="user"; // Mysql username

$password="pass"; // Mysql password

$db_name="db_name"; // Database name

$tbl_name="table"; // Table name

 

// Connect to server and select database.

mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

 

// get value of id that sent from address bar

$id=$_GET['id'];

 

 

// Retrieve data from database

$sql="SELECT * FROM $tbl_name WHERE id='$id'";

$result=mysql_query($sql);

 

$rows=mysql_fetch_array($result);

?>

<table align="center" width="400" border="0" cellspacing="1" cellpadding="0">

<tr>

<form name="form1" method="post" action="update_ac.php">

<td>

<table width="100%" border="0" cellspacing="1" cellpadding="0">

<tr>

<td> </td>

<td align="center" colspan="3"><strong>Edit News</strong><br>

<textarea name="content" maxlength="255" type="text" id="content" rows="10" cols="50" value="" size="15"><? echo $rows['content']; ?></textarea>

<br>

<?PHP

include_once("./include/author.php");

  $count = 0;

    foreach($LINK_ARRAY as $set){

$logged_in = false;

if(isset($user) && isset($pass) && isset($auth)){

$logged_in = true;

}

if( ($logged_in && ($auth >= $set['auth']) && $set['auth'] != -1) || ($set['auth'] == 0) || (!$logged_in && $set['auth'] == -1) ){

if($set['auth'] == -2 && $LINK_ARRAY[$count + 1]['auth'] <= $auth){

echo "<p><center><img src='./images/mblank2.gif'></center><br></p><center><strong>".$set['text']."</strong></center><br>";

}elseif($set['auth'] != -2){

$image = $set['imge'];

if($set['imge'] == NULL){

$image = '_home';

}

 

?>

         

               

<label>

<input type="radio" name="author" id="author" value="<? echo $set["author"]; ?>">

                <? echo $set["author"]; ?>

</label>

                <br>

             

             

  <?

}

}

$count++;

}

?>

<br>

 

<input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>">

<input type="submit" name="Submit" value="Submit"></td>

</tr>

</table>

</td>

</form>

</tr>

</table>

 

<?

 

// close connection

mysql_close();

 

?>

 

update_ac.php code

<?php

$host="localhost"; // Host name

$username="user"; // Mysql username

$password="pass"; // Mysql password

$db_name="db_name"; // Database name

$tbl_name="table"; // Table name

 

// Connect to server and select database.

mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

 

// update data in mysql database

$sql="UPDATE $tbl_name SET id='$id', content='$content', author='$author' WHERE id='$id'";

$result=mysql_query($sql);

 

// if successfully updated.

if($result){

echo "<center>";

echo "Successful";

echo "<BR>";

echo "<a href='view_del.php'>View News</a>";

echo "<br>";

echo "<a href='index.php'>Back to Main</a>";

echo "</center>";

}

 

else {

echo "ERROR";

}

 

?>

 

please does anyone have an idea what I am doing wrong

 

Thank You in Advanced for your help

Link to comment
https://forums.phpfreaks.com/topic/220183-need-help-please/
Share on other sites

I don't see where your values are being set before building this SQL:

 

$sql="UPDATE $tbl_name SET id='$id', content='$content', author='$author' WHERE id='$id'";

 

echo the sql to see:

 

$sql="UPDATE $tbl_name SET id='$id', content='$content', author='$author' WHERE id='$id'";
echo "sql: $sql <br />";

 

You need to set $id, $content and $author.

 

you also do not need to include "set id='$id'" in your update SQL, as id is already = id.

Link to comment
https://forums.phpfreaks.com/topic/220183-need-help-please/#findComment-1141136
Share on other sites

I don't think I under stand I tried adding this

 

$sql="UPDATE $tbl_name SET content='$content', author='$author' WHERE id='$id'";

echo "sql: $sql <br />";

 

but I just get an ERROR

 

I am really new to php scripts most of this script is off a tutorial site, they had no info on the edit though

Link to comment
https://forums.phpfreaks.com/topic/220183-need-help-please/#findComment-1141143
Share on other sites

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.