Jump to content

[SOLVED] php and databases


pyke96

Recommended Posts

if ($connection)

$query = "INSERT INTO patients (patient_first_name, patient_last_name, patient_user_name, patient_pass_word, patient_address, patient_county, patient_country) VALUES ($_SESSION['firstname'], $_SESSION['lastname'], $_SESSION['username'], $_SESSION['password'], $_SESSION['address'], $_SESSION['county'], $_SESSION['country'])";

$result = mysql_query($query);

echo "New record added to the database";

else

echo "connection failed";

 

This is the snippit of code I was using to add a record to a mysql database. this is the error i got:

 

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\webs\test\add_pat.php on line 15

 

Could someone help with this??

Link to comment
https://forums.phpfreaks.com/topic/89713-solved-php-and-databases/
Share on other sites

<?php

$_SESSION['firstname'] = $_POST['firstname'];

$_SESSION['lastname'] = $_POST['lastname'];

$_SESSION['username'] = $_POST['user'];

$_SESSION['password'] = $_POST['pass'];

$_SESSION['address'] = $_POST['address'];

$_SESSION['county'] = $_POST['county'];

$_SESSION['country'] = $_POST['country'];

$connection = mysql_connect('157.190.116.250','sheehanl','R00010258') or die(mysql_error());

 

if ($connection)

$query = "INSERT INTO patients (patient_first_name, patient_last_name, patient_user_name, patient_pass_word, patient_address, patient_county, patient_country) VALUES ($_SESSION['firstname'], $_SESSION['lastname'], $_SESSION['username'], $_SESSION['password'], $_SESSION['address'], $_SESSION['county'], $_SESSION['country'])";

$result = mysql_query($query);

echo "New record added to the database";

else

echo "connection failed";

 

$db = mysql_select_db("sheehanldb") or die(mysql_errror());

echo "<p>Database selected</p>";

 

This is all of the code used. Thanks

Looks like you've come from a background of programming VB... where are your parenthesis?

 

<?php
$_SESSION['firstname'] = $_POST['firstname'];
$_SESSION['lastname'] = $_POST['lastname'];
$_SESSION['username'] = $_POST['user'];
$_SESSION['password'] = $_POST['pass'];
$_SESSION['address'] = $_POST['address'];
$_SESSION['county'] = $_POST['county'];
$_SESSION['country'] = $_POST['country'];
$connection = mysql_connect('157.190.116.250','sheehanl','R00010258') or die(mysql_error());

if ($connection) [color=red]{[/color]
       $query = "INSERT INTO patients (patient_first_name, patient_last_name, patient_user_name, patient_pass_word, patient_address, patient_county, patient_country) VALUES ($_SESSION['firstname'], $_SESSION['lastname'], $_SESSION['username'], $_SESSION['password'], $_SESSION['address'], $_SESSION['county'], $_SESSION['country'])";
      $result = mysql_query($query);
echo "New record added to the database";
[color=red]}[/color] else [color=yellow]{[/color]
      echo "connection failed";
[color=red]}[/color]

$db = mysql_select_db("sheehanldb") or die(mysql_errror());
echo "<p>Database selected</p>";

try

<?php
$_SESSION['firstname'] = $_POST['firstname'];
$_SESSION['lastname'] = $_POST['lastname'];
$_SESSION['username'] = $_POST['user'];
$_SESSION['password'] = $_POST['pass'];
$_SESSION['address'] = $_POST['address'];
$_SESSION['county'] = $_POST['county'];
$_SESSION['country'] = $_POST['country'];
$connection = mysql_connect('157.190.116.250','sheehanl','R00010258') or die(mysql_error());

if ($connection){
       $query = "INSERT INTO patients (patient_first_name, patient_last_name, patient_user_name, patient_pass_word, patient_address, patient_county, patient_country) VALUES ('".$_SESSION['firstname']."', '".$_SESSION['lastname']."', '".$_SESSION['username']."', '".$_SESSION['password']."', '".$_SESSION['address']."', '".$_SESSION['county']."', '".$_SESSION['country']."'";
      $result = mysql_query($query);
echo "New record added to the database";}
else
      echo "connection failed";

$db = mysql_select_db("sheehanldb") or die(mysql_errror());
echo "<p>Database selected</p>";
?>

try

<?php
$_SESSION['firstname'] = $_POST['firstname'];
$_SESSION['lastname'] = $_POST['lastname'];
$_SESSION['username'] = $_POST['user'];
$_SESSION['password'] = $_POST['pass'];
$_SESSION['address'] = $_POST['address'];
$_SESSION['county'] = $_POST['county'];
$_SESSION['country'] = $_POST['country'];
$connection = mysql_connect('157.190.116.250','sheehanl','R00010258') or die(mysql_error());

if ($connection){
       $query = "INSERT INTO patients (patient_first_name, patient_last_name, patient_user_name, patient_pass_word, patient_address, patient_county, patient_country) VALUES ('".$_SESSION['firstname']."', '".$_SESSION['lastname']."', '".$_SESSION['username']."', '".$_SESSION['password']."', '".$_SESSION['address']."', '".$_SESSION['county']."', '".$_SESSION['country']."'";
      $result = mysql_query($query);
echo "New record added to the database";}
else
      echo "connection failed";

$db = mysql_select_db("sheehanldb") or die(mysql_errror());
echo "<p>Database selected</p>";
?>

 

Thats after working for us except this is the page returned:

 

Notice: Undefined index: address in c:\webs\test\add_pat1.php on line 9

New record added to the database

 

Database selected

You forgot a ")" at the end of your values and you should put in some error checking until your code is at least debugged.

<?php
$_SESSION['firstname'] = $_POST['firstname'];
$_SESSION['lastname'] = $_POST['lastname'];
$_SESSION['username'] = $_POST['user'];
$_SESSION['password'] = $_POST['pass'];
$_SESSION['address'] = $_POST['address'];
$_SESSION['county'] = $_POST['county'];
$_SESSION['country'] = $_POST['country'];
$connection = mysql_connect('157.190.116.250','sheehanl','R00010258') or die(mysql_error());

if ($connection){
$query = "INSERT INTO patients (patient_first_name, patient_last_name, patient_user_name, patient_pass_word, patient_address, patient_county, patient_country) VALUES ('".$_SESSION['firstname']."', '".$_SESSION['lastname']."', '".$_SESSION['username']."', '".$_SESSION['password']."', '".$_SESSION['address']."', '".$_SESSION['county']."', '".$_SESSION['country']."')";
$result = mysql_query($query);
  if($result){
  echo "New record added to the database";
  } else {
  echo "Could not Insert record: Sql error ".mysql_error();
  }
} else {
echo "connection failed";
}
$db = mysql_select_db("sheehanldb") or die(mysql_errror());
echo "<p>Database selected</p>";
?>

 

Ray

Stephen,

 

I hardly feel using these types of methods is in keeping with the spirit of the project.  Please remember that part of this task is the signing of an anti-plagiarism document.

 

-Eamonn.

Wait, what the? Did you reply to the wrong topic or something. ??? Who are you talking to?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.