August 12, 201115 yr mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die("Unable to select database"); $query = "INSERT INTO member VALUES (",'$first','$last','$email','$mobile')"; mysql_query($query); mysql_close(); ?> its telling me there is a problem with '$query = "INSERT INTO member VALUES (",'$first','$last','$email','$mobile')";' line 'Parse error: syntax error, unexpected ',' in /home/bkwebdes/public_html/php/insert.php on line 14' please help
August 12, 201115 yr Author work through your " , ( ) etc you have three " ok ive made it not error, but im not sure if my stuffs got in my database http://bkwebdesignandhosting.co.uk/php/ Edited August 12, 201115 yr by kingy da killa
August 12, 201115 yr ok ive made it not error, but im not sure if my stuffs got in my database http://bkwebdesignandhosting.co.uk/php/ Same answer as zed gave. Open up PHPMYADMIN and see if the stuff is in the database.
August 12, 201115 yr Author Same answer as zed gave. Open up PHPMYADMIN and see if the stuff is in the database. i dont think it does man
August 12, 201115 yr Author or if you're really keen, write another php page to get the information back thats next step need to master this first!!!
August 12, 201115 yr Author <?php $username = "bkwebdes_devuser"; $database = "bkwebdes_dev"; $password = "cheeky!"; $first = $_POST['first']; $last = $_POST['last']; $email = $_POST['email']; $mobile = $_POST['mobile']; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die("Unable to select database"); $query = "INSERT INTO member VALUES (,'$first','$last','$email','$mobile')"; mysql_query($query); mysql_close(); ?>
August 12, 201115 yr You'll need to echo out any errors that may happen. Don't 'Die' as this'll stop the script and if there are numerous errors you wont see them all.
August 12, 201115 yr Author what's that @ doing?? http://www.w3schools.com/PHP/php_mysql_insert.asp http://www.freewebmasterhelp.com/tutorials/phpmysql/4 tells me 2. ive removed that mike and still dont tell me the error ahh
August 12, 201115 yr remove the '@' and... <?php $username = "bkwebdes_devuser"; $database = "bkwebdes_dev"; $password = "cheeky!"; $first = $_POST['first']; $last = $_POST['last']; $email = $_POST['email']; $mobile = $_POST['mobile']; mysql_connect(localhost,$username,$password); mysql_select_db($database) or die("Unable to select database"); $query = "INSERT INTO member VALUES (,'$first','$last','$email','$mobile')"; mysql_query($query); mysql_close()or die ('Error updating database because '.mysql_error()); ?> Edited August 12, 201115 yr by MikeChipshop
August 12, 201115 yr remove the '@' and... <?php $username = "bkwebdes_devuser"; $database = "bkwebdes_dev"; $password = "cheeky!"; $first = $_POST['first']; $last = $_POST['last']; $email = $_POST['email']; $mobile = $_POST['mobile']; mysql_connect(localhost,$username,$password); mysql_select_db($database) or die("Unable to select database"); $query = "INSERT INTO member VALUES (,'$first','$last','$email','$mobile')"; mysql_query($query); mysql_close()or die ('Error updating database because '.mysql_error()); ?> ^^^^ should work, although im sure it should tell you the error if you dont connect anyway, so when testing i dont think @ or die(mysql_error()) is necessary on just the database select Edited August 12, 201115 yr by web-itec
August 12, 201115 yr To make it easier to work with, slap your connection stuff into a seperate connection file and PHP include it such as.... connect.php <?php // DB Host $db_host = "localhost"; // Place the username for the MySQL database here $db_username = "bkwebdes_devuser"; // Place the password for the MySQL database here $db_pass = "cheeky!"; // Place the name for the MySQL database here $db_name = "bkwebdes_dev"; mysql_connect("$db_host","$db_username","$db_pass") or die(mysql_error()); mysql_select_db("$db_name") or die("no database by that name"); ?> and include that at the top of every page that needs a connection, using PHP includes. That's keep the files extra clean so you can work your way round them when error spotting.
August 12, 201115 yr Author Parse error: syntax error, unexpected ';' in /home/bkwebdes/public_html/php/insert.php on line 14 that the error i now get $query = ("INSERT INTO member VALUES (,'$first','$last','$email','$mobile')"; that is the line :/
August 12, 201115 yr change to... $query="INSERT INTO member VALUES (,'$first','$last','$email','$mobile')"; Edited August 12, 201115 yr by MikeChipshop
August 12, 201115 yr Author <!DOCTYPE HTML> <html> <head> </head> <body> <form action="insert.php" method="post"> First Name: <input type="text" name="first"></br> Last Name: <input type="text" name="last"></br> Email: <input type="text" name="email"></br> Phone: <input type="text" name="mobile"></br> <input type="Submit"> </form> </body> </html> <?php include 'connect.php'; $first = $_POST['first']; $last = $_POST['last']; $email = $_POST['email']; $mobile = $_POST['mobile']; mysql_connect(localhost,$username,$password); mysql_select_db($database) or die("Unable to select database"); $query = ("INSERT INTO member VALUES (,'$first','$last','$email','$mobile')"; mysql_query($query); mysql_close() or die ('Error updating database because '.mysql_error()); ?>
August 12, 201115 yr <?php include ('connect.php'); $first = $_POST['first']; $last = $_POST['last']; $email = $_POST['email']; $mobile = $_POST['mobile']; mysql_connect(localhost,$username,$password); mysql_select_db($database) or die("Unable to select database"); $query="INSERT INTO member VALUES ('$first','$last','$email','$mobile')"; mysql_query($query); mysql_close() or die ('Error updating database because '.mysql_error()); ?>
August 12, 201115 yr Author Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'bkwebdes'@'localhost' (using password: NO) in /home/bkwebdes/public_html/php/insert.php on line 9 Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'bkwebdes'@'localhost' (using password: NO) in /home/bkwebdes/public_html/php/insert.php on line 10 Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/bkwebdes/public_html/php/insert.php on line 10 Unable to select database
August 12, 201115 yr Although i usually do this... $query="INSERT INTO members(first, last, email, mobile)VALUES ('".$first."','".$last."','".$email."','".$mobile."')";
August 12, 201115 yr Author index.php <!DOCTYPE HTML> <html> <head> </head> <body> <form action="insert.php" method="post"> First Name: <input type="text" name="first"></br> Last Name: <input type="text" name="last"></br> Email: <input type="text" name="email"></br> Phone: <input type="text" name="mobile"></br> <input type="Submit"> </form> </body> </html> insert.php <?php include ('connect.php'); $first = $_POST['first']; $last = $_POST['last']; $email = $_POST['email']; $mobile = $_POST['mobile']; mysql_connect(localhost,$username,$password); mysql_select_db($database) or die("Unable to select database"); $query="INSERT INTO member VALUES ('$first','$last','$email','$mobile')"; mysql_query($query); mysql_close() or die ('Error updating database because '.mysql_error()); ?> connect.php <?php // DB Host $db_host = "localhost"; // Place the username for the MySQL database here $db_username = "bkwebdes_devuser"; // Place the password for the MySQL database here $db_pass = "cheeky!"; // Place the name for the MySQL database here $db_name = "bkwebdes_dev"; mysql_connect("$db_host","$db_username","$db_pass") or die(mysql_error()); mysql_select_db("$db_name") or die("no database by that name"); ?> Edited August 12, 201115 yr by kingy da killa
August 12, 201115 yr Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'bkwebdes'@'localhost' (using password: NO) in /home/bkwebdes/public_html/php/insert.php on line 9 Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'bkwebdes'@'localhost' (using password: NO) in /home/bkwebdes/public_html/php/insert.php on line 10 Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/bkwebdes/public_html/php/insert.php on line 10 Unable to select database Did you put the correct connection detail in the include file?
August 12, 201115 yr You could try removing the first comma and closing up the gap between values and the parenthesis - shouldn't have gaps between function names and values in MySQL: $query = "INSERT INTO member VALUES ('$first','$last','$email','$mobile')"; edit: INSERT INTO table_name (column_names) VALUES(values) - try putting in your database column names
August 12, 201115 yr Author one sec ima get ride of this connection file n start again Edited August 12, 201115 yr by kingy da killa
August 12, 201115 yr Try... <?php // HOST $db_host = "localhost"; // USERNAME $db_username = "bkwebdes_devuser"; // PASSWORD $db_pass = "cheeky!"; // DB NAME $db_name = "bkwebdes_dev"; mysql_connect("$db_host","$db_username","$db_pass") or die(mysql_error()); mysql_select_db("$db_name") or die("no database by that name"); ?> <?php $first = $_POST ['first']; $last = $_POST ['last']; $email = $_POST ['email']; $mobile = $_POST ['mobile']; $query="INSERT INTO member (first, last, email, mobile)VALUES ('".$first."','".$last."','".$email."','".$mobile."')"; mysql_query($query) or die ('Error updating database because '.mysql_error()); echo "Thank you the database has been updated." ; ?> Edited August 12, 201115 yr by MikeChipshop
August 12, 201115 yr Author cheers its working now mike! bloody hell that was long, what was wrong :/ Edited August 12, 201115 yr by kingy da killa
August 12, 201115 yr Have look at http://www.ardamis.com/2008/05/26/a-php-script-for-testing-a-mysql-database-connection/ and use it to test your connection.
August 12, 201115 yr Author Have look at http://www.ardamis.com/2008/05/26/a-php-script-for-testing-a-mysql-database-connection/ and use it to test your connection. my connection was fine untill i started playing around with it though.. what i changed to the way you said, i wasent uploadign the right file when i changed edited the connection file.. silly me cheers for sorting out the other bit thou! Edited August 12, 201115 yr by kingy da killa
August 12, 201115 yr Author You got it sorted then? http://bkwebdesignandhosting.co.uk/php/ yessir this is gunna go in my resource folder, for next projects, want to move on from wordpress(or combine) n do all the php my self (give it a few months) Edited August 12, 201115 yr by kingy da killa
August 12, 201115 yr Nice one man. Once you've got inserting, deleting and updating, you'll need to move on to encrypting and sanitising!
August 12, 201115 yr Author Phil McCrack bumlove@hotmail.com 0208 666 Encrypting and sanitising bruv lmfao right good idea! ahh cant wait to get them things done, and move onto what ever the **** sanitising is lol
August 12, 201115 yr ahh cant wait to get them things done, and move onto what ever the **** sanitising is lol It's the making sure what ever's entered in to your database via the form is a) what you want in there and Not gonna compromise your database or site. if you have a field for emails then you want what goes in there to be an email and not a piece of code to hack your site (SQL injection Attack)
August 12, 201115 yr Author It's the making sure what ever's entered in to your database via the form is a) what you want in there and Not gonna compromise your database or site. if you have a field for emails then you want what goes in there to be an email and not a piece of code to hack your site (SQL injection Attack) yeah wicked, nice 1 http://bkwebdesignandhosting.co.uk/php/output.php have a check !!! just need to make it display a bit nicer now, and in an order list.. hmmm Edited August 12, 201115 yr by kingy da killa
August 12, 201115 yr Author <?php include ('connect.php'); $query="SELECT * FROM member"; $result=mysql_query($query); $num=mysql_numrows($result); echo"<br/>DATABASE CUSTOMERS OUTPUT ADVANCED<br/><br/>"; <table border="0" cellspacing="2" cellpadding="2"> <tr> <th>Name</th> <th>Email</th> <th>Mobile</th> </tr> <? $i=0; while ($i <$num){ $first=mysql_result($result,$i,"first"); $last=mysql_result($result,$i,"last"); $email=mysql_result($result,$i,"email"); $mobile=mysql_result($result,$i,"mobile"); <tr> <td><? echo $first." ".$last; ?></td> <td><a href="mailto:<? echo $email; ?>"Email</a></td> <td><? echo $mobile; ?></td> </tr> $i++ } echo"</table>"; ?> http://bkwebdesignandhosting.co.uk/php/output.php this works. http://bkwebdesignandhosting.co.uk/php/output2.php but the code above is for this which is more complicated where am i going wrong! i no u cant have bogstandard html in my code, but not sure what to do (maybe put all the html in echo strings> Edited August 12, 201115 yr by kingy da killa
Create an account or sign in to comment