Jump to content

Parse Errors


ChompGator

Recommended Posts

Parse error: parse error, unexpected T_STRING in d:\hosting\member\aiim\login\members\handle.php on line 13

 

I have revised my script to use mysql-update. I have a form that users can fill out to change their profile > upon submission the database table is supposed to update the changes...Im trying to ensure that it is only updating the 'company' based on the usersID number...that way if you had two john smiths in your database, that wont matter because the script is updating based on the users ID number.

 

here is handle.php (the script that should update the fields in the databasE)

 

<?php session_start();
$host=""; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name=""; // Database name

  
// Connect to DB
$db = mysql_connect ($host, $username, $password) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($db_name);


UPDATE aiimjoin SET company = WHERE uid = $_SESSION['uid']; //I know this is wrong, any advice?

// Step 3  
$result = mysql_query($sql) or die ( mysql_error() );  
?>

Link to comment
https://forums.phpfreaks.com/topic/118448-parse-errors/
Share on other sites

$sql = "UPDATE aiimjoin SET company ='What you want company set to' WHERE uid ='$_SESSION[uid]'";

 

You said in your code

 

$result = mysql_query($sql) or die ( mysql_error() );  

 

The

 

mysql_query($sql)

 

part is looking for a

 

$sql

 

variable with a mysql query. You have set the query, but it is not assigned to a variable.

Link to comment
https://forums.phpfreaks.com/topic/118448-parse-errors/#findComment-609699
Share on other sites

Yep, here it is:

 

this is handle.php  // The form.php  is below it

<?php session_start();
$host="***"; // Host name 
$username="***"; // Mysql username 
$password="***"; // Mysql password 
$db_name="***"; // Database name

  
// Connect to DB
$db = mysql_connect ($host, $username, $password) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($db_name);


$sql = "UPDATE aiimjoin SET company = 'company' WHERE uid = "$_SESSION[uid]"";

// Step 3  
$result = mysql_query($sql) or die ( mysql_error() );  
?>

 

 

form.php

<form method="post" action="handle.php"<br>
<td style="width: 175px;" valign="top"><font face="Verdana" size="2">
	<strong>Company Name:<br><input type=""text" AutoFill" tabindex="1" maxlength="25" size="20" name="company">
	</strong></font></td><br>
<td style="width: 175px;" valign="top"><font face="Verdana" size="2">
	<strong>Company Address:<Br><input type="text" tabindex="1" maxlength="25" size="20" name="address">
	</strong></font></td><br>
<td style="width: 175px;" valign="top"><font face="Verdana" size="2">
	<strong>Phone Number:<br><input type="text" tabindex="1" maxlength="25" size="20" name="phone">
	</strong></font></td><br>
<input type="submit" value="Change Profile" />
</form>
[code]

[/code]

Link to comment
https://forums.phpfreaks.com/topic/118448-parse-errors/#findComment-609714
Share on other sites

You cannot use double quotes within a double quoted string without escaping them.

 

This line could be...

 

$sql = "UPDATE aiimjoin SET company = 'company' WHERE uid = \"$_SESSION[uid]\"";

 

But thats still not the best solution because associative indexes also should be surrounded by quotes. Try...

 

$sql = "UPDATE aiimjoin SET company = 'company' WHERE uid = '{$_SESSION['uid']}'";

 

You also really ought be sanatising any variables use din queries with mysql_real_escape_string().

Link to comment
https://forums.phpfreaks.com/topic/118448-parse-errors/#findComment-609723
Share on other sites

AAlright, here is the new code:

Getting a "No Database Selected"

Other than that, Parse errors have disappeared, thank you for all the help and advice!

 

 

<?php session_start();

$host=""; // Host name

$username=""; // Mysql username

$password=""; // Mysql password

$db_name="login"; // Database name

 

 

// Connect to DB

mysql_connect ( $host, $username, $password, $db_name)or die("Could not connect: ".mysql_error());

 

 

$sql = "UPDATE aiimjoin SET company = 'company' WHERE uid = '{$_SESSION['uid']}'";

 

// Step 3 

$result = mysql_query($sql) or die ( mysql_error() ); 

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/118448-parse-errors/#findComment-609909
Share on other sites

One last problem...Ok, I have it so it updates now, however the form submits, I dont get any errors, handle.php is the php script that does the updating, however after filling out the form and clicking "update profile" - it doesn't update the fields in phpmyadmin

....Any advice?

 

handle.php // Supposed to update the fields in the db table.

<?php session_start();
$host=""; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name=""; // Database name


  
// Connect to DB
mysql_connect ( $host, $username, $password, $db_name)or die("Could not connect: ".mysql_error());

mysql_select_db($db_name);
$sql = "UPDATE aiimjoin SET company = 'company' WHERE uid = '{$_SESSION['uid']}'";

// Step 3  
$result = mysql_query($sql) or die ( mysql_error() );  
?>

Link to comment
https://forums.phpfreaks.com/topic/118448-parse-errors/#findComment-610081
Share on other sites

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.