Jump to content

updating an sql database


dsjoes

Recommended Posts

i have 3 php scripts to update the database but i cannot get them to display anything.

the first script holds the login details, host and database name.

 

this is the second script called update.php and it just displays a blank page.

<?
include("dbinfo.inc.php");
mysql_connect($localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM News WHERE id='$id'";
$result=mysql_query($query);
echo $sql; 
$num=mysql_numrows($result); 
mysql_close();

$i=0;
while ($i < $num) {
$News=mysql_result($result,$i,"Clan News");


?>

<form action="updated.php">
<input type="hidden" name="ud_id" value="<? echo "$id"; ?>">
News: <input type="text" name="ud_News" value="<? echo "$News"?>"><br>
<input type="Submit" value="Update">
</form>

<?
++$i;
} 
?>

 

this is the third script called updated.php i have not tryed this yet because it needs script 2 to work.

<?
include("dbinfo.inc.php");
mysql_connect($localhost,$username,$password);

$query="UPDATE News SET News='$ud_News' WHERE id='$ud_id'";
@mysql_select_db($database) or die( "Unable to select database");
mysql_query($query);
echo "Record Updated";
mysql_close();
?>

 

any help please

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/208479-updating-an-sql-database/
Share on other sites

You aren't assigning values to the variables before trying to use them. Also, you should replace all the short open <?tags with the full <?php tags in all of your scripts.

 

<?php
include("dbinfo.inc.php");
mysql_connect($localhost,$username,$password);

$ud_id = (int)$_GET['ud_id'];
$ud_news = mysql_real_escape_string($_GET['ud_news']);

$query="UPDATE News SET News='$ud_News' WHERE id='$ud_id'";
mysql_select_db($database) or die( "Unable to select database");
mysql_query($query);
echo "Record Updated";
mysql_close();
?>

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.