Jump to content


Photo

Problem with PHP/Mysql


  • Please log in to reply
7 replies to this topic

#1 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 30 August 2006 - 01:22 PM

hi guys, I want to display the result form db and add it some Edit and Delete function, here is my effort but think I'am not on  a correct way. Your ideas will be very appreciated.

P.S I won't post the Reslut script, it works ok, here is the delete function, which of course doesn't work...

<?php
$con = mysql_connect("localhost","user","pass"); //connect to db
if(!$con){
  die('Error:'.mysql_error());
  }
mysql_select_db("user", $con); //select db

$query = "SELECT * FROM link_manager WHERE id ORDER BY id";
$result = mysql_query($query) or die("Error: " . mysql_error());
while($row = mysql_fetch_array($result))
$id = $row['id'];
$query2 = "DELETE * FROM link_manager WHERE id = $id";
$result2 = mysql_query($query2) or die("Error: " . mysql_error());
header( 'Location: http://www.mysite.net/links/') ;
mysql_close($con);
?>

I don't need your script, I'll try to write it myself

#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 30 August 2006 - 01:35 PM

where id = what?????

that is your problem!

follow me on twitter @PHPsycho

#3 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 30 August 2006 - 01:36 PM

To be more clear, ToonMariner meant this line:
$query = "SELECT * FROM link_manager WHERE id <you are missing an ID value> ORDER BY id";

Info: PHP Manual


#4 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 30 August 2006 - 01:37 PM

yea, I know but I can't figure it out..
I want this to be dinamic, I mean when I add a new record to db, it should add Edit And Delete link (function) automatically.
I don't need your script, I'll try to write it myself

#5 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 30 August 2006 - 01:39 PM

here is the error:

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM link_manager WHERE id = 47' at line 1
I don't need your script, I'll try to write it myself

#6 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 30 August 2006 - 01:58 PM

Think I need a Guru help...
I don't need your script, I'll try to write it myself

#7 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 30 August 2006 - 02:01 PM

echo your query to the screen and comment out the execution of the query - then check it in phpmyadmin - it may point out something more.

This will probably be a case of some single or double quote issue...


follow me on twitter @PHPsycho

#8 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 30 August 2006 - 02:05 PM

I've tested this and works ok:

$
query = "SELECT * FROM link_manager WHERE id ORDER BY id";
$result = mysql_query($query) or die("Error: " . mysql_error());
while($row = mysql_fetch_array($result))
echo $row['id'];

I don't need your script, I'll try to write it myself




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users