Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert into Table & extract last ID
    primarykey
    data
    text
    <p>Afternoon geniuses, Hoping you can help. This was inserting into the tables Twitch &amp; Birds before i added upload image to it, Now the only part that works is the image upload. this is very simple code but cant work out why it's not adding.</p> <p>Also how can i get the auto increment ID from The TWITCH table once it works. Thanks in advance. </p> <pre><code>&lt;?php session_start(); include ('dbconnect.php'); //Set Variables from Form $species =($_POST['Species']); $age =($_POST['Age']); $sex =($_POST['Sex']); $location =($_POST['Location']); $date_seen = date("Y-m-d"); $time_seen =($_POST['Time']); $twitch =($_POST['Comments']); //$twitch_id=(". mysql_insert_id()"); //Insert Into Birds table $query1 = "INSERT INTO Birds (Species, Age, Sex, Location, Date_Seen, Time_Seen, Comments) VALUES ( '$species', '$age', '$sex', '$location', '$date_seen', '$time_seen', '$twitch')"; result1 = mysqli_query($conn, $query1); //Insert into Twitch table query2 = "INSERT INTO Twitch (Twitch_ID, Twitch) VALUES( 'NULL', '$twitch')"; $result2 = mysqli_query($conn, $query2); // Validate and upload image file if ( !preg_match( '/gif|png|x-png|jpeg/', $_FILES['userFile']['type']) ) { die('&lt;p&gt;Only browser compatible images allowed&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;'); } else if ( strlen($_POST['altText']) &lt; 9 ) { die('&lt;p&gt;Please provide meaningful alternate text&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;'); } else if ( $_FILES['userFile']['size'] &gt; 1116384 ) { die('&lt;p&gt;Sorry file too large&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;'); // Connect to database } else if ( !($conn=mysqli_connect($host, $username, $password)) ) { die('&lt;p&gt;Error connecting to database&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;'); } else if ( !(mysqli_select_db($conn, $db_name)) ) { die('&lt;p&gt;Error selecting database&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;'); // Copy image file into a variable } else if ( !($handle = fopen ($_FILES['userFile']['tmp_name'], "r")) ) { die('&lt;p&gt;Error opening temp file&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;'); } else if ( !($image = fread ($handle, filesize($_FILES['userFile']['tmp_name']))) ) { die('&lt;p&gt;Error reading temp file&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;'); } else { fclose ($handle); // Commit image to the database $image = mysqli_real_escape_string($conn, $image); $alt = htmlentities($_POST['altText']); $query3 = 'INSERT INTO Image (Image_Name, Image_Type, Description, Image) VALUES ("' . $_FILES['userFile']['type'] . '","' . $_FILES['userFile']['name'] . '","' . $alt . '","' . $image . '")'; if ( !(mysqli_query($conn, $query3)) ) { die('&lt;p&gt;Error writing image to database&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;'); } else { header ("Location: TwitchWall.php"); } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload