Jump to content


Photo

Inserting Jscript into PHP


  • Please log in to reply
4 replies to this topic

#1 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 24 July 2006 - 05:59 PM

Can someone please tell me how to correct this line of code?
It is for a radio button so when a button is clicked it opens deletenews.php?id= and the id number of the record to be deleted so the correct record is deleted from the database

I have tried this
echo("<input style=\"border:none;\" type=\"radio\" name=\"loc\" onClick=\"go(\'deletenews.php?id=<? echo $code[\'id\']; ?>\');\">".$code->title."<BR>");
and it reports T_BAD_CHARACTER.

I have tried
echo("<input style=\"border:none;\" type=\"radio\" name=\"loc\" onClick=\"go(\'deletenews.php?id=".$code->id."');\">".$code->title."<BR>");
but that doesn't delete the record when clicked
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 24 July 2006 - 06:12 PM

Only escape the type of quote character you're using to delimite the echo string, not both. Also, you're already in an echo statement, the second one is illegal.
<?php
echo "<input style=\"border:none;\" type=\"radio\" name=\"loc\" onClick=\"go('deletenews.php?id=" . $code['id'] . "');\">".$code->title."<BR>";?>

Ken

#3 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 24 July 2006 - 06:35 PM

I get the error message syntax error, unexpected $end
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 24 July 2006 - 06:37 PM

Can we see the rest of your code?

That error is usually caused by a missing end quote or curly brace "}".

Ken

#5 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 24 July 2006 - 10:18 PM

<?php 
//REMEMBER TO CONNECT TO DATABASE! 

include_once("../includes/connection.php");
    @mysql_connect($host, $user, $password) or die("ERROR--CAN'T CONNECT TO SERVER"); 
    @mysql_select_db($database) or die("ERROR--CAN'T CONNECT TO DB"); 
//**EDIT TO YOUR TABLE NAME, ECT. 

$t = mysql_query("SELECT * FROM `news`"); 
  if(!$t) die(mysql_error()); 
    
$a                = mysql_fetch_object($t); 
$total_items      = mysql_num_rows($t); 
$limit            = $_GET['limit']; 
$type             = $_GET['type']; 
$page             = $_GET['pagenum']; 

//set default if: $limit is empty, non numerical, less than 2, greater than 50 
if((!$limit)  || (is_numeric($limit) == false) || ($limit < 2) || ($limit > 50)) { 
     $limit = 2; //default 
} 
//set default if: $page is empty, non numerical, less than zero, greater than total available 
if((!$page) || (is_numeric($page) == false) || ($page < 0) || ($page > $total_items)) { 
      $page = 1; //default 
} 

//calcuate total pages 
$total_pages     = ceil($total_items / $limit); 
$set_limit          = $page * $limit - ($limit); 

//query: **EDIT TO YOUR TABLE NAME, ECT. 

$q = mysql_query("SELECT * FROM `news` LIMIT $set_limit, $limit"); 
  if(!$q) die(mysql_error()); 
     $err = mysql_num_rows($q); 
       if($err == 0) die("No matches met your criteria."); 

//Results per page: **EDIT LINK PATH** 
echo("   
<a href=?page=delete_news&limit=10&amp;pagenum=1></a> 
<a href=?page=delete_news&limit=25&amp;pagenum=1></a> 
<a href=?page=delete_news&limit=50&amp;pagenum=1></a>"); 

//show data matching query:

while($code = mysql_fetch_object($q)) { 
echo "<input style=\"border:none;\" type=\"radio\" name=\"loc\" onClick=\"go('deletenews.php?id=" . $code['id'] . "');\">".$code->title."<BR>";?>
}


$id = urlencode($id); //makes browser friendly 

//prev. page: **EDIT LINK PATH** 

$prev_page = $page - 1; 

if($prev_page >= 1) { 
  echo("<b>&lt;&lt;</b> <a href=?page=delete_news&limit=$limit&amp;pagenum=$prev_page><b>Prev.</b></a>"); 
} 

//Display middle pages: **EDIT LINK PATH** 

for($a = 1; $a <= $total_pages; $a++) 
{ 
   if($a == $page) { 
      echo("<b> $a</b> | "); //no link 
     } else { 
  echo("  <a href=?page=delete_news&limit=$limit&amp;pagenum=$a> $a </a> | "); 
     } 
} 

//next page: **EDIT THIS LINK PATH** 

$next_page = $page + 1; 
if($next_page <= $total_pages) { 
   echo("<a href=?page=delete_news&limit=$limit&amp;pagenum=$next_page><b>Next</b></a> &gt; &gt;"); 
} 

//all done 
?>

(Note: edited to put in the [code][/code] tags by a moderator)
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users