Data does not go into db on-line?

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 943 Views - Last Post: 30 May 2012 - 04:46 PM

#16 eduardar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 29-May 12

Re: Data does not go into db on-line?

Posted 30 May 2012 - 08:54 AM

And this code:

<?php
session_start();  
if(isset($_SESSION['views']))
    $_SESSION['views'] = $_SESSION['views']+ 1;
else
    $_SESSION['views'] = 1;

echo "views = ". $_SESSION['views']; 
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


<head>

    <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">

    <title>Eduard Lid</title>
    <link rel="stylesheet" type="text/css" href=ex1.css>
</head>


<body>
<div id="floater">

    <ul id="flags">
        <li>eng<a href="portfolio.html"><span id="amer"></span></a></li>
        <li>es<a href="portfolio.html"><span id="spanish"></span></a></li>
        <li>d<span id="germ"></span></li>
        <li>nl<span id="dutc"></span></li>
        <li>f<span id="fren"></span></li>
    </ul>

<?php

$Site_Name = $_POST['site_name'];
$Site_URL = $_POST['site_url'];
$Description = $_POST['Description'];


$con = mysql_connect("localhost","root","usbw") or die(mysql_error());

$title = 'PHP';

mysql_select_db("website", $con);
$q = $conn->prepare($sql);
$q->execute(array($title));


$sql="INSERT INTO links (Site_Name, Site_URL, Description)
VALUES ('$_POST[site_name]','$_POST[site_url]','$_POST[Description]')";

if (!mysql_query($sql,$con))
{
    die('Error: ' . mysql_error());
}

mysql_close($con);

?>



<form action="insert.php" method="POST">
    <label for="s_name">Site Name:</label>
    <input type="text" id="s_name" name="site_name">
    <label for="s_url">Site URL:</label>
    <input type="text" id="s_url" name="site_url">
    <label for="Description">Description:</label>
    <input type="text" id="Description" name="Description">
    <input type="submit" value="Add Link">
</form>

</div><!--end #floater -->

<div id="vertical">

</div>




<div id="main">

    <p><img id="eduard" src="eduard.JPG" alt="img Eduard Lid"></p>

 <p><img id="lake" src="lake.jpg" alt="img lake"></p>


<iframe id="player" 
  src="http://www.youtube.com/embed/h2AWKgU0cN4" frameborder="0"></iframe>
<br>

        <p>Web designer<span class="right">Diseñador de sitios web</span></p>


        <p>Translator<span class="right">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Traductor
</span>

        <ul id="links">
            <li><a href="english.html">more</a></li>
            <li><a href="spanish.html">más</a></li>

        </ul>


</div><!--end #main -->

<h1>Eduard Lid</h1>

<p>
    <a href="http://validator.w3.org/check?uri=referer"><img
      src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>
  </p>
  


<p id="copyright">Copyright &copy; 2012</p>



</body>
</html>


Was This Post Helpful? 0
  • +
  • -

#17 eduardar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 29-May 12

Re: Data does not go into db on-line?

Posted 30 May 2012 - 03:06 PM

I now get the error message: no database selected??
Was This Post Helpful? 0
  • +
  • -

#18 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3710
  • View blog
  • Posts: 5,958
  • Joined: 08-June 10

Re: Data does not go into db on-line?

Posted 30 May 2012 - 04:36 PM

View Posteduardar, on 30 May 2012 - 02:18 PM, said:

Is this a right prepared statement:

No. Not at all. The old mysql_connect family of functions do not support prepared statements. What you are doing there is mixing the old MySQL extension with a couple of lines from what looks like the PDO extension.

If you want to use prepared statements (which you should) then you need to stop using all functions that start with mysql_ and instead use PDO or MySQLi. - The docs for those extensions contain a lot of examples you can look through, and of course there is Dormilich's PDO tutorial here on DIC I linked to earlier, and another for Introduction to MySQLi and Prepared Statements.

Note that PDO is completely object orientated, but MySQLi has a procedural interface, much like that of the mysql_ functions you are using now. If you aren't familiar with OOP, you may want to start with MySQLi.

Quote

I now get the error message: no database selected??

In the two latest examples you posted you are again ignoring the return value of the mysql_select_db call, so you may well be missing an error there. Remember to do:
mysql_select_db("website", $con) or die(mysql_error());


So that you'll see the error message.
Was This Post Helpful? 0
  • +
  • -

#19 eduardar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 29-May 12

Re: Data does not go into db on-line?

Posted 30 May 2012 - 04:46 PM

View PostAtli, on 30 May 2012 - 04:36 PM, said:

View Posteduardar, on 30 May 2012 - 02:18 PM, said:

Is this a right prepared statement:

No. Not at all. The old mysql_connect family of functions do not support prepared statements. What you are doing there is mixing the old MySQL extension with a couple of lines from what looks like the PDO extension.

If you want to use prepared statements (which you should) then you need to stop using all functions that start with mysql_ and instead use PDO or MySQLi. - The docs for those extensions contain a lot of examples you can look through, and of course there is Dormilich's PDO tutorial here on DIC I linked to earlier, and another for Introduction to MySQLi and Prepared Statements.

Note that PDO is completely object orientated, but MySQLi has a procedural interface, much like that of the mysql_ functions you are using now. If you aren't familiar with OOP, you may want to start with MySQLi.

Quote

I now get the error message: no database selected??

In the two latest examples you posted you are again ignoring the return value of the mysql_select_db call, so you may well be missing an error there. Remember to do:
mysql_select_db("website", $con) or die(mysql_error());


So that you'll see the error message.


Ill give it up! Ive been with this problem many days! I wont be a web developer! However, many thanks for your time and explanations! Bye!
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2