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