0

I 'm trying to store data from a php form to MySql database (phpMyAdmin) and i got the following error: unexpected 'pname' (T_STRING) in C:\XAMPP\htdocs\testsubmit.php on line 22

How can i solve this?

adminform.php

<form action="testsubmit.php" method="POST">
Program Name: <input type="text" name= "pname" size="40" maxlength="80">
<br/>
<br/>
Year: <input type="text" name="py" size="20">
<br/>
<br/>
Criteria: <input type="text"  name= "pcrit" size="40" maxlength="80">
<br/>
<br/>
Score: <input type="text" name="psco" size="20">
<br/>
<br/>
<input type="submit" name="formSubmit" value="Submit"/>
</form>

testsubmit.php

<?php

 define ('DB_NAME','mynewdb');
 define ('DB_USER','root');
 define ('DB_PASSWORD','');
 define ('DB_HOST','localhost');


 $link=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);

  if(!$link){
      die('Could not connect:'.mysql_error());
  }


 $db_selected=mysql_select_db(DB_NAME, $link);

 if(!$db_selected){
     die('Can\'t use' .DB_NAME.':".mysql_error());
 }

 $value=$_POST['pname'];
 $value2=$_POST[ 'py' ];
 $value3=$_POST['pcrit'];
 $value4=$_POST['psco'];


 $sql="INSERT INTO new(pname,py,pcrit,psco)              VALUES('$value','$value2','$value3','$value4')";

  if(!mysql_query($sql)){

       die('Error:'.mysql_error());
  }

  mysql_close();

?>

aurora
  • 161
  • 4
  • 15

1 Answers1

0

you must change

die('Can\'t use' .DB_NAME.':".mysql_error());  

to

  die('Can\'t use' . DB_NAME . ':' . mysql_error());

The problem is change of " by '

Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63