AEdwards Posted April 23, 2012 Share Posted April 23, 2012 I am currently running a NAS (Synology DS211+) and have been asked to set up an intranet on it. I've never worked with such a horrible machine, Basically I can't get any PHP to work on it what so ever, Synology claims php is pre-installed but i'm beginning to have my doubts. My problem: I'm setting up an "Add new client" page, so we can use check box's to add clients to the database, How ever, using an insert.php (Form) and insert_ac.php (connecting and sending data to the database), the Insert_ac.php is just showing up as text. So the < ? Php > (etc) is all appearing on the page. Any suggestions would be greatly appreciated, please post if you need more information. Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 23, 2012 Share Posted April 23, 2012 So the < ? Php > (etc) is all appearing on the page. Are you using PHP short tags or full tags? You shouldn't be using short tags (unless the documentation for that device states you need to) Quote Link to comment Share on other sites More sharing options...
AEdwards Posted April 23, 2012 Author Share Posted April 23, 2012 Using full tags, <form name="form1" method="post" action="insert_ac.php"> <table width="300" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td> <table width="100%" border="0" cellspacing="1" cellpadding="3"> <tr> <td colspan="3"><strong>Insert Data Into mySQL Database </strong></td> </tr> <tr> <td width="71">Name</td> <td width="6">:</td> <td width="301"><input name="name" type="text" id="name"></td> </tr> <tr> <td>Company</td> <td>:</td> <td><input name="company" type="text" id="company"></td> </tr> <tr> <td>Phone</td> <td>:</td> <td><input name="phone" type="text" id="phone"></td> </tr> <tr> <td>Mobile</td> <td>:</td> <td><input name="mobile" type="text" id="mobile"></td> </tr> <tr> <td>Email</td> <td>:</td> <td><input name="email" type="text" id="email"></td> </tr> <tr> <td>Called</td> <td>:</td> <td><input type="checkbox" name="call" value="training" /> Training <input type="checkbox" name="call" value="business" /> Business <input type="checkbox" name="call" value="legal" /> Legal <input type="checkbox" name="call" value="other" /> Other</td> </tr> </tr> <tr> <td>Patched To</td> <td>:</td> <td> <select name="patch"> <option value="sperkins">S.Perkins</option> <option value="srayson">S.Rayson</option> <option value="strandafil">S.Trandafil</option> <option value="tmoore">T.Moore</option> <option value="lharding">L.Harding</option> <option value="vmitchell">V.Mitchell</option> <option value="achilvers">A.Chilvers</option> <option value="aedwards">A.Edwards</option> <option value="rfrost">R.Frost</option> <option value="ohoogenhout">O.Hoogenhout</option> <option value="pkeily">P.Keily</option> </select> </td> </tr> <tr> <td>Filled out by</td> <td>:</td> <td><input name="user" type="text" id="user"></td> </tr> <tr> <td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </td> </tr> </table> </form> <?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="members"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Get values from form $name=$_POST['name']; $company=$_POST['company']; $phone=$_POST['phone']; $mobile=$_POST['mobile']; $email=$_POST['email']; $call=$_POST['call']; $patch=$_POST['patch']; $user=$_POST['user']; // Insert data into mysql $sql="INSERT INTO $tbl_name(name, company, phone, mobile, email, call, patch, user)VALUES('$name', '$company', '$phone' '$mobile', '$email', '$call', '$patch', '$user')"; $result=mysql_query($sql); // if successfully insert data into database, displays message "Successful". if($result){ echo "Successful"; echo "<BR>"; echo "<a href='insert.php'>Back to main page</a>"; } else { echo "ERROR"; } // close connection mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 23, 2012 Share Posted April 23, 2012 How are you accessing the pages via the browser? Are you accessing them through their file system locations or are you "requesting" them through the built-in web server? Also, did you enable the web services in the configuration for the device? Quote Link to comment Share on other sites More sharing options...
AEdwards Posted April 23, 2012 Author Share Posted April 23, 2012 How are you accessing the pages via the browser? Are you accessing them through their file system locations or are you "requesting" them through the built-in web server? Using my computers browser and opening them from the file location. e.g "\\diskstation\web\insert.php" Also, did you enable the web services in the configuration for the device? Webservices, PHP and MySQL have all been enabled. Quote Link to comment Share on other sites More sharing options...
creata.physics Posted April 23, 2012 Share Posted April 23, 2012 what does phpinfo() say? Make a page called test.php and have just that function in the page and make sure it gives you the output you are expecting. Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 23, 2012 Share Posted April 23, 2012 How are you accessing the pages via the browser? Are you accessing them through their file system locations or are you "requesting" them through the built-in web server? Using my computers browser and opening them from the file location. e.g "\\diskstation\web\insert.php" Is that the FILE path or the WEB path? You can't simply load a PHP file in your browser and expect the PHP code to be parsed. You have to request the file from the web server path. EDIT: The manual is a little vague, but it looks as if the "web" folder is the FILE path. And, I think you need to be accessing the file using http://Synology_Server_Name/filename.php (assuming the file is in the root of the "Web" folder) Quote Link to comment Share on other sites More sharing options...
AEdwards Posted April 23, 2012 Author Share Posted April 23, 2012 Is that the FILE path or the WEB path? You can't simply load a PHP file in your browser and expect the PHP code to be parsed. You have to request the file from the web server path. EDIT: The manual is a little vague, but it looks as if the "web" folder is the FILE path. And, I think you need to be accessing the file using http://Synology_Server_Name/filename.php (assuming the file is in the root of the "Web" folder) Ah! It works! God bless your cotton socks! This has been giving me a headache and I was sure i was reading it right, I thought it said the file path was the URL... Well Much appreciated! Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 23, 2012 Share Posted April 23, 2012 Is that the FILE path or the WEB path? You can't simply load a PHP file in your browser and expect the PHP code to be parsed. You have to request the file from the web server path. EDIT: The manual is a little vague, but it looks as if the "web" folder is the FILE path. And, I think you need to be accessing the file using http://Synology_Server_Name/filename.php (assuming the file is in the root of the "Web" folder) Ah! It works! God bless your cotton socks! This has been giving me a headache and I was sure i was reading it right, I thought it said the file path was the URL... Well Much appreciated! Yeah, the manual sort of sucks on that one particular point. I didn't see any reference of what the web path was in the setup. But, I say the web path mentioned when enabling web space for users. So, I just modified that one to what would seem logical. Quote Link to comment Share on other sites More sharing options...
AEdwards Posted April 23, 2012 Author Share Posted April 23, 2012 <?php $host="Localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="members"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Get values from form $name=$_POST['name']; $company=$_POST['company']; $phone=$_POST['phone']; $mobile=$_POST['mobile']; $email=$_POST['email']; $call=$_POST['call']; $patch=$_POST['patch']; $user=$_POST['user']; // Insert data into mysql $sql="INSERT INTO $tbl_name(name, company, phone, mobile, email, call, patch, user)VALUES('$name', '$company', '$phone' '$mobile', '$email', '$call', '$patch', '$user')"; $result=mysql_query($sql); // if successfully insert data into database, displays message "Successful". if($result){ echo "Successful"; echo "<BR>"; echo "<a href='insert.php'>Back to main page</a>"; } else { echo "ERROR 1"; //This is where the error is. Not sure why it's not working } // close connection mysql_close(); ?> Just out of curiousity, on the line that says "echo "ERROR 1"; The error1 keeps appearing, so it's not putting the information into the database for some reason, any thoughts would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 23, 2012 Share Posted April 23, 2012 Well, simply echoing "ERROR 1" isn't providing much help now is it? Why don't you echo something that will provide some actionable information: if($result) { echo "Successful<BR><a href='insert.php'>Back to main page</a>"; } else { echo "ERROR 1<br>"; echo "Query: {$sql}<br>\n"; echo "Error: " . mysql_error(); } Quote Link to comment Share on other sites More sharing options...
AEdwards Posted April 23, 2012 Author Share Posted April 23, 2012 ERROR 1 Query: INSERT INTO members(name, company, phone, mobile, email, call, patch, user)VALUES('Name Test', 'Company Test', 'Phone Test' 'Mobile Test', 'Email Test', 'other', 'aedwards', 'A.Edwards') 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 'call, patch, user)VALUES('Name Test', 'Company Test', 'Phone Test' 'Mobile Test'' at line 1 Thats the error i've got popping up. :S Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 23, 2012 Share Posted April 23, 2012 I didn't check all your field names, but 'call' is a MySQL reserved word. You can either change the field name or enclose the reference in back quotes. Also, you should REALLY be validating/sanitizing user input before using it in a query // Get values from form $name = mysql_real_escape_string(trim($_POST['name'])); $company = mysql_real_escape_string(trim($_POST['company'])); $phone = mysql_real_escape_string(trim($_POST['phone'])); $mobile = mysql_real_escape_string(trim($_POST['mobile'])); $email = mysql_real_escape_string(trim($_POST['email'])); $call = mysql_real_escape_string(trim($_POST['call'])); $patch = mysql_real_escape_string(trim($_POST['patch'])); $user = mysql_real_escape_string(trim($_POST['user'])); $sql = "INSERT INTO $tbl_name (`name`, `company`, `phone`, `mobile`, `email`, `call`, `patch`, `user`) VALUES ('$name', '$company', '$phone' '$mobile', '$email', '$call', '$patch', '$user')"; $result = mysql_query($sql); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.