aolsucks Posted April 14, 2010 Share Posted April 14, 2010 i have 3 php pages the same as this that will add things to the database just fine but for some reason my newest one wont work i just get a error. i've checked the page over and over but carnt find any typo's or mistakes. anyone got a idea why im just getting a error. <title>Artist Added!</title> <?php include ('auth.php'); ?> <?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="wearemetal"; // Database name $tbl_name="artists"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Get values from form $artistname=$_POST['artistname']; $urlfriend=$_POST['urlfriend']; $image=$_POST['image']; $location=$_POST['location']; $bio=$_POST['bio']; $genre=$_POST['genre']; $label=$_POST['label']; $websites=$_POST['websites']; $video1=$_POST['video1']; $video2=$_POST['video2']; $releases=$_POST['releases']; $audio=$_POST['audio']; $shows=$_POST['shows']; // Insert data into mysql $sql="INSERT INTO $tbl_name (artistname,urlfriend,image,location,bio,genre,label,websites,video1,video2,releases,audio,shows)VALUES('$artistname','$urlfriend','$image','$location','$bio','$genre','$label','$websites','$video1','$video2','$releases','$audio','$shows')"; $result=mysql_query($sql); // if successfully insert data into database, displays message "Successful". if($result){ echo "Your artist has been added"; echo "<BR>"; echo "<a href='../staff_index.php'>Back to main page</a>"; } else { echo "ERROR! something went wrong!"; }?> the form id's are all the same and checked for typo's and mistakes. Quote Link to comment https://forums.phpfreaks.com/topic/198565-add-to-database-php-not-working/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 14, 2010 Share Posted April 14, 2010 You do realize that the error you mentioned twice is relevant to where and what the problem is. We are not standing right next to you. When you don't bother to communicate information that you know about the problem, it reduces the chance of getting a solution. Quote Link to comment https://forums.phpfreaks.com/topic/198565-add-to-database-php-not-working/#findComment-1041975 Share on other sites More sharing options...
Jax2 Posted April 14, 2010 Share Posted April 14, 2010 I think he may have meant it shows his own personal error message, but I could be wrong. Here's a suggestion. If you're programming a site and it's not open to the public, always include this at the top just after any session stuff: ini_set('display_errors',1); error_reporting(E_ALL|E_STRICT); That will tell you almost 99% of the time what the error is ... try that and then let us know what it says if you still can't figure it out. Quote Link to comment https://forums.phpfreaks.com/topic/198565-add-to-database-php-not-working/#findComment-1041978 Share on other sites More sharing options...
Jax2 Posted April 14, 2010 Share Posted April 14, 2010 One other thing to consider... you're not cleaning your variables ... not only can this lead to sql injection / cross site scripting, it can also prevent you from adding any information that, for example, may contain ' or other chars as such into the database.... For example, if you or someone else types in "Jax2's Band", it will return an error unless you're using addslashes, or another method of cleaning... I can give you a really REALLY nice sanitizing function if you'd like, I've never had a single problem since I started using it. Quote Link to comment https://forums.phpfreaks.com/topic/198565-add-to-database-php-not-working/#findComment-1041979 Share on other sites More sharing options...
aolsucks Posted April 14, 2010 Author Share Posted April 14, 2010 yeah sorry i did mean it was showing my personal error message, i will give that a go and show a error message if i get one. the only error i got was this Warning: include(auth.php) [function.include]: failed to open stream: No such file or directory in C:\wamp\www\beta\_staff\includes\addartist_update.php on line 1 Warning: include() [function.include]: Failed opening 'auth.php' for inclusion (include_path='.;C:\php5\pear') in C:\wamp\www\beta\_staff\includes\addartist_update.php on line 1 ERROR something went wrong! but i also get this on the other pages. Quote Link to comment https://forums.phpfreaks.com/topic/198565-add-to-database-php-not-working/#findComment-1041989 Share on other sites More sharing options...
Jax2 Posted April 14, 2010 Share Posted April 14, 2010 May not help, but humor me Try changing the code to this: $sql="INSERT INTO ".$tbl_name." (arti ... If you're not getting any errors reported at all, it should be working fine from what I've read... if it was a problem with ' or other chars, it would return an sql error ... (I.e., you have an error near s band at line 32) or some such. Quote Link to comment https://forums.phpfreaks.com/topic/198565-add-to-database-php-not-working/#findComment-1041993 Share on other sites More sharing options...
aolsucks Posted April 14, 2010 Author Share Posted April 14, 2010 tried but still nothing here's my php form might help <form id="form1" name="form1" method="post" action="includes/addartist_update.php"> <table width="880" border="0" cellspacing="0" cellpadding="0"> <tr> <td> </td> <td class="style6"><strong></strong></td> <td> </td> </tr> <tr> <td width="13"> </td> <td width="181" class="style1"><div align="left" class="style7">Name</div></td> <td width="686"><label> <div align="left"> <input name="artistname" type="text" id="artistname" size="60"> </div> </label></td> </tr> <tr> <td> </td> <td class="style1"><div align="left" class="style7"><strong>Url Friendly Name</strong></div></td> <td><label> <div align="left"> <input name="urlfriend" type="text" id="urlfriend" size="60"> </div> </label></td> </tr> <tr> <td> </td> <td class="style1"><div align="left" class="style7"><strong>Image <a href="" target="_new" onclick="MM_openBrWindow('../uploadbandimage.php','','width=600,height=100')">(upload Image)</a></strong></div></td> <td><label> <div align="left"> <input name="image" type="text" id="image" size="60"> </div> </label></td> </tr> <tr> <td> </td> <td class="style1"><div align="left" class="style7"><strong>Location</strong></div></td> <td><label> <div align="left"> <input name="location" type="text" id="location" size="60"> </div> </label></td> </tr> <tr> <td> </td> <td class="style1"><div align="left" class="style7"><strong>Bio</strong></div></td> <td><label> <div align="left"> <label> <textarea name="bio" id="bio" cols="40" rows="5"></textarea> </label> </div> </label></td> </tr> <tr> <td> </td> <td class="style1"><div align="left" class="style7"><strong>Genre's</strong></div></td> <td><label> <div align="left"> <input name="genre" type="text" id="genre" size="60"> </div> </label></td> </tr> <tr> <td> </td> <td class="style1"><div align="left" class="style7"><strong>Label</strong></div></td> <td><label> <div align="left"> <input name="label" type="text" id="label" size="60"> </div> </label></td> </tr> <tr> <td> </td> <td class="style1"><div align="left" class="style7"><strong>Website</strong></div></td> <td><label> <div align="left"> <input name="websites" type="text" id="websites" size="60"> </div> </label></td> </tr> <tr> <td> </td> <td class="style1"><div align="left" class="style6">Video Link One</div></td> <td><label> <div align="left">Replace the CHANGE ME with the youtube video id <br /> (e.g http://www.youtube.com/watch?v=<strong>lIGokN09kwY</strong>) <br /> so you would change the values to <strong>lIGokN09kwY</strong> </div> <div align="left"> <label> <textarea name="video1" id="video1" cols="40" rows="5"></textarea> </label> </div> </label></td> </tr> <tr> <td> </td> <td class="style5"><div align="left" class="style6"><strong>Video Link Two</strong></div></td> <td><div align="left"> <textarea name="video2" id="video2" cols="40" rows="5"></textarea> </div></td> </tr> <tr> <td> </td> <td class="style1"><div align="left" class="style6">Releases</div></td> <td><div align="left"><em><strong>Please open the releases template <a href="admin-section/pages/pages/releases.txt" target="_new">here</a> and change the CHANGE ME values</strong></em></div></td> </tr> <tr> <td> </td> <td class="style1"><div align="left"><span class="style6"></span></div></td> <td><label> <label> <div align="left"> <textarea name="releases" id="releases" cols="60" rows="5"></textarea> </div> </label> </label></td> </tr> <tr> <td> </td> <td class="style7"> </td> <td><div align="left"><em><strong>Again change the change me values</strong></em></div></td> </tr> <tr> <td> </td> <td class="style1 style5"><div align="left" class="style6">Audio Player</div></td> <td><div align="left"> <label> <textarea name="audio" id="audio" cols="45" rows="5"></textarea> </label> </div></td> </tr> <tr> <td> </td> <td class="style6"><strong></strong></td> <td> </td> </tr> <tr> <td> </td> <td class="style1 style5"><div align="left" class="style6">Shows</div></td> <td><div align="left"><strong><a href="" target="_new">Watch Video</a> how to copy shows HTML from myspace </strong><br /> <label> <textarea name="shows" id="shows" cols="45" rows="5"></textarea> </label> </div></td> </tr> <tr> <td> </td> <td class="style7"> </td> <td><div align="left"> <input type="submit" name="submit" id="submit" value="Submit" /> <br> <br> </div></td> </tr> </table> <div align="left"></label> </div> </form> Quote Link to comment https://forums.phpfreaks.com/topic/198565-add-to-database-php-not-working/#findComment-1041995 Share on other sites More sharing options...
PFMaBiSmAd Posted April 14, 2010 Share Posted April 14, 2010 Your query is failing due to an error ($result is FALSE). echo mysql_error() to find out why. Quote Link to comment https://forums.phpfreaks.com/topic/198565-add-to-database-php-not-working/#findComment-1041996 Share on other sites More sharing options...
Jax2 Posted April 14, 2010 Share Posted April 14, 2010 Ahh, PFMaB to the rescue again ... lol, I wasn't paying attention, I thought you were echoing that already. That should show you where your error is, and it very well could be as I said, you're trying to upload something with an apostrophe or single quote in it ... So yeah, should be $result=mysql_query($sql) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/198565-add-to-database-php-not-working/#findComment-1041999 Share on other sites More sharing options...
aolsucks Posted April 14, 2010 Author Share Posted April 14, 2010 thanks guys your both awesome! i think i need a rest lol i was calling video1 and video2 when its just video and video1 in my mysql hahaha! sorry my bad i think i need some sleep thanks for the help guys Quote Link to comment https://forums.phpfreaks.com/topic/198565-add-to-database-php-not-working/#findComment-1042013 Share on other sites More sharing options...
Jax2 Posted April 14, 2010 Share Posted April 14, 2010 Hey man, I've been doing this (as an amateur) for over 10 years ... I can't begin to tell you how many times I've spent more than an hour trying my best to figure out why something isn't working when it's something stupid like a spelling mistake, or calling a variable I haven't properly defined ... You live and learn and hopefully don't repeat! Good job getting it figured out. I think I can speak for everyone when I say we're always glad to help! Quote Link to comment https://forums.phpfreaks.com/topic/198565-add-to-database-php-not-working/#findComment-1042015 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.