Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > MySQL > please help quick

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-01-03, 01:48
sebi_peter sebi_peter is offline
Registered User
 
Join Date: Mar 2003
Posts: 4
Post please help quick

hi there,
it would be greatful if u help,i have been having this problem,i am making a program in c and connecting the to database mysql
the program is like this

#include<stdlib.h>
#include<stdio.h>
#include "include/mysql.h"
#include<string.h>


MYSQL mysql;
MYSQL_RES *res;
MYSQL_ROW row;


int ipdel()
{
char sql[]="delete from IPMaster where IP_Address ='" ;
char ip1[25];
char *ip;

int temp;

mysql_init(&mysql);
if(mysql_real_connect(&mysql,"localhost","project" ,"hi",NULL,0,NULL,0)==NULL)
{
printf("Can't connect to MySQL\n Reason :%s ",
mysql_error(&mysql));
}

if(mysql_select_db(&mysql,"Status")!=0)
{
printf("Can't open the Database :%s",
mysql_error(&mysql));
}
printf("Enter the IP Address to be Deleted :");
scanf("%s",&ip1);
ip=ip1;
strcat(sql,ip);
strcat(sql,"'");
mysql_real_query(&mysql,sql,100);
mysql_close(&mysql);

return(0);
}

IP_Address is varchar(25) it is giving the segmentation fault after it deletes the entry from the table. and program terminates. it throws the SIGSEGV signal upon deletion could anybody help how to avoid this segmentation fault

when i am running gdb it gives the output

Program received signal SIGSEGV, Segmentation fault.
0x804a507 in main ()
(gdb) where
#0 0x804a507 in main ()
Cannot access memory at address 0x27312e31
(gdb) list
1 rtld.c: No such file or directory.
(gdb) c
Continuing.

Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.
Reply With Quote
  #2 (permalink)  
Old 04-07-03, 13:38
Santino Santino is offline
Registered User
 
Join Date: Apr 2003
Location: Rome, Italy
Posts: 2
Exclamation Change this!

char sql[]="delete from IPMaster where IP_Address ='" ;

to

char sql[255]="delete from IPMaster where IP_Address ='" ;


when you strcat sql you write bytes out of sql var space.

Santino
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On