please help me i am new to PHP and i am having this error on my program (Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\project\viewforum.php on line 29) <?php include("config.php"); if(isset($_GET['id']) == TRUE) { if(is_numeric($_GET['id']) == FALSE) { header("Location: " . $config_basedir); } $validforum = $_GET['id']; } else { header("Location: " . $config_basedir); } require("header.php"); $forumsql = "SELECT * FROM forums WHERE id = " . $validforum . ";"; $forumresult = mysql_query($forumsql); $forumrow = mysql_fetch_assoc($forumresult); echo "<h2>" . $forumrow['name'] . "</h2>"; echo "<a href='index.php'>" . $config_forumsname . " forums</a><br /><br />"; echo "[<a href='newtopic.php?id=" . $validforum . "'>New Topic</a>]"; echo "<br /><br />"; $topicsql = "SELECT MAX( messages.date ) AS maxdate, topics.id AS topicid, topics.*, users.* FROM messages, topics, users WHERE messages.topic_id = topics.id AND topics.user_id = users.id AND topics.forum_id = " . $validforum . " GROUP BY messages.topic_id ORDER BY maxdate DESC;"; $topicresult = mysql_query($topicsql); $topicsnumrows = mysql_num_rows($topicresult); if($topicsnumrows == 0) { echo "<table width='300px'><tr><td>No topics!</td></tr></table>"; } else { echo "<table class='forums'>"; echo "<tr>"; echo "<th>Topic</th>"; echo "<th>Replies</th>"; echo "<th>Author</th>"; echo "<th>Date Posted</th>"; echo "</tr>"; while($topicrow = mysql_fetch_assoc($topicresult)) { $msgsql = "SELECT id FROM messages WHERE topic_id = " . $topicrow['topicid']; $msgresult = mysql_query($msgsql); $msgnumrows = mysql_num_rows($msgresult); echo "<tr>"; echo "<td>"; echo "<strong> <a href='viewmessages.php?id=" . $topicrow['topicid'] . "'>" . $topicrow['subject'] . "</a></strong></td>"; echo "<td>" . $msgnumrows . "</td>"; echo "<td>" . $topicrow['username'] . "</td>"; echo "<td>" . date("D jS F Y g.iA", strtotime($topicrow['date'])) . "</td>"; echo "<tr>"; } echo "</table>"; ?> <?php } require("footer.php"); ?>
anything in $topicsql = "SELECT MAX( messages.date ) AS maxdate, topics.id AS topicid, topics.*, users.* FROM messages, topics, users WHERE messages.topic_id = topics.id AND topics.user_id = users.id AND topics.forum_id = " . $validforum . " GROUP BY messages.topic_id ORDER BY maxdate DESC;"; that is varchar should be wrapped in single quotes then retry.. also That error usually indicates that MySQL was unable to process the SQL you provided it, so you need to debug the query code. Check to see if the result of your mysql_query() is false, and if so, do an error_log() or otherwise output the query string and the result of mysql_error() to find out what was wrong with the query.
This really is the mother of all annoying mySQL errors, its either the field count, something to do with quote marks, spelling mistake or nothing in your database.
mysql_query is probably returning a false due to query failure (because of possible incorrect SQL query). I would recommend fixing the query.
Parse error: syntax error, unexpected T_ELSE in C:\xampp\htdocs\Forum\Login.php on line 64 PLease help me with this error . here is the code: <?php session_start(); require("config.php"); require("functions.php"); $db = mysql_connect($dbhost, $dbuser, $dbpassword); mysql_select_db($dbdatabase, $db); $db = mysql_connect($dbhost, $dbuser, $dbpassword); mysql_select_db($dbdatabase, $db); if($_POST['submit']) { $sql = "SELECT * FROM users WHERE username = '" . $_POST['username'] . "' AND password = '" . $_POST['password'] . "';"; $result = mysql_query($sql); $numrows = mysql_num_rows($result); $result = mysql_query($sql); $numrows = mysql_num_rows($result); if($numrows == 1) { $row = mysql_fetch_assoc($result); if($row['active'] == 1) { session_register("USERNAME"); session_register("USERID"); $_SESSION['USERNAME'] = $row['username']; $_SESSION['USERID'] = $row['id']; switch($_GET['ref']) { case "newpost": if(isset($_GET['id']) == FALSE) { header("Location: " . $config_basedir . "/newtopic.php"); } else { header("Location: " . $config_basedir . "/newtopic.php?id=" . $_GET['id']); } break; case "reply": if(isset($_GET['id']) == FALSE) { header("Location: " . $config_basedir . "/newtopic.php"); } else { header("Location: " . $config_basedir . "/newtopic.php?id=" . $_GET['id']); } break; default: header("Location: " . $config_basedir); break; } } else { require("header.php"); echo "This account is not verified yet. You were emailed a link to verify the account. Please click on the link in the email to continue."; } echo "This account is not verified yet. You were emailed a link to verify the account. Please click on the link in the email to continue."; } } else { header("Location: " . $config_basedir . "/login.php?error=1"); } else { require("header.php"); if($_GET['error']) { /echo "Incorrect login, please try again!"; } ?> <form action="<?php echo pf_script_with_get($SCRIPT_NAME); ?>" method="post"> <table> <tr> <td>Username</td> <td><input type="text" name="username"></td> </tr> <tr> <td>Password</td> <td><input type="password" name="password"></td> </tr> <tr> <td></td> <td><input type="submit" name="submit" value="Login!"></td> </tr> </table> </form> Don't have an account? Go and <a href="register.php">Register</a>! <?php } require("footer.php"); ?>
Should really start indenting your code more. helps when debugging like this. having it all railed to one side makes it a lot harder. Try this out. <?php session_start(); require("config.php"); require("functions.php"); $db = mysql_connect($dbhost, $dbuser, $dbpassword); mysql_select_db($dbdatabase, $db); $db = mysql_connect($dbhost, $dbuser, $dbpassword); mysql_select_db($dbdatabase, $db); if($_POST['submit']) { $sql = "SELECT * FROM users WHERE username = '" . $_POST['username'] . "' AND password = '" . $_POST['password'] . "';"; $result = mysql_query($sql); $numrows = mysql_num_rows($result); $result = mysql_query($sql); $numrows = mysql_num_rows($result); if($numrows == 1) { $row = mysql_fetch_assoc($result); if($row['active'] == 1) { session_register("USERNAME"); session_register("USERID"); $_SESSION['USERNAME'] = $row['username']; $_SESSION['USERID'] = $row['id']; switch($_GET['ref']) { case "newpost": if(isset($_GET['id']) == FALSE) { header("Location: " . $config_basedir . "/newtopic.php"); } else { header("Location: " . $config_basedir . "/newtopic.php?id=" . $_GET['id']); } break; case "reply": if(isset($_GET['id']) == FALSE) { header("Location: " . $config_basedir . "/newtopic.php"); } else { header("Location: " . $config_basedir . "/newtopic.php?id=" . $_GET['id']); } break; default: header("Location: " . $config_basedir); break; } else { require("header.php"); echo "This account is not verified yet. You were emailed a link to verify the account. Please click on the link in the email to continue."; } } } echo "This account is not verified yet. You were emailed a link to verify the account. Please click on the link in the email to continue."; } else { header("Location: " . $config_basedir . "/login.php?error=1"); } else { require("header.php"); if($_GET['error']) { echo "Incorrect login, please try again!"; //had to remove a "/" in very front on this line } ?> <form action="<?php echo pf_script_with_get($SCRIPT_NAME); ?>" method="post"> <table> <tr> <td>Username</td> <td><input type="text" name="username"></td> </tr> <tr> <td>Password</td> <td><input type="password" name="password"></td> </tr> <tr> <td></td> <td><input type="submit" name="submit" value="Login!"></td> </tr> </table> </form> Don't have an account? Go and <a href="register.php">Register</a>! <?php } require("footer.php"); ?> PHP:
its nw giving me this error arse error: syntax error, unexpected T_ELSE in C:\xampp\htdocs\Forum\Login.php on line 60
Fix my code, please! Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\ index.php <?php include 'includes/connection.php'; $query = "SELECT * FROM tuotteet"; $result = mysql_query($query); while($tuote = mysql_fetch_array($result)) { echo "<h3>" . $tuote['Nimi'] . "</h3>"; echo "<p>" . $tuote['Kuvaus'] . "</p>"; echo "<a href=\"modify.php\id=" . $tuote['ID'] . "\">Muokkaa Tuotetta</a>"; echo "<span> </span>"; echo "<a href=\"delete.php?id=" . $tuote['ID'] . "\">Muokkaa Tuotetta</a>"; } ?> <h1>Lisää tuote</h1> <form action="create.php" method="post"> Tuotteen nimi <input type="text" name="inputName" value="" /><br /> Tuotteen kuvaus <input type="text" name="inputDesc" value="" /> <br /> <input name="submit" type="submit" id="submit" /> </form>