Jump to content

Sanjib Sinha

Members
  • Posts

    97
  • Joined

  • Last visited

Everything posted by Sanjib Sinha

  1. Hi Scott Your belief is true. I removed ' and replaced with ` and it solved. Thank you. I have learnt a new thing.
  2. Here is my code: <?php $c = mysql_connect('localhost','root',""); $c = mysql_select_db('user', $c); for($i=1; $i<=5; $i++){ $sql = "INSERT INTO 'users' ('username') VALUES('$i')"; $res = mysql_query($sql) or die(mysql_error()); echo "Row $i has been added <br>\n" ; } ?> Here is the output: 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 ''users' ('username') VALUES('1')' at line 1 Where is the problem?
  3. Thanks. I'll try this out. But The question is how could I define those variables? Should I do that or it's not needed?
  4. Neither way it's not working. Is it not possible to upload files to mysql database? There must be some ways. Anyway...I'll try and thanks for your concern.
  5. here is the code in line 6 $data = addslashes(fread($_FILES['form_data']['tmp_name'], "r")), filesize($form_data));
  6. When I put $_FILES['form_data']['tmp_name'] in place of (fopen($form_data, "r") it comes out: Parse error: parse error in C:\wamp\www\upload.php on line 6
  7. Would you kindly explain a little bit? The thing is, script does not work into the remote server also. I just tried and almost the same error message came out.
  8. I am trying to upload file from my computer to local server using php and failed. I am working with three pages : form.php, upload.php and download.php form.php is as follows: <?php // this starts the session session_start(); ?> <html> <head> <meta http-equiv="Expires" content="0"> <title>Form</title> </head> <body bgcolor="#ffffff" leftmargin="100" topmargin="100" marginwidth="100" marginheight="100"> <form method="post" action="upload.php" enctype="multipart/form-data"> Description:<br> <input type="text" name="form_description" size="40"> <input type="hidden" name="MAX_FILE_SIZE" value="1000"> <br>File to upload:<br> <input type="file" name="form_data" size="40"> <p><input type="submit" name="submit" value="submit"> </form> </body> </html> upload.php is as follows: <?php // this starts the session session_start(); ?> <html> <head> <meta http-equiv="Expires" content="0"> <title>form Process</title> </head> <body bgcolor="#ffffff" leftmargin="100" topmargin="100" marginwidth="100" marginheight="100"> <?php mysql_connect("localhost","root",""); mysql_select_db("userfile"); echo "Uploaded"; $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data))); $result=MYSQL_QUERY("INSERT INTO uploads (description, data,filename,filesize,filetype) ". "VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')"); $id= mysql_insert_id(); print "<p>File ID: <b>$id</b><br>"; print "<p>File Name: <b>$form_data_name</b><br>"; print "<p>File Size: <b>$form_data_size</b><br>"; print "<p>File Type: <b>$form_data_type</b><p>"; print "To upload another file <a href=form.php> Click Here</a>"; ?> </body> </html> download.php is as follows: <?php // this starts the session session_start(); ?> <html> <head> <meta http-equiv="Expires" content="0"> <title>Downloading file</title> </head> <body bgcolor="#ffffff" leftmargin="100" topmargin="100" marginwidth="100" marginheight="100"> <?php mysql_connect("localhost","root",""); mysql_select_db("userfile"); $query = "SELECT data,filetype FROM uploads where id=$id"; $result = MYSQL_QUERY($query); $data = MYSQL_RESULT($result,0,"data"); $type = MYSQL_RESULT($result,0,"filetype"); Header( "Content-type: $type"); print $data; ?> </body> </html> Now the problem is whenever I try to upload a file (whether it's an image or text) the output is like below : Uploaded Notice: Undefined variable: form_data in C:\wamp\www\php_project-1\upload\upload.php on line 16 Notice: Undefined variable: form_data in C:\wamp\www\php_project-1\upload\upload.php on line 16 Warning: fread(): supplied argument is not a valid stream resource in C:\wamp\www\php_project-1\upload\upload.php on line 16 Notice: Undefined variable: form_description in C:\wamp\www\php_project-1\upload\upload.php on line 17 Notice: Undefined variable: form_data_name in C:\wamp\www\php_project-1\upload\upload.php on line 17 Notice: Undefined variable: form_data_size in C:\wamp\www\php_project-1\upload\upload.php on line 17 Notice: Undefined variable: form_data_type in C:\wamp\www\php_project-1\upload\upload.php on line 17 File ID: 0 Notice: Undefined variable: form_data_name in C:\wamp\www\php_project-1\upload\upload.php on line 20 File Name: Notice: Undefined variable: form_data_size in C:\wamp\www\php_project-1\upload\upload.php on line 21 File Size: Notice: Undefined variable: form_data_type in C:\wamp\www\php_project-1\upload\upload.php on line 22 File Type: To upload another file Click Here // here is the end. Where is the problem in the script? Or is it because I am trying it locally? Have a nice year everybody.
  9. Besides these two I would like to add www.killerphp.com It's video tutorial on basic database management is very helpful.
  10. Sorry, I should not have thought that way. I just tried to manage as my knowledge is incomplete. Thanks. I'm learning.
  11. Yes that has solved the problem. I also tried in a different way, I just put $query = "SELECT * FROM record"; $result = mysql_query($query); $my_rows = " "; while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $my_rows = $my_rows . "Name : {$row['Name']} <br>"; } echo ($my_rows); It also reads only 'Name' from record. Thank you for answering.
  12. I have a database called 'people'. It has a table 'record'. It contains 4 fields : Name, Address, Phone-Number, Pan-Number. The page exp1.php has the following code <html> <head> <meta http-equiv="Expires" content="0"> <title>experiment</title> </head> <body bgcolor="#ffffff" leftmargin="100" topmargin="100" marginwidth="100" marginheight="100"> <?php $my_connection = mysql_connect('localhost', 'root', ''); if (!$my_connection) { die('Could not conncet: ' . mysql_error()); } echo 'Connected Successfully' . '<br><br>'; $my_database = mysql_select_db('people'); if (!$my_database) { die('Could not find database: ' . mysql_error()); } $query = "SELECT * FROM record"; $result = mysql_query($query); $my_rows = " "; while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $my_rows = $my_rows . "Name : {$row['Name']} <br>" . "Address : {$row['Address']} <br>" . "Phone_Number : {$row['Phone-Number']} <br>" . "Pan_Number : {$row['Pan-Number']} <br><br>"; } echo ($my_rows); mysql_close($my_connection); ?> </body> </html> It has an output as follows: Connected Successfully Name : Sanjib Sinha Address : 55 Phone_Number : 332225648 Pan_Number : 123456 Name : Kaberi sinha Address : 55 Phone_Number : 123456 Pan_Number : 123456 Name : Hagudu Mutudu Address : 55 Phone_Number : 123456 Pan_Number : 123456 Name : D N chowdhury Address : 55, Regent Park, Calcutta-711109 Phone_Number : 123456 Pan_Number : 123456 So it works fine. Now I want to retrieve only the 'Name' fields. What should be the code?
  13. So the future is OOP? I wouldn't say that exactly. I am sure PHP will let you work with it like it always has. OOP just makes certain tasks etc more efficient. It all depends on the script you are working on whether OOP would be the way to go or not. Thanks you. I got my answer. I have to learn the procedural basic soundly.
  14. What are the main differences between procedural and object oriented php? Can I relate these two?
  15. file_get_contents is working perfectly. Number has vanished. thanks.
  16. 's' is a function here. I wanted to put html file in variable!
  17. I have two php pages titled index.php and method1.php code of method1.php is <?php function s($file = "myfile.html") { return ("$file"); } ?> and the code of index.php is <?php include ("method1.php"); ?> <?php echo s(readfile("myfile.html")); ?> The problem is readfile as a function executes fine but at the end a number 347 has come up. Why this happens? Secondly, can any one tell me whether reading or writing file as function can be done this way, or it is wrong?
  18. I would like to know the role of server in executing php script. Does it do the same job that a compiler does in C language?
  19. Whenever I upload any php file in my site and try to see the page, this message comes : Error in my_thread_global_end(): 1 threads didn't exit Why this thing happens? Can anyone please help!
  20. Thanks everybody who had read my post and gave his/her precious time to help me out. Could anyone throw any light on what the live projects are and how I can participate on that or it will be too immatured to jump on live projects as a beginner?
  21. before starting learn php i did some conceptual homework in C . now how long it will take to learn php and start working professionally?
×
×
  • 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.