0

I want to create one page, where users add their informations.. I allready have that page created, but my real problem its down code..

I have some kind of problem, with that part of code:

<?php
//Connect to DB
$db = mysql_connect("localhost","USER","PASS") or die("Database Error");
mysql_select_db("DB",$db);

//Get ID from request
$idstire = isset($_GET['idstire']) ? (int)$_GET['idstire'] : 0;

//Check id is valid
if($idstire > 0)
{
//Query the DB
$resource = mysql_query("SELECT * FROM stiri2 WHERE idstire = " . $idstire);
if($resource === false)
{
    die("Eroare la conectarea cu baza de date");
}

if(mysql_num_rows($resource) == 0)
{
    die("Se pare ca stirea nu mai exista, sau a fost stearsa. <a     href='http://www.wanted-web.ro'>ACASA</a>");
}

$user = mysql_fetch_assoc($resource);

echo "
<div class='main-article-content'>
<h2 class='article-title'>asd</h2>

<div class='article-photo'>
<img src='" . $user['poza'] . "' class='setborder' alt='' />
</div>

<div class='article-controls'>

<div class='date'>
<div class='calendar-date'>" . $user['data'] . "</div>

                            </div>

<div class='right-side'>
<div class='colored'>
<a href='' class='icon-link'><span class='icon-text'></span>Printeaza articol</a>
<a href='#' class='icon-link'><span class='icon-text'></span>Trimite prietenilor</a>
                                </div>

                                <div>
<a href='#' class='icon-link'><span class='icon-text'></span>de Cristian Cosmin D.</a>
<a href='#' class='icon-link'><span class='icon-text'></span>39 comentarii</a>
                                </div>
                            </div>

<div class='clear-float'></div>


                        </div>


<div class='shortcode-content'>
<p>" . $user['nume'] . " , " . $user['prenume'] . " , " . $user['varsta'] . " , " . $user['localitatea'] . "</p>
                        </div>
                    </div>


";
}

$query = "UPDATE stiri2 SET accesari = accesari + 1 WHERE idstire=\"" . $idstire . "\"";
$result = mysql_query($query) OR die(mysql_error());
?>

It's show me error from here:

if(mysql_num_rows($resource) == 0)
{
    die("Se pare ca stirea nu mai exista, sau a fost stearsa. <a     href='http://www.wanted-web.ro'>ACASA</a>");
}

I really dont understand why!?

Can someone explain me? Thank you!

6
  • 1
    Is this new code? If it is you might want to consider not using mysql_* functions as they are deprecated. Consider prepared statements instead, with PDO or MySQLi. Commented Aug 24, 2013 at 12:23
  • Perhaps you should consider telling us what error you get. Commented Aug 24, 2013 at 12:24
  • Is there any record in stiri2 table maybe? Commented Aug 24, 2013 at 12:24
  • That error: boldSe pare ca stirea nu mai exista, sau a fost stearsa. <a href='wanted-web.ro'>ACASA</a>**bold** Commented Aug 24, 2013 at 12:25
  • table records are "id , nume , prenume , varsta , localitatea, numep, poza, data, accesari" . when i write details on form,they are added in database.. but in that page show me that error Commented Aug 24, 2013 at 12:27

3 Answers 3

1

mysql_query should have the second parameter as the connection which is in your case $db

$resource = mysql_query("SELECT * FROM stiri2 WHERE idstire = " . $idstire,$db);

if this also not works then use mysql_error to know the exact error

$row=mysql_num_rows($resource);
if($row)
{

}
else
{
    mysql_error();
}

this will show you if there is problwm in mysql_num_rows

Sign up to request clarification or add additional context in comments.

3 Comments

i changed with your code, but now not show me informations from database.. Not show any error, but not show informations added.. I hope to understand what i say
@MuzicaVeche: You do understand that there is no information to show, right?
now i see the error.. i try to resolve that.. ty a lot brothers for help me.
1

Well the problem is, that your SQL Statement does not have any results.

Please check if your database contains some rows for this idstire.

4 Comments

idstire row exist , and informations are added succesfully .. but still show me the error on page
Try to execute the SQL Statement directly in PHPMyAdmin to test it.
its show me that: ERROR: Unknown Punctuation String @ 3 STR: // SQL: //Get ID from request $idstire = isset($_GET['idstire']) ? (int)$_GET['idstire'] : 0;
Paste this "SELECT * FROM stiri2 WHERE idstire = X" in to PMA and replace X with the idstire you normally use for test purpose.
1

If $_GET['idstire'] is not set, you are setting $idstire to 0. Is there any entry in the table for idstire=0?

You can print your php query with $idstire replaced with its value. Take that query and execute in phpmyadmin to see the error. Also verify that row exists for the value of $idstire being used in the query.

1 Comment

i see my error was in form page.. i resolved that.. ty a lot brothers for opening my eyes !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.