Jump to content

AEdwards

Members
  • Posts

    13
  • Joined

  • Last visited

    Never

Posts posted by AEdwards

  1. Hello,

    I've just made a News system for a website i've been working on using, It has all been going fine-and-dandy. Until...

     

    My boss has asked me to add in a simple Login feature so people don't have to type there names in every form they fill-out when they use the website, My major problem is I can't get the news field to display the Login "Username" in the news, It's kind of a head-ache. (This is all for an intranet site).

     

    Sorry for the super long-ness in the post, just not sure where to look first to fix this problem :S.

     

    Please let me know if any other information is needed.

     

    Thanks!

     

    Login:

    <?php
    include 'header.php';
    ?>
    <form name="form1" method="post" action="checklogin.php">
    <table id="formcss">
    <tr>
    <td colspan="3"><strong>Member Login </strong></td>
    </tr>
    <tr>
    <td width="78">Username</td>
    <td width="6">:</td>
    <td width="294"><input name="myusername" type="text" id="myusername"></td>
    </tr>
    <tr>
    <td>Password</td>
    <td>:</td>
    <td><input name="mypassword" type="text" id="mypassword"></td>
    </tr>
    <tr>
    <td> </td>
    <td> </td>
    <td><input type="submit" name="Submit" value="Login"></td>
    </tr>
    </table>
    </td>
    </form>
    <?php
    include 'footer.php';
    ?>

     

    check login

    <?php
    include 'header.php';
    ?>
    <?php
    $host="localhost"; // Host name 
    $username="root"; // Mysql username 
    $password=""; // Mysql password 
    $db_name="test"; // Database name 
    $tbl_name="admins"; // Table name
    
    // Connect to server and select databse.
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    // username and password sent from form 
    $myusername=$_POST['myusername']; 
    $mypassword=$_POST['mypassword'];
    
    // To protect MySQL injection (more detail about MySQL injection)
    $myusername = stripslashes($myusername);
    $mypassword = stripslashes($mypassword);
    $myusername = mysql_real_escape_string($myusername);
    $mypassword = mysql_real_escape_string($mypassword);
    
    $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
    $result=mysql_query($sql);
    
    // Mysql_num_row is counting table row
    $count=mysql_num_rows($result);
    // If result matched $myusername and $mypassword, table row must be 1 row
    
    if($count==1){
    // Register $myusername, $mypassword and redirect to file "login_success.php"
    session_register("myusername");
    session_register("mypassword"); 
    header("location:login_success.php");
    }
    else {
    echo "Wrong Username or Password<p>";
    
    echo "</p><a href=http://nrsdiskstation/login.php>Go Back</a>";
    }
    ?>
    <?php
    include 'footer.php';
    ?>

     

    News

    <?php
    $host="localhost"; // Host name 
    $username="root"; // Mysql username 
    $password=""; // Mysql password 
    $db_name="test"; // Database name 
    $tbl_name="admin"; // 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 value of id that sent from address bar
    $id=$_GET['id'];
    "SELECT column_name1, column_name2 FROM table_name";
    
    // Retrieve data from database 
    $sql="SELECT * FROM $tbl_name WHERE id='$id'";
    $result=mysql_query($sql);
    
    $rows=mysql_fetch_array($result);
    ?>
    
    <?php
    include 'header.php';
    ?>
    <form name="form1" method="post" action="news_ac.php">
    <table id="formcss" width="100%" border="0" cellspacing="1" cellpadding="3" align="center">
    <tr>
    <td colspan="2" align="center"><strong>New News</strong></td>
    </tr>
    <tr>
    <td width="71">Title</td>
    <td width="301"><input name="title" type="text" id="title"></td>
    </tr>
    <tr>
    <td>News Type</td>
    <td>
    <select name="picture" id="picture">
    <option value="">None</option>
    <option value="<img src=http://nrsdiskstation/Images/urgent.png align=right valign=top>">Attention</option>
    <option value="<img src=http://nrsdiskstation/Images/about.png align=right valign=top>">About</option>
    <option value="<img src=http://nrsdiskstation/Images/dots.png align=right valign=top>">Information</option>
    </select>
    </td>
    </tr>
    <tr>
    <td>News</td>
    <td>
    <textarea rows="4" cols="33" name="news"></textarea>
    </td>
    </tr>
    <input name="date" type="hidden" id="date" value="<?php echo date('g:i - d/m/Y'); ?>">
    <input name="byuser" type="hidden" id="byuser" value="<? echo $rows['myusername']; ?>">
    <tr>
    <td colspan="2" align="center"><input type="submit" name="Submit" value="Submit"></td>
    </tr>
    </table>
    </form>
    <?php
    include 'footer.php';
    ?>

     

    News_Ac

    <?php
    include 'header.php';
    ?>
    <?php
    $host="localhost"; // Host name 
    $username="root"; // Mysql username 
    $password=""; // Mysql password 
    $db_name="test"; // Database name 
    $tbl_name="News"; // 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 
    $title=$_POST['title'];
    $news=$_POST['news'];
    $byuser=$_POST['byuser'];
    $picture=$_POST['picture'];
    $date=$_POST['date'];
    
    
    // Insert data into mysql 
    $data_no=$_GET['id'];
    $sql="INSERT INTO $tbl_name(`title`, `news`, `byuser`, `picture`, `date`)VALUES('$title', '$news', '$byuser', '$picture', '$date')";
    $result=mysql_query($sql);
    
    // if successfully insert data into database, displays message "Successful". 
    if($result)
    {
        echo "Successful<BR><a href='index.php'>Back to Index</a>";
    }
    else
    {
        echo "ERROR 1<br>";
        echo "Query: {$sql}<br>\n";
        echo "Error: " . mysql_error();
    }
    
    ?>
    <?php
    include 'footer.php';
    ?>

     

    News display:

    <?php
    include 'header.php';
    ?>
    <strong>Intranet System </strong> <a href="http://nrsdiskstation/news.php">(Post new news)</a><br>
    <?php
    
    $host="localhost"; // Host name 
    $username="root"; // Mysql username 
    $password=""; // Mysql password 
    $db_name="test"; // Database name 
    $tbl_name="News"; // 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");
    
    // Retrieve data from database 
    $sql="SELECT * FROM $tbl_name";
    $result=mysql_query($sql);
    
    // Start looping rows in mysql database.
    while($rows=mysql_fetch_array($result)){
    ?>
    <table id="formcss" align="center">
    <tr><Td>
    <strong><? echo $rows['title']; ?></strong>
    </td></tr>
    <tr><td>
    <? echo $rows['picture']; ?>
    <? echo $rows['news']; ?>
    </tr></td>
    <tr><td align="right">
    <h6><? echo $rows['byuser']; ?> @ <? echo $rows['date']; ?><br><a href="news_update.php?id=<? echo $rows['id']; ?>">edit</a> last edited on: <? echo $rows['editdate']; ?></h6>
    </td></td>
    </table>
    <br><br><br>
    <?
    // close while loop 
    }
    
    // close connection 
    mysql_close();
    ?>
    <?php
    include 'footer.php';
    ?>

  2. After changing the ' to ` I've got:

     

    ERROR 1
    Query: INSERT INTO members(`name`, `company`, `phone`, `mobile`, `email`, `call`, `patch`, `user`)VALUES('', '', '' '', '', '', '', '')
    Error: Column count doesn't match value count at row 1

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

     

    Sorry bout that, I've got it it another post from earlier.

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

  5. <?php
    include 'header.php';
    ?>
    <form name="form1" method="post" action="insert_ac.php">
    <table id="formcss" width="100%" border="0" cellspacing="1" cellpadding="3" align="center">
    <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>
    </form>
    <?php
    include 'footer.php';
    ?>

     

    <?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();
    ?>

     

    Can anyone see what i've done wrong here?  I swear my brain is going to explode if i look over this one more time.

     

    Just a simple form trying to submit to the database :-\

  6. <?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.

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

     

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

  9. 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();
    ?>

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

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