Jump to content

Archived

This topic is now archived and is closed to further replies.

Gruzin

Problem with PHP/Mysql

Recommended Posts

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

[code]<?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);
?>[/code]

Share this post


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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
I've tested this and works ok:

$[code]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'];[/code]

Share this post


Link to post
Share on other sites

×

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.