PHP question
- Started
- Last post
- 7 Responses
- Nac
hey guys, been dipping into PHP, and can't seem to get this update record in mysql script to work.....
Any suggestions?
Thank you in advance!
require("database_variables.php...
$id=$_POST['id'];
$title=$_POST['title'];
$news=$_POST['news'];$link = mysql_connect($host,$usr,$pwd);
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)or die("Couldn't open $db: ".mysql_error());
mysql_query(" UPDATE mainnews SET title='$title' , news='$news' WHERE id='$id'");
echo "Record Updated for ID#: $id, Click here to return to the main news admin";mysql_close($link);
- phirschybar0
what error message are you getting?
- unfittoprint0
tip: instead of
$id=$_POST['id'] ; $title=$_POST['t itle']; $news=$_POST['news']
use
foreach ($_REQUEST as $key => $value) {
$$key = $value;
}and you'll get all your post/get/cookie data [no sessions tough].
also:
I learned that what worked in mylocalhost wouldn't work on the server, so you could try to addslashes() to your string variables before doing the update query.
- Nac0
hmm ok..... thanks un
but phirschybar i actually don't get a error message, it returns as it went through fien but when i check the db, nothing is changed
- zackgilbert0
try:
$result = mysql_query("UPDATE...");
if($result){
echo "Record Updated...";
}else{
die('Query failed: ' . mysql_error())
}you're not really testing for errors. use the error reporting to your advantage. im sure you'll find something in there.
- Nac0
Thanks Zack I am going to give that a try...
btw pretty nice projects youve worked on brother
- zackgilbert0
thanks.
hope that works for you. let me know if it's still giving you problems.
- Nac0
Still some problems, but I am working them out, thank you guys!