Jump to content

babak83

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

babak83's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. sql not successful: 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 '; insert into admin_users values( '3' , 'admin' , '558341344316
  2. HI , I have written small code to generate backup from a mysql Database and save as a sql file, It workds great and no problem till here , but when I am trying to restore the sql file I get error in mysql syntax (I think it is because of existing semicolons in the sql file) I put the sql file content into a variable $sql for exmple and try mysql_query($sql) , How may I solve this prob ? this is the code : $file = fopen($filename,"r"); $line_count = load_backup_sql($file); fclose($file); echo "lines read: ".$line_count; function load_backup_sql($file) { $line_count = 0; $db_connection = db_connect(); mysql_select_db (db_name()) or exit(); while (!feof($file)) { $query = NULL; while (!feof($file)) { $query .= fgets($file); } if ($query != NULL) { $line_count++; mysql_query($query) or die("sql not successful: ".mysql_error()); } } return $line_count; } function db_name() { return ("db_name"); } function db_connect() { $db_connection = mysql_connect("localhost", "user", "pass"); return $db_connection; }
  3. [!--quoteo(post=382181:date=Jun 10 2006, 03:28 AM:name=babak83)--][div class=\'quotetop\']QUOTE(babak83 @ Jun 10 2006, 03:28 AM) [snapback]382181[/snapback][/div][div class=\'quotemain\'][!--quotec--] Hello every one ! I have written the following code for showing the results of a poll in my site but it dose not working (in firefox it says : "The image “http://127.0.0.1/poll/Poll.php” cannot be displayed, because it contains errors.") Please help me solve the problem .Tanks in advance [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /] <?php header ("Content-type: image/png"); $vote=$_POST['vote']; if(! $db_conn=@mysql_connect("localhost","babak","159753")) { echo'Error ! Cannot Connect to DB !!'; exit; } @mysql_select_db('poll'); if (!empty($vote)) { $vote = addslashes($vote); $query="update poll_resuls set num_votes = num_votes + 1 where candidate = '$vote'"; if (!($result=@mysql_query($query, $db_conn))) echo 'Error !! Could Not execute The Query !'; exit; } else { echo'Go Back and Compelete The form'; } $query ='select * from poll_resuls'; if(!($result = @mysql_query($query, $db_conn))) { echo 'Error !! Can not connect to db !'; } $num_candidate = mysql_num_rows($result); $total_votes = 0; while ($row = mysql_fetch_object ($result)) { $total_votes+= $row->num_votes; } mysql_data_seek($result, 0); //***********************graphic*************************** $width=500; $left_margin=50; $right_margin=50; $bar_height=40; $bar_spacing=$bar_height/2; $font='c:\windows\fonts\arial.TTF'; $title_size=16; $main_size=12; $small_size=12; $text_indent=10; $x=$left_margin + 60; $y=50; $bar_unit=($width-($x+$right_margin))/100; $height=$num_candidate * ($bar_height + $bar_spacing) +50; $im = imagecreate($width,$height); $white= ImageColorAllocate ($im, 255, 255, 255); $blue= ImageColorAllocate ($im, 0, 64, 128); $black= ImageColorAllocate ($im, 0, 0, 0); $pink= ImageColorAllocate ($im, 255, 78, 243); $text_color=$black; $bg_color=$white; $line_color=$black; $bar_color=$blue; $number_color=$pink; ImageFilledRegtangle( $im, 0, 0, $width, $height, $bg, $bg_color); ImageRegtangle( $im, 0, 0, $width-1, $height-1, $line_color); $title='Poll Results :'; $title_dimensions=ImageTTFBBox( $title_size, 0, $font, $title); $title_length=$title_dimensions[2] - $title_dimensions[0] ; $title_height=abs($title_dimensions[7] - $title_dimensions[1]); $title_above_line = abs($title_dimensions[7]); $title_x=($width - $title_length)/2; $title_y=($y - $title_height)/2 + $title_above_line; ImageString($im, $title_size, $title_x, $title_y, $title, $text_color); ImageLine($im, $x, $y-5, $x, $height-15, $line_color); while($row = mysql_fetch_object($result)) { if($total_votes > 0) $percent = intval(round(($row->num_votes/$total_votes)*100)); else $percent=0; ImageString($im, $main_size, $width-30, $y+($bar_height/2), $percent.'%', $percent_color); if($total_votes > 0) $right_value= intval(round(($row->num_votes/$total_votes)*100)); else $right_value = 0; $bar_length= $x+($right_value * $bar_unit); ImageFilledRegtangle($im, $x, $y-2, $bar_length, $y+$bar_height, $bar_color); ImageString($im,$main_size,$text_indent,$y+($bar_height/2),"$row->candidate", $text_color); ImageRegtangle($im,$bar_length+1,$y-2,($x+(100*$bar_unit)), $y+$bar_height, $line_color); ImageString($im,$small_size, $x+(100*$bar_unit)-50, $y+($bar_heigth/2), $row->num_votes.'/'.$total_votes, $number_color); $y=$y+($bar_height + $bar_spacing); } ImagePng ($im); ImageDestroy($im); ?> [/quote]
  4. Hello every one ! I have written the following code for showing the results of a poll in my site but it dose not working (in firefox it says : "The image “http://127.0.0.1/poll/Poll.php” cannot be displayed, because it contains errors.") Please help me solve the problem .Tanks in advance [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /] <?php header ("Content-type: image/png"); $vote=$_POST['vote']; if(! $db_conn=@mysql_connect("localhost","babak","159753")) { echo'Error ! Cannot Connect to DB !!'; exit; } @mysql_select_db('poll'); if (!empty($vote)) { $vote = addslashes($vote); $query="update poll_resuls set num_votes = num_votes + 1 where candidate = '$vote'"; if (!($result=@mysql_query($query, $db_conn))) echo 'Error !! Could Not execute The Query !'; exit; } else { echo'Go Back and Compelete The form'; } $query ='select * from poll_resuls'; if(!($result = @mysql_query($query, $db_conn))) { echo 'Error !! Can not connect to db !'; } $num_candidate = mysql_num_rows($result); $total_votes = 0; while ($row = mysql_fetch_object ($result)) { $total_votes+= $row->num_votes; } mysql_data_seek($result, 0); //***********************graphic*************************** $width=500; $left_margin=50; $right_margin=50; $bar_height=40; $bar_spacing=$bar_height/2; $font='c:\windows\fonts\arial.TTF'; $title_size=16; $main_size=12; $small_size=12; $text_indent=10; $x=$left_margin + 60; $y=50; $bar_unit=($width-($x+$right_margin))/100; $height=$num_candidate * ($bar_height + $bar_spacing) +50; $im = imagecreate($width,$height); $white= ImageColorAllocate ($im, 255, 255, 255); $blue= ImageColorAllocate ($im, 0, 64, 128); $black= ImageColorAllocate ($im, 0, 0, 0); $pink= ImageColorAllocate ($im, 255, 78, 243); $text_color=$black; $bg_color=$white; $line_color=$black; $bar_color=$blue; $number_color=$pink; ImageFilledRegtangle( $im, 0, 0, $width, $height, $bg, $bg_color); ImageRegtangle( $im, 0, 0, $width-1, $height-1, $line_color); $title='Poll Results :'; $title_dimensions=ImageTTFBBox( $title_size, 0, $font, $title); $title_length=$title_dimensions[2] - $title_dimensions[0] ; $title_height=abs($title_dimensions[7] - $title_dimensions[1]); $title_above_line = abs($title_dimensions[7]); $title_x=($width - $title_length)/2; $title_y=($y - $title_height)/2 + $title_above_line; ImageString($im, $title_size, $title_x, $title_y, $title, $text_color); ImageLine($im, $x, $y-5, $x, $height-15, $line_color); while($row = mysql_fetch_object($result)) { if($total_votes > 0) $percent = intval(round(($row->num_votes/$total_votes)*100)); else $percent=0; ImageString($im, $main_size, $width-30, $y+($bar_height/2), $percent.'%', $percent_color); if($total_votes > 0) $right_value= intval(round(($row->num_votes/$total_votes)*100)); else $right_value = 0; $bar_length= $x+($right_value * $bar_unit); ImageFilledRegtangle($im, $x, $y-2, $bar_length, $y+$bar_height, $bar_color); ImageString($im,$main_size,$text_indent,$y+($bar_height/2),"$row->candidate", $text_color); ImageRegtangle($im,$bar_length+1,$y-2,($x+(100*$bar_unit)), $y+$bar_height, $line_color); ImageString($im,$small_size, $x+(100*$bar_unit)-50, $y+($bar_heigth/2), $row->num_votes.'/'.$total_votes, $number_color); $y=$y+($bar_height + $bar_spacing); } ImagePng ($im); ImageDestroy($im); ?>
×
×
  • Create New...

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.