Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

2 Stron V  < 1 2  
Reply to this topicStart new topic
> [php+mysql] Ciężkie początki
mike
post 7.05.2006, 10:27:21
Post #21





Grupa: Przyjaciele php.pl
Postów: 7 494
Pomógł: 302
Dołączył: 31.03.2004

Ostrzeżenie: (0%)
-----


Nie wiem czy dostrzegasz ale mój poprzedni post miał dwa punkty.
Sprawdź po wykananiu zapytania czy faktycznie coś dodano do bazy, a nie piszesz komunikat że dodano bezz pstrawdzania tego.

Tylko nie pisz kolejnego posta jak to zrobić bo dałem Ci podpowiedź i najpierw sprawdź.


A tak poza tym, to już dawno przestało to mieć związek z instalacją rozszerzeń do MySQLa.
Go to the top of the page
+Quote Post
henio
post 7.05.2006, 10:36:11
Post #22





Grupa: Zarejestrowani
Postów: 237
Pomógł: 1
Dołączył: 15.10.2004
Skąd: Lublin

Ostrzeżenie: (0%)
-----


dodaj_banner1.php

  1. <html>
  2. <head>
  3.   <title>Banner dodany</title>
  4. </head>
  5. <body>
  6. <h1>Banner dodany</h1>
  7. <?php
  8.   // utworzenie krótkich nazw zmiennych
  9.   $link=$_POST['link'];
  10.   $alt=$_POST['alt'];
  11.   $url=$_POST['url'];
  12.  
  13.   if (!$link || !$alt || !$url)
  14.   {
  15.      echo 'Nie podano wszystkich potrzebnych danych.<br />'
  16.           .'Wróć do poprzedniej strony i spróbuj ponownie.';
  17.      exit;
  18.   }
  19.  
  20.   {  
  21.     $banner = addslashes($link);
  22.     $alt = addslashes($alt);
  23.     $url = addslashes($url);
  24.   }
  25.    $db = mysqli_connect('localhost', 'root', 'heniek', 'admin');
  26.   
  27.  if (mysqli_connect_errno())
  28.   {
  29.      echo 'Błąd: : Połączenie z bazą danych nie powiodło się. Spróbuj jeszcze raz później.';
  30.      exit;
  31.   }
  32.  else
  33. {
  34. $wynik = $db->query("insert into bannery (link, alt, url) 
  35. values ('".$link."', '".$alt."', '".$url."')");
  36. echo 'Dane dodane';
  37. printf ("Nowy rekord ma id %d.\n", $wynik->insert_id);
  38. }
  39. ?>
  40. </body>
  41. </html>


I wyświetla mi się:

Kod
Dane dodane
Notice: Trying to get property of non-object in C:\Program Files\Apache Group\Apache2\htdocs\dodaj_banner1.php on line 38
Nowy rekord ma id 0.


Ten post edytował henio 7.05.2006, 10:47:57
Go to the top of the page
+Quote Post
mike
post 7.05.2006, 10:49:11
Post #23





Grupa: Przyjaciele php.pl
Postów: 7 494
Pomógł: 302
Dołączył: 31.03.2004

Ostrzeżenie: (0%)
-----


insert_id jest polem klasy mysqli a nie polem w obiekcie zbioru wyników.
Zreztą w manualu masz przykłady, więc skąd ten błąd?
Go to the top of the page
+Quote Post
henio
post 7.05.2006, 10:57:34
Post #24





Grupa: Zarejestrowani
Postów: 237
Pomógł: 1
Dołączył: 15.10.2004
Skąd: Lublin

Ostrzeżenie: (0%)
-----


Cytat(mike_mech @ 2006-05-07 09:49:11)
insert_id jest polem klasy mysqli a nie polem w obiekcie zbioru wyników.
Zreztą w manualu masz przykłady, więc skąd ten błąd?

Tez nie wiem: Jak troche zmieniłem na wzór manuala yo wyświeta ze nie zna funkcji query
Go to the top of the page
+Quote Post
mike
post 7.05.2006, 11:07:57
Post #25





Grupa: Przyjaciele php.pl
Postów: 7 494
Pomógł: 302
Dołączył: 31.03.2004

Ostrzeżenie: (0%)
-----


Ty masz poważne problemy ze zrozumieniem tego co czytasz.
To że nie wiem skąd błąd, miałem na myśli że nie wiem dlaczego zrobiłeś błąd używając czegoś co w manualu ma przykłady.

nie tak:
  1. <?php
  2.  
  3. $wynik->insert_id
  4.  
  5. ?>


tylko

  1. <?php
  2.  
  3. $db->insert_id
  4.  
  5. ?>
Go to the top of the page
+Quote Post
henio
post 7.05.2006, 11:20:46
Post #26





Grupa: Zarejestrowani
Postów: 237
Pomógł: 1
Dołączył: 15.10.2004
Skąd: Lublin

Ostrzeżenie: (0%)
-----


Teraz jest ok! Tylko, że wyświetla mi się:

Dane dodane. Nowy rekord ma id 0.
Go to the top of the page
+Quote Post
mike
post 7.05.2006, 11:36:42
Post #27





Grupa: Przyjaciele php.pl
Postów: 7 494
Pomógł: 302
Dołączył: 31.03.2004

Ostrzeżenie: (0%)
-----


To może tuż przed wykonaniem zapytania wyświetl sobie jak ono wygląda.

  1. <?php
  2.  
  3. echo $strQuery = "insert into bannery (link, alt, url) values ('".$link."', '".$alt."', '".$url."')";
  4. $wynik = $db->query( $strQuery );
  5.  
  6. ?>

A potemm sprawdź to zapytanie z linni komend


P.S.
Dane idące do bazy nie powinno filtrować się addslashes() tylko czymś do czego zsotało to stworzone, czyli: mysqli_escape_string()
Go to the top of the page
+Quote Post
henio
post 7.05.2006, 11:44:45
Post #28





Grupa: Zarejestrowani
Postów: 237
Pomógł: 1
Dołączył: 15.10.2004
Skąd: Lublin

Ostrzeżenie: (0%)
-----


Wyświetla się

Kod
insert into bannery (link, alt, url) values ('http://www.realmadryt.com.pl/baner/real2but.gif', 'Strona o Realu Madryt', 'http://www.realmadryt.com.pl')


Jak dodaej normalny tekst przez php to jest ok, a jak tekst z takim znakim jak: / to nie jest ok
Próbuje użyć funkcji:

  1. <?php
  2. echo $strQuery = "insert into bannery (link, alt, url) values ('".$link."', '".$alt."', '".$url."')<br />";
  3.  
  4. $wynik = $db->query( $strQuery );
  5.  
  6. $wynik = $db->real_escape_string($link);
  7. $wynik = $db->real_escape_string($url);
  8.  
  9.  $wynik = $db->query("insert into bannery (link, alt, url) 
  10.  values ('".$link."', '".$alt."', '".$url."')");
  11.  
  12. echo "Dane dodane.\n";
  13.  
  14. printf ("Nowy rekord ma id %d.\n", $db->insert_id);
  15. ?>



Ale nadal dane się nie dodają

Ten post edytował henio 7.05.2006, 12:02:56
Go to the top of the page
+Quote Post
dzesi
post 8.10.2006, 13:07:18
Post #29





Grupa: Zarejestrowani
Postów: 235
Pomógł: 0
Dołączył: 3.05.2006

Ostrzeżenie: (0%)
-----


Mam problem :] zainstalowałem apache php + mysql php działa ale mysql nie phpinfo go nie wykrywa tzn mysql5 i php 5.2:]bibioteke libmysql przeniosłem do system32 i do apache /bin w php.ini odznaczyłem
extension=php_mssql.dll
extension=php_msql.dll
extension=php_mysql.dll
extension=php_dba.dll
extension=php_dbase.dll
i mysql nie jest połaczone z php moge wiedziec co zle robie:>?

moj php.ini



; Directory in which the loadable extensions (modules) reside.
extension_dir = "c:/php/ext"

; Whether or not to enable the dl() function. The dl() function does NOT work
; properly in multithreaded servers, such as IIS or Zeus, and is automatically
; disabled on them.
enable_dl = On

; cgi.force_redirect is necessary to provide security running php as a CGI under
; most web servers. Left undefined, php turns this on by default. You can
; turn it off here AT YOUR OWN RISK
; **You CAN safely turn this off for IIS, in fact, you MUST.**
; cgi.force_redirect = 1

; if cgi.nph is enabled it will force cgi to always sent Status: 200 with
; every request.
; cgi.nph = 1

; if cgi.force_redirect is turned on, and you are not running under Apache or Netscape
; (iPlanet) web servers, you MAY need to set an environment variable name that php
; will look for to know it is OK to continue execution. Setting this variable MAY
; cause security issues, KNOW WHAT YOU ARE DOING FIRST.
; cgi.redirect_status_env = ;

; FastCGI under IIS (on WINNT based OS) supports the ability to impersonate
; security tokens of the calling client. This allows IIS to define the
; security context that the request runs under. mod_fastcgi under Apache
; does not currently support this feature (03/17/2002)
; Set to 1 if running under IIS. Default is zero.
; fastcgi.impersonate = 1;

; Disable logging through FastCGI connection
; fastcgi.log = 0

; cgi.rfc2616_headers configuration option tells php what type of headers to
; use when sending HTTP response code. If it's set 0 php sends Status: header that
; is supported by Apache. When this option is set to 1 php will send
; RFC2616 compliant header.
; Default is zero.
;cgi.rfc2616_headers = 0


;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
;upload_tmp_dir =c:/uploud

; Maximum allowed size for uploaded files.
upload_max_filesize = 10M


;;;;;;;;;;;;;;;;;;
; Fopen wrappers ;
;;;;;;;;;;;;;;;;;;

; Whether to allow the treatment of URLs (like http:// or ftp://) as files.
allow_url_fopen = On

; Whether to allow include/require to open URLs (like http:// or ftp://) as files.
allow_url_include = Off

; Define the anonymous ftp password (your email address)
;from="john@doe.com"

; Define the User-Agent string
; user_agent="php"

; Default timeout for socket based streams (seconds)
default_socket_timeout = 60

; If your scripts have to deal with files from Macintosh systems,
; or you are running on a Mac and need to deal with files from
; unix or win32 systems, setting this flag will cause php to
; automatically detect the EOL character in those files so that
; fgets() and file() will work regardless of the source of the file.
; auto_detect_line_endings = Off


;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
;
; If you wish to have an extension loaded automatically, use the following
; syntax:
;
; extension=modulename.extension
;
; For example, on Windows:
;
; extension=msql.dll
;
; ... or under UNIX:
;
; extension=msql.so
;
; Note that it should be the name of the module only; no directory information
; needs to go here. Specify the location of the extension with the
; extension_dir directive above.


; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
; Note that many DLL files are located in the extensions/ (php 4) ext/ (php 5)
; extension folders as well as the separate PECL DLL download (php 5).
; Be sure to appropriately set the extension_dir directive.

;extension=php_mbstring.dll
;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_dba.dll
;extension=php_dbase.dll
;extension=php_exif.dll
;extension=php_fdf.dll
;extension=php_filepro.dll
;extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_ifx.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
;extension=php_mcrypt.dll
;extension=php_mhash.dll
;extension=php_mime_magic.dll
;extension=php_ming.dll
extension=php_mssql.dll
extension=php_msql.dll
extension=php_mysql.dll
;extension=php_oci8.dll
;extension=php_openssl.dll
;extension=php_oracle.dll
;extension=php_pgsql.dll
;extension=php_shmop.dll
;extension=php_snmp.dll
;extension=php_sockets.dll
extension=php_sqlite.dll
;extension=php_sybase_ct.dll
;extension=php_tidy.dll
;extension=php_xmlrpc.dll
;extension=php_xsl.dll

wycinek php ini ps: czy plik php INI-DIST ma byc taki czy mam zapisac na php.ini bo ja zapisuje na php.ini błągam was pomózcie:]
;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;

[Date]
; Defines the default timezone used by the date functions
;date.timezone =

[Syslog]
; Whether or not to define the various syslog variables (e.g. $LOG_PID,
; $LOG_CRON, etc.). Turning it off is a good idea performance-wise. In
; runtime, you can define these variables by calling define_syslog_variables().
define_syslog_variables = Off

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
;sendmail_from = me@example.com

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =

[SQL]
sql.safe_mode = Off

[ODBC]
;odbc.default_db = Not yet implemented
;odbc.default_user = Not yet implemented
;odbc.default_pw = Not yet implemented

; Allow or prevent persistent links.
odbc.allow_persistent = On

; Check that a connection is still valid before reuse.
odbc.check_persistent = On

; Maximum number of persistent links. -1 means no limit.
odbc.max_persistent = -1

; Maximum number of links (persistent + non-persistent). -1 means no limit.
odbc.max_links = -1

; Handling of LONG fields. Returns number of bytes to variables. 0 means
; passthru.
odbc.defaultlrl = 4096

; Handling of binary data. 0 means passthru, 1 return as is, 2 convert to char.
; See the documentation on odbc_binmode and odbc_longreadlen for an explanation
; of uodbc.defaultlrl and uodbc.defaultbinmode
odbc.defaultbinmode = 1

[MySQL]
; Allow or prevent persistent links.
mysql.allow_persistent = On

; Maximum number of persistent links. -1 means no limit.
mysql.max_persistent = -1

; Maximum number of links (persistent + non-persistent). -1 means no limit.
mysql.max_links = -1

; Default port number for mysql_connect(). If unset, mysql_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order). Win32 will only look
; at MYSQL_PORT.
mysql.default_port =

; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
mysql.default_socket =

; Default host for mysql_connect() (doesn't apply in safe mode).
mysql.default_host =

; Default user for mysql_connect() (doesn't apply in safe mode).
mysql.default_user =root

; Default password for mysql_connect() (doesn't apply in safe mode).
; Note that this is generally a *bad* idea to store passwords in this file.
; *Any* user with php access can run 'echo get_cfg_var("mysql.default_password")
; and reveal this password! And of course, any users with read access to this
; file will be able to reveal the password as well.
mysql.default_password =haker1

; Maximum time (in seconds) for connect timeout. -1 means no limit
mysql.connect_timeout = 60

; Trace mode. When trace_mode is active (=On), warnings for table/index scans and
; SQL-Errors will be displayed.
mysql.trace_mode = Off

[MySQLi]

; Maximum number of links. -1 means no limit.
mysqli.max_links = -1

; Default port number for mysqli_connect(). If unset, mysqli_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order). Win32 will only look
; at MYSQL_PORT.
mysqli.default_port = 3306

; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
mysqli.default_socket =

; Default host for mysql_connect() (doesn't apply in safe mode).
mysqli.default_host =

; Default user for mysql_connect() (doesn't apply in safe mode).
mysqli.default_user =

; Default password for mysqli_connect() (doesn't apply in safe mode).
; Note that this is generally a *bad* idea to store passwords in this file.
; *Any* user with php access can run 'echo get_cfg_var("mysqli.default_pw")
; and reveal this password! And of course, any users with read access to this
; file will be able to reveal the password as well.
mysqli.default_pw =

; Allow or prevent reconnect
mysqli.reconnect = Off

[mSQL]
; Allow or prevent persistent links.
msql.allow_persistent = On

; Maximum number of persistent links. -1 means no limit.
msql.max_persistent = -1

; Maximum number of links (persistent+non persistent). -1 means no limit.
msql.max_links = -1
Go to the top of the page
+Quote Post

2 Stron V  < 1 2
Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 22.06.2025 - 23:00