I’m building a system to manage musician profiles and need to store multiple web addresses for each person. The form has fields for social media profiles like Facebook, Twitter, Instagram etc. I’m having weird issues where some URL fields work fine but others cause server errors.
Here’s my form structure:
<form method="post" action="save_musician.php">
<input type="text" name="first_name" required>
<input type="text" name="last_name" required>
<input type="email" name="contact_email" required>
<input type="text" name="personal_site" size="60">
<input type="text" name="facebook_url" size="60">
<input type="text" name="twitter_handle" size="60">
<input type="text" name="instagram_profile" size="60">
<input type="text" name="spotify_link" size="60">
<input type="submit" value="Save Profile">
</form>
And the PHP handler:
<?php
$db = mysqli_connect("localhost", "username", "password", "database");
$first_name = mysqli_real_escape_string($db, $_POST['first_name']);
$last_name = mysqli_real_escape_string($db, $_POST['last_name']);
$contact_email = mysqli_real_escape_string($db, $_POST['contact_email']);
$personal_site = mysqli_real_escape_string($db, $_POST['personal_site']);
$facebook_url = mysqli_real_escape_string($db, $_POST['facebook_url']);
$twitter_handle = mysqli_real_escape_string($db, $_POST['twitter_handle']);
$instagram_profile = mysqli_real_escape_string($db, $_POST['instagram_profile']);
$spotify_link = mysqli_real_escape_string($db, $_POST['spotify_link']);
$query = "INSERT INTO musicians (";
$query .= "name_first, name_last, email_contact, ";
$query .= "url_website, url_facebook, url_twitter, ";
$query .= "url_instagram, url_spotify, created_date) ";
$query .= "VALUES ('$first_name', '$last_name', '$contact_email', ";
$query .= "'$personal_site', '$facebook_url', '$twitter_handle', ";
$query .= "'$instagram_profile', '$spotify_link', NOW())";
mysqli_query($db, $query);
?>
The strange thing is it works with one URL but fails with multiple ones. I get 403 forbidden errors when adding URLs to certain fields but not others. Server permissions look fine and error logs show nothing. Anyone know what might cause this?