+ 2

How to use SQL database on my page?

Hello. I am sorry, because this will be probably duplicate question, but I couldn't find answer via search box. Anyway, I need to know, how can I use SQL database to store some data. I need it for quite complex project, so I won't describe what is it for in details. Let's just say I need a program, that saves text submitted via HTML form into database table. I went through HTML, CSS, JS, PHP and SQL courses, but I couldn't find how to acceess SQL. Can somebody make a code that would do that? If it's not posible to make in Sololearn because of blocking file-creation, send the code as raw text here please. And if it's to complex to describe just in a comment, send a link to a webpage that describes it. Thanks.

1st Jun 2018, 1:34 PM
Jan Štěch
Jan Štěch - avatar
6 odpowiedzi
+ 8
first you need to create database . download xammpp➡run your local apache server ➡ open phpmyadmin➡ create new database, run 👇on server (index.php) <?php $servername = "localhost"; $database = "testdb"; $username = "root"; $password = ""; $name="test"; $pass="testing"; // Create connection $conn = mysqli_connect($servername, $username, $password, $database); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } $sql = "INSERT INTO test_db (username,password) VALUES ('$name','$pass')"; if (mysqli_query($conn, $sql)) { echo "<br><fieldset>New record created successfully,/fieldset>"; } else { echo "Error: " . $sql . "<br>" . mysqli_error($conn); mysqli_close($conn); } ?> you cannot get enough answer on sololearn coz it's a complex method so visit different sites
1st Jun 2018, 1:45 PM
Sudarshan Rai
Sudarshan Rai - avatar
+ 1
Hello there It means if sql runs properly then this condition will be true Suppose you have mentioned some column to be not null and it will go to else part then throwing error. To check just change the table or column name it will go to else part.
23rd Jun 2018, 2:12 PM
ᴋᵘⁿᵃˡ
ᴋᵘⁿᵃˡ - avatar
+ 1
W3schools and tutorial are the website to Learn the code and modify you can do it on your local for practical examples.
23rd Jun 2018, 2:57 PM
ᴋᵘⁿᵃˡ
ᴋᵘⁿᵃˡ - avatar
0
Thank you very much. I will write here if I need help.
1st Jun 2018, 2:36 PM
Jan Štěch
Jan Štěch - avatar
0
Hello again. After several weeks of studying php I finally understand this a bit. Can you just explain me what does line "if (mysqli_query($conn, $sql))..." exactly do?
23rd Jun 2018, 10:30 AM
Jan Štěch
Jan Štěch - avatar
0
Ok, thanks for explanation. BTW do you know any good webpage/video/pdf document where I can learn to modify databases with php?
23rd Jun 2018, 2:55 PM
Jan Štěch
Jan Štěch - avatar