Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[HELP] with my php! easy noob question!

Featured Replies

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

work through your " , ( ) etc

 

you have three "

or if you're really keen, write another php page to get the information back :)

  • Author

Same answer as zed gave.

Open up PHPMYADMIN and see if the stuff is in the database.

 

 

i dont think it does man :(

  • Author

or if you're really keen, write another php page to get the information back :)

 

thats next step need to master this first!!! :)

  • 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();
?>

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 by MikeChipshop

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 by web-itec

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.

  • 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 :/

  • 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());
?>


<?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());
?>

  • 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

  • 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 by kingy da killa

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?

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

  • Author

one sec ima get ride of this connection file n start again

Edited by kingy da killa

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 by MikeChipshop

  • Author

cheers its working now mike!

 

bloody hell that was long, what was wrong :/

Edited by kingy da killa

  • Author

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 by kingy da killa

  • 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 by kingy da killa

  • 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

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 B) 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)

  • 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 B) 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 by kingy da killa

  • 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 by kingy da killa

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.