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

Link to comment
Share on other sites

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>";

Link to comment
Share on other sites

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>";
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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