angel55 Posted May 27, 2009 Share Posted May 27, 2009 I keep getting this error.plz help Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\xampp\htdocs\Estate\update_agent.php on line 19 I have highlighted line 19 below <?php $db1 = new agent(); $db1->openDB(); $sql="select Agent_ID from agents "; $result=$db1->getResult($sql); if (!$_POST) { ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> Select Agent ID to update: <select name="pid"> <?php while($row = mysql_fetch_assoc($result)) echo "<option value='{$row['Agent_ID']}'>{ $row['Agent_ID']} </option>";?> </select> <input type="submit" value="Go" /> </form> <?php } // end if elseif (!$_POST['Agent_name'] && !$_POST['Address '] && !$_POST['Postcode'] ) { $Agent_ID = $_POST['Agent_ID']; $sql="SELECT Agent_name,Address,Postcode, from agents where Agent_ID ={$Agent_ID}"; $result=$db1->getResult($sql); $row = mysql_fetch_assoc($result); if($row) { $Agent_ID = $row['Agent_ID']; $Agent_name = $row['Agent_name']; $Address= $row['Address']; $Postcode = $row['Postcode']; } // end of inner if else die("SQL Error: " . mysql_error()); $sql2 = ""; $result2=$db1->getResult($sql2); if(!$result2) { die("SQL Error: " . mysql_error()); } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Agent_ID:<input type="text" name="pid" value="<?php echo $Agent_ID; ?>" /><br /> Agent Name:<input type="text" name="name" value="<?php echo $Agent_name; ?>" /><br /> Address:<input type="text" name="name" value="<?php echo $Address; ?>" /><br /> Postcode:<input type="text" name="name" value="<?php echo $Postcode; ?>" /><br /> <?php } // end of else if else //user has submitted form { $Agent_ID = $_POST['Agent_ID']; $Agent Name = $_POST['Agent Name']; $Address = $_POST['Address']; $Postcode= $_POST['Postcode']; $numofrows = $db1->update($Agent_ID,$Agent Name,$Address,$Postcode); echo "Success. Number of rows affected: <strong>{$numofrows}<strong>"; $db1->closeDB(); } ?> Link to comment https://forums.phpfreaks.com/topic/159884-update-record/ Share on other sites More sharing options...
cunoodle2 Posted May 27, 2009 Share Posted May 27, 2009 I'm guessing the issue is with the brackets "{ }" that you are using. Try this.. <?php while($row = mysql_fetch_assoc($result)) { echo "<option value='$row['Agent_ID']'> $row['Agent_ID'] </option>"; } ?> If that does work then try this... <?php while($row = mysql_fetch_assoc($result)) { echo "<option value='".$row['Agent_ID']."'> ".$row['Agent_ID']." </option>"; } ?> The first method is preferred and will run/render faster. Also please enclose all of your code with the "code" tags. Link to comment https://forums.phpfreaks.com/topic/159884-update-record/#findComment-843255 Share on other sites More sharing options...
angel55 Posted May 27, 2009 Author Share Posted May 27, 2009 that error is solved. ive got this error message now Parse error: parse error in C:\xampp\htdocs\Estate\update_agent.php on line 68 i ave highlighted below <?php $db1 = new agent(); $db1->openDB(); $sql="select Agent_ID from agents "; $result=$db1->getResult($sql); if (!$_POST) { ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> Select Agent ID to update: <select name="pid"> <?php while($row = mysql_fetch_assoc($result)) { echo "<option value='".$row['Agent_ID']."'> ".$row['Agent_ID']." </option>"; } ?> </select> <input type="submit" value="Go" /> </form> <?php } // end if elseif (!$_POST['Agent_name'] && !$_POST['Address '] && !$_POST['Postcode'] ) { $Agent_ID = $_POST['Agent_ID']; $sql="SELECT Agent_name,Address,Postcode, from agents where Agent_ID ={$Agent_ID}"; $result=$db1->getResult($sql); $row = mysql_fetch_assoc($result); if($row) { $Agent_ID = $row['Agent_ID']; $Agent_name = $row['Agent_name']; $Address= $row['Address']; $Postcode = $row['Postcode']; } // end of inner if else die("SQL Error: " . mysql_error()); $sql2 = ""; $result2=$db1->getResult($sql2); if(!$result2) { die("SQL Error: " . mysql_error()); } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Agent_ID:<input type="text" name="pid" value="<?php echo $Agent_ID; ?>" /><br /> Agent Name:<input type="text" name="name" value="<?php echo $Agent_name; ?>" /><br /> Address:<input type="text" name="name" value="<?php echo $Address; ?>" /><br /> Postcode:<input type="text" name="name" value="<?php echo $Postcode; ?>" /><br /> <?php } // end of else if else //user has submitted form { $Agent_ID = $_POST['Agent_ID']; $Agent Name = $_POST['Agent Name'];$Address = $_POST['Address']; $Postcode= $_POST['Postcode']; $numofrows = $db1->update($Agent_ID,$Agent Name,$Address,$Postcode); echo "Success. Number of rows affected: <strong>{$numofrows}<strong>"; $db1->closeDB(); } ?> Link to comment https://forums.phpfreaks.com/topic/159884-update-record/#findComment-843268 Share on other sites More sharing options...
cunoodle2 Posted May 27, 2009 Share Posted May 27, 2009 Your code was.. $Agent Name = $_POST['Agent Name']; change it to... $Agent_Name = $_POST['Agent Name']; OR.. $AgentName = $_POST['Agent Name']; Php variables can't have spaces and SERIOUSLY next time use the "code" brackets or I (and probably along with other people here) will simply ignore your post. Link to comment https://forums.phpfreaks.com/topic/159884-update-record/#findComment-843289 Share on other sites More sharing options...
angel55 Posted May 27, 2009 Author Share Posted May 27, 2009 thnx ive done tat now i got this error message. Iam really new to php.do you know what the following error message means? SQL Retrieve Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from agents where Agent_ID =' at line 1 my sql table for the agent is below: CREATE TABLE IF NOT EXISTS `agents` ( `Agent_ID` int(4) NOT NULL AUTO_INCREMENT, `Agent_Name` varchar(20) DEFAULT NULL, `Address` varchar(40) DEFAULT NULL, `Postcode` varchar(7) DEFAULT NULL, PRIMARY KEY (`Agent_ID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ; Link to comment https://forums.phpfreaks.com/topic/159884-update-record/#findComment-843296 Share on other sites More sharing options...
anupamsaha Posted May 27, 2009 Share Posted May 27, 2009 Your form element is named as "name" Agent Name:<input type="text" name="name" value="<?php echo $Agent_name; ?>" /> So, change as follows: $Agent_Name = $_POST['name']; And, PHP and any programming language or script does not allow SPACE in a variable name. Link to comment https://forums.phpfreaks.com/topic/159884-update-record/#findComment-843382 Share on other sites More sharing options...
angel55 Posted May 27, 2009 Author Share Posted May 27, 2009 is still not working. giving me the same error Link to comment https://forums.phpfreaks.com/topic/159884-update-record/#findComment-843403 Share on other sites More sharing options...
anupamsaha Posted May 27, 2009 Share Posted May 27, 2009 is still not working. giving me the same error Why there are 3 identical name attributes to 3 different form input elements? Agent Name:<input type="text" name="name" value="<?php echo $Agent_name; ?>" /><br /> Address:<input type="text" name="name" value="<?php echo $Address; ?>" /><br /> Postcode:<input type="text" name="name" value="<?php echo $Postcode; ?>" /><br /> Change them and change PHP variables accordingly. Link to comment https://forums.phpfreaks.com/topic/159884-update-record/#findComment-843413 Share on other sites More sharing options...
angel55 Posted May 27, 2009 Author Share Posted May 27, 2009 i have changed them but still no luck Link to comment https://forums.phpfreaks.com/topic/159884-update-record/#findComment-843418 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.