Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // credentials
- $db_user="imageuser";
- $db_pass="password";
- $db_host="localhost";
- $db_name="images";
- // check for both fields having content
- if ( isset ($_POST['title']) && ($_POST['url']) ){
- // assign title and url variables
- $title=$_POST['title'];
- $url=$_POST['url'];
- // first I define connection string
- $mysqli= mysqli_connect($db_host, $db_user, $db_pass, $db_name);
- $sql_insert = "INSERT INTO urls (id, title, url) VALUES (NULL, '$title', '$url')";
- // now make a connection
- if($mysqli->connect_errno){
- // if there is a connection error, print the error
- printf("Connect failed: %s\n", $mysqli->connect_error);
- } else {
- // insert image into database:
- if (mysqli_query($mysqli, $sql_insert)) {
- echo "image stored successfully";
- } else {
- printf("Error message: %s\n", mysqli_error($mysqli));
- }
- }
- }
- ?>
- <form action="" method="post">
- <label for="">title</label>
- <input type="text" name="title">
- <label for="">URL</label>
- <input type="text" name="url">
- <input type="submit" value="submit">
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement