|
-
Aug 18th, 2011, 12:28 AM
#1
Thread Starter
Member
javascript delete
here i have written to delete using javascript......
it is "del.php"
Code:
<script>
function fundel(sno)
{
rv=confirm("u want to delete");
if(rv==true)
{
location="delete.php?seno="+sno;
}
}
</script>
<table border="2">
<?php
mysql_connect("localhost","root","");
mysql_select_db("test");
$data=mysql_query("select * from emp");
while($rec=mysql_fetch_row($data))
{
echo "<tr><td>$rec[0]<td>$rec[1]<td>$rec[2]</tr>
<input type="button" value="delete" onclick='fundel($rec[2])'>";
}
?>
also is the "delete.php"
Code:
<?php
$qs=$_REQUEST['seno'];
mysql_connect("localhost","root","");
mysql_select_db("test");
mysql_query("delete from emp where sno=$qs");
header("location:getrec.php");
?>
it is displaying the error as Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\xampp\htdocs\del.php on line 19
tell me what went wrong....
whether it will delete the values.....
-
Aug 18th, 2011, 03:28 AM
#2
Re: javascript delete
Not to disappoint you but javascript and php have nothing to do with each other. Javascript is client-side code while php is server-side code.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Aug 18th, 2011, 12:00 PM
#3
Member
Re: javascript delete
What is on line 19 of del.php?
The one you have shown has only 7 lines.
-
Aug 18th, 2011, 12:27 PM
#4
Re: javascript delete
del.php is the first snippet he posted, PBertie. Your problem is here:
PHP Code:
echo "<tr><td>$rec[0]<td>$rec[1]<td>$rec[2]</tr> <input type="button" value="delete" onclick='fundel($rec[2])'>";
PHP can't do multi-line strings like that.
Edit: the above is full of stupid. Below is a possible correction you can use (also see techgnome's below), and some other fun ways you can write strings:
PHP Code:
//Escape the double quotes: echo "<tr><td>$rec[0]<td>$rec[1]<td>$rec[2]</tr> <input type=\"button\" value=\"delete\" onclick='fundel($rec[2])'>";
//Use a single line: echo "<tr><td>$rec[0]<td>$rec[1]<td>$rec[2]</tr><input type=\"button\" value=\"delete\" onclick='fundel($rec[2])'>";
//Use concatenation: echo "<tr><td>$rec[0]<td>$rec[1]<td>$rec[2]</tr>". "<input type=\"button\" value=\"delete\" onclick='fundel($rec[2])'>";
//Use heredoc notation: echo <<<DOC <tr><td>$rec[0]<td>$rec[1]<td>$rec[2]</tr> <input type="button" value="delete" onclick='fundel($rec[2])'> DOC;
Last edited by SambaNeko; Aug 18th, 2011 at 02:19 PM.
-
Aug 18th, 2011, 01:52 PM
#5
Re: javascript delete
"PHP can't do multi-line strings like that." -- what? SHENNANIGANS! It can too... I do it all the time (usually when I'm dealing with SQL queries)... the problem is the " that are in the middle of the string... around button and delete.... they should be enclosed in single quote marks:
PHP Code:
echo "<tr><td>$rec[0]<td>$rec[1]<td>$rec[2]</tr> <input type='button' value='delete' onclick='fundel($rec[2])'>";
-tg
-
Aug 18th, 2011, 02:15 PM
#6
Re: javascript delete
Whoops, sorry, don't know what I was thinking (something stupid, clearly). Post edited for clarity++
I should also add it's usually best not to echo a bunch of HTML anyway; write your PHP as an embedded language:
PHP Code:
<?php //php here... ?> <tr><td><?php echo $rec[0];?><td><?php echo $rec[1];?><td><?php echo $rec[2];?></tr> <input type="button" value="delete" onclick='fundel(<?php echo $rec[2];?>)'> <?php //more php here... ?>
So I am being stupid and lazy lately.
Last edited by SambaNeko; Aug 18th, 2011 at 02:24 PM.
-
Aug 19th, 2011, 02:30 AM
#7
Re: javascript delete
 Originally Posted by SambaNeko
I should also add it's usually best not to echo a bunch of HTML anyway
I would also add that its usually best not to allow direct SQL injection attacks
-
Aug 19th, 2011, 09:58 AM
#8
Re: javascript delete
Picky, picky.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|