Pandareen Posted January 1, 2012 Share Posted January 1, 2012 It echoes only ERROR and i don't know why?can i get some help please? 1.index.php: ... <tr> <td width="128"><?php echo $row_Recordset1['pacientID']; ?></td> <td width="111"><?php echo $row_Recordset1['nume']; ?></td> <td width="128"><?php echo $row_Recordset1['prenume']; ?></td> <td width="122"><?php echo $row_Recordset1['cnp']; ?></td> <td width="192"><?php echo $row_Recordset1['data']; ?></td> <td width="192"><a href="delete_inregistrare.php?pacientID=<? echo $rows['pacientID']; ?>">Elimiare Pacient</a></td> </tr> ... 2.delete_inregistrare.php <?php $host="#####"; $username="#####"; $password="######"; $db_name="model_healthcare"; $tbl_name="pacienti"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $pacientID=$_GET['pacientID']; $sql="DELETE FROM $tbl_name WHERE pacientID='$pacientID'"; $result=mysql_query($sql); if($result){ echo "Deleted Successfully"; } else { echo "ERROR"; } mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/254162-delete-data/ Share on other sites More sharing options...
litebearer Posted January 1, 2012 Share Posted January 1, 2012 1. are you SURE it is connecting to the db? 2. did you try echoing your #sql to make sure it contains the values you expect? Quote Link to comment https://forums.phpfreaks.com/topic/254162-delete-data/#findComment-1303037 Share on other sites More sharing options...
Pandareen Posted January 1, 2012 Author Share Posted January 1, 2012 yeah, the connection is ok, and the echo works...do u have any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/254162-delete-data/#findComment-1303038 Share on other sites More sharing options...
mika Posted January 1, 2012 Share Posted January 1, 2012 For debugging purposes, you should echo the exact error, not a general message, replace: echo "ERROR"; with echo mysql_error(); and see what it says. Quote Link to comment https://forums.phpfreaks.com/topic/254162-delete-data/#findComment-1303040 Share on other sites More sharing options...
Pandareen Posted January 1, 2012 Author Share Posted January 1, 2012 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 'pacientID']; ?>'' at line 1 This is the error!thnx for the tip...but i don't know how to fix it :-s Quote Link to comment https://forums.phpfreaks.com/topic/254162-delete-data/#findComment-1303041 Share on other sites More sharing options...
mika Posted January 1, 2012 Share Posted January 1, 2012 You are missing the <?php tag, short tags are not enabled on your server: Change: <td width="192"><a href="delete_inregistrare.php?pacientID=<? echo $rows['pacientID']; ?>">Elimiare Pacient</a></td> to <td width="192"><a href="delete_inregistrare.php?pacientID=<?php echo $rows['pacientID']; ?>">Elimiare Pacient</a></td> Quote Link to comment https://forums.phpfreaks.com/topic/254162-delete-data/#findComment-1303042 Share on other sites More sharing options...
mika Posted January 1, 2012 Share Posted January 1, 2012 Another thing. You are allowing SQL injection. Sanitize your input data or at least do this $pacientID=(int)$_GET['pacientID']; assuming pacientID is an integer. Quote Link to comment https://forums.phpfreaks.com/topic/254162-delete-data/#findComment-1303044 Share on other sites More sharing options...
Pandareen Posted January 1, 2012 Author Share Posted January 1, 2012 okeeeeey, now it shows "Deleted Successfully" but data is still there after refresh, and the database is unchanged :-s Quote Link to comment https://forums.phpfreaks.com/topic/254162-delete-data/#findComment-1303045 Share on other sites More sharing options...
mika Posted January 1, 2012 Share Posted January 1, 2012 Echo your $sql statement and check what is the pacientID value. Also check the link, if pacientID= is not empty. Quote Link to comment https://forums.phpfreaks.com/topic/254162-delete-data/#findComment-1303046 Share on other sites More sharing options...
Pandareen Posted January 1, 2012 Author Share Posted January 1, 2012 like so? DELETE FROM pacienti WHERE pacientID=' Notice: Undefined variable: rows in ...../administrare.php on line 83 ' and line 83 is this: <td width="192"><a href="delete_inregistrare.php?pacientID=<?php echo $rows['pacientID']; ?>">Elimiare Pacient</a></td> Quote Link to comment https://forums.phpfreaks.com/topic/254162-delete-data/#findComment-1303047 Share on other sites More sharing options...
mika Posted January 1, 2012 Share Posted January 1, 2012 I assume $rows should be replaced with $row_Recordset1... Again do Input Sanitization Quote Link to comment https://forums.phpfreaks.com/topic/254162-delete-data/#findComment-1303049 Share on other sites More sharing options...
Pandareen Posted January 1, 2012 Author Share Posted January 1, 2012 i don't need security 'cuz is only a project ( for now ) but thnx.Look what shows with recordset: Cannot delete or update a parent row: a foreign key constraint fails (`model_healthcare`.`internari`, CONSTRAINT `internari_ibfk_1` FOREIGN KEY (`pacientID`) REFERENCES `pacienti` (`pacientID`)) Quote Link to comment https://forums.phpfreaks.com/topic/254162-delete-data/#findComment-1303050 Share on other sites More sharing options...
mika Posted January 1, 2012 Share Posted January 1, 2012 The record you are attempting to delete is used in some other table(s). You should delete these record(s) first. Quote Link to comment https://forums.phpfreaks.com/topic/254162-delete-data/#findComment-1303051 Share on other sites More sharing options...
Pandareen Posted January 1, 2012 Author Share Posted January 1, 2012 Yeah i know , is a foreign key for a "bigger table", but is a way to delete those records too? Quote Link to comment https://forums.phpfreaks.com/topic/254162-delete-data/#findComment-1303052 Share on other sites More sharing options...
mika Posted January 1, 2012 Share Posted January 1, 2012 $tbl_name = 'BIGGER TABLE'; $sql="DELETE FROM $tbl_name WHERE pacientID='$pacientID'"; $result=mysql_query($sql); Replace BIGGER TABLE with exact table name. I hope this is what you would like to do. Quote Link to comment https://forums.phpfreaks.com/topic/254162-delete-data/#findComment-1303053 Share on other sites More sharing options...
Pandareen Posted January 1, 2012 Author Share Posted January 1, 2012 $host="localhost"; $username="root"; $password="administrator"; $db_name="model_healthcare"; $tbl_name="pacienti"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $pacientID=$_GET['pacientID']; $tbl_name = 'internari'; $sql="DELETE FROM $tbl_name WHERE pacientID='$pacientID'"; $result=mysql_query($sql); $sql2="DELETE FROM $tbl_name WHERE pacientID='$pacientID'"; $result=mysql_query($sql2); i've tried like this but is the same result..no change Quote Link to comment https://forums.phpfreaks.com/topic/254162-delete-data/#findComment-1303054 Share on other sites More sharing options...
mika Posted January 1, 2012 Share Posted January 1, 2012 Try with this: $host="localhost"; $username="root"; $password="administrator"; $db_name="model_healthcare"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $pacientID=$_GET['pacientID']; $tbl_name = 'internari'; $sql="DELETE FROM $tbl_name WHERE pacientID='$pacientID'"; $result=mysql_query($sql); $tbl_name="pacienti"; $sql2="DELETE FROM $tbl_name WHERE pacientID='$pacientID'"; $result=mysql_query($sql2); Quote Link to comment https://forums.phpfreaks.com/topic/254162-delete-data/#findComment-1303056 Share on other sites More sharing options...
Pandareen Posted January 1, 2012 Author Share Posted January 1, 2012 same result....no change Quote Link to comment https://forums.phpfreaks.com/topic/254162-delete-data/#findComment-1303059 Share on other sites More sharing options...
mika Posted January 1, 2012 Share Posted January 1, 2012 Please provide more information. 1. are there any errors: first SQL, second SQL; is $pacientID non empty? 2. are records from 'internari' deleted or not 3. are there any other foreign keys associated to "pacienti" 4. other messages, notices,... Quote Link to comment https://forums.phpfreaks.com/topic/254162-delete-data/#findComment-1303063 Share on other sites More sharing options...
Pandareen Posted January 1, 2012 Author Share Posted January 1, 2012 yessssss it worked now, i forgot to replace $row with $recordset1 on your script.Thnx a lot man Quote Link to comment https://forums.phpfreaks.com/topic/254162-delete-data/#findComment-1303068 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.