Jump to content

papaJ

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

papaJ's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. *MASSIVE FOREHEAD SLAP* I missed out the method attribute in the form tag. Why is it always the simplest of things that cause the biggest headaches? Thanks for all your help guys, sorry for (sort of) wasting your time.
  2. Just tried it, an it returned 'Error: the query was empty', so I guess the data isn't being picked up from the form. I think I read somewhere that $_POST might not be supported by default, would this have something to do with it?
  3. Thanks for your help guys, I think we're one step closer. I stuck an echo $sql; in like you said and it returned: INSERT INTO articles (id, artist, title, label, short_text, long_text, thumbnail, image, tracklisting, vendor_1, vendor_1_url, vendor_2, vendor_2_url, vendor_3, vendor_3_url ) VALUES ('','','','','','','','','','','','','','','') So it looks like the values from the form aren't being picked up. Do I have to assign them to variables before I use them in the SQL Query? LIke this: $artist = $_POST[artist]
  4. Tha't just the thing - I don't get any error messages. The script says: '1 record added' and the row appears in the table. The problem is that all of the fields are empty, which makes me suspect this might have something to do with the way I've set up my database. I can provide more data on the dB if needed.
  5. Hello there, I'm pretty new to PHP but an old hand at front-end stuff. I'm trying to insert some data into a table but I seem to be having a problem. Here's the code I'm using: $dbHost = 'localhost'; $dbUser = 'xxxxx'; $dbPassword = 'xxxxxx'; $dbName = 'xxxxx'; $dbConnect = mysql_connect($dbHost, $dbUser, $dbPassword) or die ('Error connecting to mysql'); $dbSelect = mysql_select_db($dbName); $sql="INSERT INTO articles (id, date, artist, title, label, short_text, long_text, thumbnail, image, tracklisting, vendor_1, vendor_1_url, vendor_2, vendor_2_url, vendor_3, vendor_3_url ) VALUES ('$_POST[id]','$_POST[date]','$_POST[artist]','$_POST[title]','$_POST[label]','$_POST[intro_text]','$_POST[long_text]','$_POST[thumb]','$_POST[image]','$_POST[tracklisting]', '$_POST[vendor1]','$_POST[vendor1Url]','$_POST[vendor2]','$_POST[vendor2Url]','$_POST[vendor3]','$_POST[vendor3Url]')"; if (!mysql_query($sql,$dbConnect)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($dbConnect); And here's the form I'm using: <form id="form1" action="includes/postDb.php"> <table border="0" cellspacing="5" cellpadding="5"> <tr> <td> <label for="id">ID</label></td> <td><input type="text" name="id" id="id" /></td> </tr> <tr> <td width="100"><label for="artist">Artist</label></td> <td width="300"><input type="text" name="artist" id="artist" /></td> </tr> <tr> <td> <label for="title">Title</label></td> <td><input type="text" name="title" id="title" /></td> </tr> <tr> <td> <label for="label">Label</label></td> <td><input type="text" name="label" id="label" /></td> </tr> <tr> <td valign="top"><label for="intro_text">Intro Text</label></td> <td><textarea name="intro_text" id="intro_text" cols="45" rows="5"></textarea></td> </tr> <tr> <td valign="top"><label for="long_text">Long Text</label></td> <td><textarea name="long_text" id="long_text" cols="45" rows="5"></textarea></td> </tr> <tr> <td><label for="thumb">Thumbnail URL</label></td> <td><input type="text" name="thumb" id="thumb" /></td> </tr> <tr> <td><label for="image">Image URL</label></td> <td><input type="text" name="image" id="image" /></td> </tr> <tr> <td><label for="tracklisting">Tracklist XML</label></td> <td><input type="text" name="tracklisting" id="tracklist" /></td> </tr> <tr> <td><label for="vendor1">Vendor 1</label></td> <td><input type="text" name="vendor1" id="vendor1" /></td> </tr> <tr> <td><label for="vendor1Url">Vendor 1 URL</label></td> <td><input type="text" name="vendor1Url" id="vendor1Url" /></td> </tr> <tr> <td><label for="vendor2">Vendor 2</label></td> <td><input type="text" name="vendor2" id="vendor2" /></td> </tr> <tr> <td><label for="vendor2Url">Vendor 2 URL</label></td> <td><input type="text" name="vendor2Url" id="vendor2Url" /></td> </tr> <tr> <td><label for="vendor3">Vendor 3</label></td> <td><input type="text" name="vendor3" id="vendor3" /></td> </tr> <tr> <td><label for="vendor3Url">Vendor 2 URL</label></td> <td><input type="text" name="vendor3Url" id="vendor3Url" /></td> </tr> </table> <input type="submit" class="submit" id="submit" value="Submit" /> </form> When I submit the form I don't get any errors, and the row gets added to the database but all the fields are blank (apart from id which is my table index). Here's a screenshot of my table from phpMyAdmin: If anyone could shed any light I'll be their best friend for ever and ever.
×
×
  • 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.