PHP - Boolean Error Calling External Mysql_query?
Hey,
I found some code online that references a bunch of sql commands in there own functions that can be called from a require_once(), All the ones I have tried work expect mysql_query when its called it returns this error: Quote Warning: mysql_result() expects parameter 1 to be resource, boolean given in But once i paste the mysql_query into the main script it works fines. code below is mine and the online script. Webcode: Code: [Select] $sql = "SELECT cat_id, cat_parent_id, cat_name, cat_description, cat_image FROM tbl_category WHERE cat_parent_id = $catId ORDER BY cat_name"; /* Don't know what getPagingQuery does and couldnt find any reference to it so i removed it and replaced with simple query in my own code */ $result = dbQuery(getPagingQuery($sql, $rowsPerPage)); My Code: Code: [Select] $sql = "SELECT cat_id, cat_parent_id, cat_name, cat_description, cat_image FROM tbl_category WHERE cat_parent_id = $catId ORDER BY cat_name"; $result = dbQuery($sql); Include file: Code: [Select] $dbHost = "localhost"; //SQL Server $dbUser = "root"; // Database username $dbPass = ""; // Database password $dbName = "lh_shop"; // Database name $sqlCon = mysql_connect($dbHost, $dbUser, $dbPass) or die ('MYSQL connection Failed. ' . mysql_error()); mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error()); // Database query functions function dbQuery($sql) { return mysql_query($sql) or die('Query failed. ' . mysql_error()); } Thanks, I really hope someone has had this issue Similar Tutorialshey I am still little new in php can you help me in this one func.php function confirm_query($result_set){ if(!$result_set){ die(mysql_error()); } function get_subjects_all() { global $connection ; $sub_query = "SELECT * FROM subjects ORDER BY position ASC"; $subject_query = mysql_query($sub_query,$connection); confirm_query($subject_query) ; return $subject_query; } function get_pages_all($subject_id) { global $connection; $query = "SELECT * FROM pages WHERE subject_id = '$subject_id' ORDER BY position ASC"; $page_set = mysql_query($query, $connection); confirm_query($page_set); return $page_set; } test.php require_once("config.php"); require_once("func.php"); $subject_query = get_subjects_all(); while($subject = mysql_fetch_array($subject_query)) { echo "<a href= \"test.php?subj=" . urlencode($subject["id"]) . "\">{$subject['menu_name']} <br />"; } $an = $subject["id"] ; $page_set = get_pages_all($an); while($page = mysql_fetch_array($page_set)) { echo "<a href = \"test.php?page=" . urldecode($page["id"]) . "\">{$page['menu_name']} </a><br />" ; // echo "<b> <a href= '1.php?page={$page['id']}' >{$page['menu_name']} </a></b> <br />"; } in this line WHERE subject_id = '$subject_id' the query don't work and gives me sql error i tried with this one ' ".$subject_id." ' but not worked but if i changed $subject_id to a number it work and read the data from the table thanks in advanced . Is there something wrong this? If so, I'm not seeing it...I keep getting this error: Quote ( ! ) Parse error: syntax error, unexpected T_STRING in C:\Program Files\wamp\www\register.php on line 1059 Here's my code for registering a member: Code: [Select] <?php mysql_query (INSERT INTO fans (id, username, email, password, country, region, gender, status, account, subscription, time_registered, date_registered, birthdate, name, website, age, activation_key) VALUES ('', '{$_SESSION["user"]["username"]}', '{$_SESSION["user"]["email"]}', '{$_SESSION["user"]["password"]}', '{$_SESSION["user"]["country"]}', '{$_SESSION["user"]["region"]}', '{$_SESSION["user"]["gender"]}', 'Offline', 'Inactive', 'Unsubscribed', '{$_SESSION["user"]["time"]}', '{$_SESSION["user"]["date"]}', '{$_SESSION["user"]["birthdate"]}', '{$_SESSION["user"]["name"]}', '{$_SESSION["user"]["website"]}', '{$_SESSION["user"]["age"]}', '{$_SESSION["user"]["activation_key"]}')) or die ("Could not register member"); ?> Help, please and thank you! Hoping someone can help me, ive spent the last hour looking up examples of mysql_query(Insert) and changing my query but im still gettin a syntax error and I cant understand where. Ive tried removing apostrophies and putting the longest variable string outside of the speach marks without any joy. mysql_query("INSERT INTO $QA_table (SUB_CATEGORY, QUESTION, FROM, FROM_EMAIL, DISPLAY) VALUES ('$sub_cat','$message','$from','$from_email','2')") or die(mysql_error()); I get the following 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 'FROM, FROM_EMAIL, DISPLAY) VALUES ('Range','test question bla bla bla','Phil','phi' at line 1 why does the top code work and the bottom does not? what am i missing? the only real diffrence is the query. im getting "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in " for this code $numrows = mysql_num_rows($result). the query works fine in phpmyadmin. thanks $query = "SELECT * FROM dsgi_servlist " ; $result = mysql_query($query) ; $numrows = mysql_num_rows($result) ; echo $numrows ; $sql = "SELECT COUNT(*) FROM dsgi_servlist where location = 'hdd'"; $result = mysql_query($sql) ; $numrows = mysql_num_rows($result) ; echo $numrows ; Hi, I have an image uploader here and I am trying to have a user enter their password and check a box in order to submit their image. I am having trouble validating the password. I get this error message: "Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/content/68/6372768/html/submit.php on line 58" From this section of the code: $query = "SELECT * FROM user_info WHERE password = SHA($user_password)"; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { $valid_password = true; } Anyone see what I am doing wrong? The password stored in my DB is encrypted with SHA. Code: [Select] <?php // Start the session require_once('startsession.php'); // Insert the page header $page_title = 'Submit an Image'; require_once('header.php'); require_once('appvars.php'); require_once('connectvars.php'); // Show the navigation menu require_once('navmenu.php'); // Make sure the user is logged in before going any further. if (!isset($_SESSION['user_id'])) { echo '<center><table border="0" cellspacing = "20"><tr><td>'; echo '<p class="login">Please <a href="login.php">log in</a> to access this page.</p>'; echo '</td></tr></table></center>'; // Insert the page footer echo '<div class="footer">'; require_once('footer.php'); echo '</div>'; exit(); } ?> <div class="linkrow"> <!-- end .linkrow --></div> <div class="contentBlue960"> <img src = "/IMAGES/WEBSITE/capBlue960.jpg"> <?php if (isset($_POST['submit'])) { // Connect to the DB $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Set password to false $valid_password = false; // Grab the id data from the POST $image_name = $_FILES['image_name']['name']; $image_name_type = $_FILES['image_name']['type']; $image_name_size = $_FILES['image_name']['size']; $user_password = (mysqli_real_escape_string($dbc, trim($_POST['user_password']))); $agree = mysqli_real_escape_string($dbc, trim($_POST['agree'])); // Grab the id data from the DB if (!isset($_GET['user_id'])) { $query = "SELECT user_name, password FROM user_info WHERE user_id = '" . $_SESSION['user_id'] . "'"; } else { $query = "SELECT user_name, password FROM user_info WHERE user_id = '" . $_GET['user_id'] . "'"; } $data = mysqli_query($dbc, $query); $user_name = $row['user_name']; $password = $row['password']; $query = "SELECT * FROM user_info WHERE password = SHA($user_password)"; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { $valid_password = true; } // If image and password are entered if (!empty($user_password) && !empty($image_name)) { // If the entered password matches the user's password if ($valid_password == true) { // If the copyright is agreed to if (($agree) == ('checked')) { // If the pic is valid if ((($image_name_type == 'image/gif') || ($image_name_type == 'image/jpeg') || ($image_name_type == 'image/pjpeg') || ($image_name_type == 'image/png')) && ($image_name_size > 0) && ($image_name_size <= GW_MAXFILESIZE)) { if ($_FILES['image_name']['error'] == 0) { // Move the file to the target upload folder $target = GW_UPLOADPATH . $image_name; if (move_uploaded_file($_FILES['image_name']['tmp_name'], $target)) { // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Error connecting to MySQL server.'); // Write the data to the database $query = "INSERT INTO user_images VALUES (0, '$user_name', NOW(), '$image_name')"; mysqli_query($dbc, $query); // Confirm success with the user echo '<p>Thanks for submitting an image! Under review as soon as possible.</p>'; echo '<p><strong>User Name:</strong> ' . $user_name . '<br />'; echo '<img src="' . GW_UPLOADPATH . $image_name . '" alt="Submitted Image" /></p>'; echo '<p><a href="submit.php"><< Back to submit page.</a></p>'; // Clear the id data to clear the form $user_name = ""; $image_name = ""; mysqli_close($dbc); } else { echo '<p class="error">Sorry, there was a problem uploading your screen shot image.</p>'; } } } else { echo '<p class="error">The screen shot must be a GIF, JPEG, or PNG image file no greater than ' . (GW_MAXFILESIZE / 1024) . ' KB in size.</p>'; } // Try to delete the temporary screen shot image file @unlink($_FILES['image_name']['tmp_name']); } else { echo '<p class="error">Must agree with and check copyright box.</p>'; } } else { echo '<p class="error">Password Incorrect</p>'; } } else { // echo 'Pass' . $password . ' 1'; // echo 'User pass' . $user_password . ' 2'; // echo 'Checkbox' . $agree . ' 3'; // echo 'Username' . $user_name . ' 3'; echo '<p class="error">Please enter all of the information to add your image.</p>'; } } // mysqli_close($dbc); ?> <table border="1" cellspacing = "20"> <tr><td width = 960px><h2>Submit an Image</h2></td></tr> </table> <table border="1" cellspacing = "20"> <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <tr><td width = "300"> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo GW_MAXFILESIZE; ?>" /> <label for="image_name">Image:</label></td> <td><input type="file" id="image_name" name="image_name" /> </td></tr> <tr><td width = "300"> <label for="user_password">Enter Password:</label></td> <td><input type="text" id="user_password" name="user_password" /><br /> </td></tr> <tr><td width = "300"> <label for="terms">This image is my own work and I own all copyrights to it.</label></td> <td><input type="checkbox" id="agree" name="agree" value = "checked"/><br /> </td></tr> <tr><td width = "300"> <input type="submit" value="Submit Image" name="submit" /> </td></tr> </form> </td> </tr> </table> <img src = "/IMAGES/WEBSITE/bottomBlue960.jpg"> <!-- end .contentWhite960 --></div> <div class="footer"> <?php // Insert the page footer require_once('footer.php'); ?> <!-- end .footer --></div> Thanks if you can help, Craig Hello there, I'm having a issue where when I run the following statement: $Session = $Module['MySQL']->RowCount("SELECT * FROM xhost_accounts WHERE (account_username = '{$Module['MySQL']->Escape($AccountUsername)}' OR account_email = '{$Module['MySQL']->Escape($AccountUsername)}') AND account_password = MD5('{$AccountPassword}')") == 1 ? true:false; I am proceeded by the following error: Code: [Select] Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\Backend\MySQL-Module.php on line 49 Yet when I do the following statement: echo $Module['MySQL']->RowCount("SELECT * FROM xhost_accounts WHERE (account_username = '{$Module['MySQL']->Escape($AccountUsername)}' OR account_email = '{$Module['MySQL']->Escape($AccountUsername)}') AND account_password = MD5('{$AccountPassword}')") It gives me the output of 2 (That's the correct table row count)? Does anybody have any insight into why this could be happening thanks. I created this function to update my tour system. The query is working and is updating one row in the table, but I get a resource boolean error in the return section of the function. Any idea why? Code: [Select] function update_tour($uid, $step) { $step = (int)$step; $uid = (int)$uid; $sql = "UPDATE `users` SET `tour_step` = ${step} WHERE `id` = '${uid}'"; $q = mysql_query($sql) or die(mysql_error()); return (mysql_num_rows($q) === 1) ? mysql_result($q, 0): false; } why is this code not working? in php i have the following...
$keywords = "+hello +world"; $query= "SELECT * FROM forums WHERE MATCH (topics) AGAINST ('$keywords' IN BOOLEAN MODE)"; $results = mysqli_query($database, $query); $row = mysqli_fetch_assoc($results); $topics = $row['topics']; echo $topics; Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given... This is a new error for me. I tried looking through some older posts and so far nothing had fixed it and thus I am stumped. Any idea what could be throwing this error? Code: [Select] <table> <?php //open DB connection include 'dbconn.php'; $sql = "select * tbl_test"; $result = mysql_query($sql,$conn); print $sql; while ($row = mysql_fetch_array($result)){ $status = $row['status']; $space = $row['spacename']; if ($status=="reserved") { echo <<<END <tr> <td style="background-color:#F00; color:#FFF;" align="center">Reserved</td> </tr> END; } else { echo <<<END <tr> <td align="center">$space</td> </tr> END; } } ?> </table> 2 9 0 1 Fatal error: Call to a member function bind_param() on boolean.
It fails on the BIND_PARAM line.
I have looked at this all day, struggling with Mysqli as my normal MySql works fine with assoc and fetch.
I have verified in PhpInfo that mysqli is enabled. I have verified its loaded using <?php print_r(get_loaded_extensions()); Added utf8 just to make sure.
If I manually use the Wrong Password, I get a connection refused error, so I know its connected.
Verified my $_POST variables are there using Print in the 2 9 0 1 above.
All Table and Field Names are correct. Manual Insert works fine in myPhpAdmin. Tried Field Names and ? marks with and without single quotes. All fields are Integers in the table.
Could it be related to an Auto_Increment Field in the table for a record ID that I am not providing?? A normal insert in myPhpAdmin doesn't need it.
$QuestionID = $_POST['qID']; print $QuestionID . " ";
Thanks, CadJoe Edited August 26, 2017 by CadJoeHi all i am trying to use curl function recursively but when the function first execute it get the content but next time it give the following error Protocol http not supported or disabled in libcurl Code: [Select] $url = "http://www.example.com"; pager($url); function pager($url){ $urlArray = array(); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); echo curl_error($ch); // code to get url from result // i get an array here $urlArray curl_close($ch); foreach($urlArray as $value){ $urlval = urlget($value); if($urlval) { $urlval = str_replace("href=","",$urlval); $urlval = str_replace("'","",$urlval); echo $urlval.'<br>'; pager($urlval); } } } Hello,
I am having some troubles and was hoping someone could guide me through it.
Q: When ever I try call my get_status function all I get is a white page of nothing, no errors to work from etc... Can anyone here see what I am doing wrong?
PATH: index.php
NOTICE //<<-- KILLS PAGE
<?php spl_autoload_register(function ($class) { include '/lib/' . $class . '.inc'; }); $servers = new servers; echo $servers->get_servers(); echo "STATUS: ".$servers->get_status("0.0.0.0",80); //<<-- KILLS PAGE ?>Page works fine until I want to use the status function, I get no errors or anything just a blank page. PATH: Lib/Servers.inc NOTICE //<<-- KILLS PAGE <?php ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(E_ALL); error_reporting(-1); include_once '../../Global-Includes/ServerStatus/db-connect.php'; //namespace xStatus; class servers { private $db_Hostname = HOSTNAME; private $db_Username = USERNAME; private $db_Password = PASSWORD; private $db_Database = DATABASE; private $dbSQL = ''; function __construct() { } // End Construct public function get_servers(){ $db = new mysqli($this->db_Hostname,$this->db_Username,$this->db_Password,$this->db_Database); $message = ''; // list current servers from database $sql = "SELECT * FROM tbl_servers"; $res = $db->query($sql); if ($res->num_rows > 0) { $message = '<h3>Current Servers</h3>'; while ($row = $res->fetch_assoc()) { $message .= $row['HostGame'] . '<br>'; $message .= $row['HostIP'] . '<br>'; $message .= $row['HostPort'] . '<br>'; $message .= $this->get_status($row['HostIP'],$row['HostPort']) . '<br>'; //<<-- KILLS PAGE! } } $message .= "<br>End of the \"Server List\" "; return $message; } public function get_status(&$ServerIP,&$ServerPort){ if(@stream_socket_client("tcp://".$this.$ServerIP.":".$this.$ServerPort."", $errno, $errstr, 1) !== false) { return "Online"; } else { return "Offline"; } return "Offline"; } } // End class ?>Kind regards and thank you. I've been hacking at this for about 4 hours now.. Throwing the towel in! Any feedback or suggestions please: I'm calling a function like so: <!--START :: Run report and update records --> <p> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <!--<input type="hidden" name="post_var">--> <input type="submit" name="runUpdate" value="Run Update"> </form> </p> <?php if (isset($_POST['runUpdate'])) { updateRecords(); }; ?> <!--END :: Run report and update records --> Here are the function details: <?php function updateRecords() { // START :: Query to replace matches mysql_query("UPDATE orig_codes_1a AS a JOIN old_and_new_codes_1a AS b ON concat(a.orig_code_1, a.orig_code_2) = concat(b.old_code_1, b.old_code_2) SET a.orig_code_1 = b.new_code_1, a.orig_code_2 = b.new_code_2") or die(mysql_error()); // END :: Query to replace matches echo "<p><table border='1' cellpadding='3' width='100%'>"; echo "<tr> <th>Updated Code 1</th> <th>Updated Code 2</th> </tr>"; // START :: While loop - keeps getting the next row until there are no more to get while($row = mysql_fetch_array($result)) { //START :: If to find matching criteria class it w/ bg color if ($row['orig_code_1'] < '10000') { $changedClass = "changedClassCSS"; } else { $changedClass = ""; }; //END :: If to find matching criteria class it w/ bg color //START :: Print out the contents of each row into a table echo "<tr><td class=\"$changedClass\">"; echo $row['orig_code_1']; echo "</td><td class=\"$changedClass\">"; echo $row['orig_code_2']; echo "</td>"; } echo "</table></p>"; //END :: Print out the contents of each row into a table // START // //echo "$tableOutput"; // END // }; ?> I'm getting this error: Notice: Undefined variable: result in C:\wamp\www\php_practice\apps\records_updater_2\functions.php on line 27 Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\wamp\www\php_practice\apps\records_updater_2\functions.php on line 27 Now what I don't understand is 1) This script works fine (even though the $result is not defined) when all of the code is in one file not being called as a function. And 2) Why the hell would it work as in number 1?? Please please please tell me what I am doing wrong here! Hey Guys, Im having problems with my code. What im trying to do is run a mysql query and show the results, but if the query returns no data, echo out "No incoming requests!" Here is my code: <? $check = "SELECT * FROM requests WHERE club='" . $_SESSION['club'] . "' AND team='" . $_SESSION['team'] . "' AND accepted='0'"; $result=mysql_query($check); if (mysql_num_rows($result) == 0) { while ($getinfo = mysql_fetch_array($result)) { $time = $getinfo["time"]; $who = $getinfo["player_name"]; $whofor = $getinfo["toplayfor"]; $from = $getinfo["team"]; $idp = $getinfo["player_id"]; echo "<a href='profile.php?id=".$idp."&team=".$from."'>".$who." </a><div style='float:right;'>(".$from.")</div><br />"; echo "<div style='margin-top: 2px;'></div>"; echo date('l, F jS, g:ia',$time); echo "<br /><div style='margin-top: 2px;'></div><a href='accept.php?playerid=".$idp."&toplayfor=".$whofor."'>Accept</a> | Decline"; echo "<div id='newsline'></div>"; } } else { echo 'No incoming requests'; } ?> Could someone help me out here? Thanks Heaps! Hey guys, I've been playing around with this open source php game, I'm having problems with the registration system. For some reason the script is echoing back that there is no password in the password fields. When in fact there is: Add_player.php: Code: [Select] <?php session_start(); session_register("pid"); include("common.inc"); include("date.inc"); include("header.inc"); dbConnect(); $res = mysql_query("select id from $dbName.pdm_players where name=\"$name\"") or die(mysql_error()); if ($name == "" || $password1 == "") { echo "<center><div class=\"sheader\">Oh dear me!</div> You have to actually enter a name and password!"; $name = ""; include("character_form.inc"); echo "</center>"; include("footer.inc"); return 0; } if ($name == $password1) { echo "<center><div class=\"sheader\">Oh dear me!</div> You can't make the password the same as the name. People will guess your password!"; include("character_form.inc"); echo "</center>"; include("footer.inc"); return 0; } if (strlen($password1) < 6) { echo "<center><div class=\"sheader\">Oh dear me!</div> Passwords must be at least 6 characters, otherwise they are easy to guess!"; include("character_form.inc"); echo "</center>"; include("footer.inc"); return 0; } if (mysql_fetch_row($res)) { echo "<center><div class=\"sheader\">Oh dear me!</div> Player $name already exists, try a different name."; $name = ""; include("character_form.inc"); echo "</center>"; include("footer.inc"); return 0; } if ($password1 != $password2) { echo "<center><div class=\"sheader\">Oh dear me!</div>"; echo "The two passwords didn't match - type carefully now!."; include("character_form.inc"); echo "</center>"; include("footer.inc"); return 0; } echo "<div class=\"sheader\">Registration for $name successful</div>"; $cp = crypt($password1); $dateArray = getdate(time()); $likeNowScoob = $dateArray["year"] . "-" . $dateArray["mon"] . "-" . $dateArray["mday"]; if ($character < 1 || $character > 9) { die("you are an idiot"); } pdm_characters(); $res = mysql_query("select type from $dbName.pdm_characters where cid = $character") or die(mysql_error()); $t = mysql_fetch_row($res); pdm_stuff(); $specRes = mysql_query("select sid from $dbName.pdm_stuff where sid >= 28 and sid <= 33 and type like \"%$t[0]%\"") or die(mysql_error()); $res = mysql_query("BEGIN") or die(mysql_error()); $res = mysql_query("insert into $dbName.pdm_players (name, used, dob, cpass, char_id, roundswon, evo, aWeapon, dWeapon) VALUES (\"$name\", 1, \"$likeNowScoob\", \"$cp\", $character, 0,0,0,0)") or die(mysql_error()); $res = mysql_query("select id from $dbName.pdm_players where name=\"$name\" for update") or die(mysql_error()); $row = mysql_fetch_row($res); $pid = $row[0]; $res = mysql_query("insert into $dbName.pdm_league (id, highest, days_no_1, yesterday, longPoints) VALUES ($pid, 16777215, 0, 16777215, 0)") or die(mysql_error()); $res = mysql_query("insert into $dbName.pdm_stats (id, level, attack, defence, health, speed, exp, ko, healthpercent, fights) VALUES ($pid, 1, 100, 100, 100, 100, 0, 0, 10, 0)") or die(mysql_error()); $res = mysql_query("insert into $dbName.pdm_clanmembers2 (id, clanTag, applyTag, utype) VALUES ($pid, NULL, NULL, '')") or die(mysql_error()); $res = mysql_query("insert into $dbName.pdm_money (id, bank, wallet, bankdate) VALUES ($pid, 0,0, '0000-00-00')") or die(mysql_error()); while ($row = mysql_fetch_row($specRes)) { $res = mysql_query("insert into $dbName.pdm_specials (id, sid, qty, switch) values ($pid, $row[0], 0, 1)") or die(mysql_error()); } $res = mysql_query("COMMIT") or die(mysql_error()); session_register("playerName"); $playerName = stripper($name); echo "<P><diV>Welcome $playerName, click the Fight link down the left to fight your first opponent.</div>"; include("main_screen.inc"); include("footer.inc"); ?> Character_form.inc: Code: [Select] <center> <form method="post" action="add_player.php"> <P> <table cellpadding="0" cellspacing="0"><tr><td align="center"> <?php dbConnect(); pdm_characters();#check HEAP table exists $res = mysql_query("select cid, name, type from $dbName.pdm_characters order by type") or die(mysql_error()); $marker = "X"; $firstOne = 1; $cTypes["A"] = "Alien"; $cTypes["M"] = "Magic"; $cTypes["S"] = "Spirit"; while ($row = mysql_fetch_row($res)) { if ($marker != $row[2]) #new type (alien/magic etc) { if ($marker != "X") { echo "</table>\n"; } $cn = $cTypes[$row[2]]; echo "\n<table cellpadding=\"0\" cellspacing=\"0\" border=1> <tr><td colspan=\"3\" align=\"center\"><div class=\"sheader\"> $cn characters</div></td></tr><tr bgcolor=\"#efefef\">"; $marker = $row[2]; } echo "\n<td><table><tr><td align=center>$row[1]</td></tr><tr><td align=center> <img alt=\"Pick me!\" src=\"images/$row[0]0.gif\"></td></tr><tr> <td align=center><input type=\"radio\" name=\"character\" value=\"$row[0]\""; if ($firstOne and $character == "") { $firstOne = 0; echo " CHECKED "; } if ($character == $row[0]) { echo " CHECKED "; } echo "></td></tr></table></td>"; } echo "</tr></table> <table width=\"551\" cellpadding=0 cellspacing=0><tr><td colspan=\"3\"><div class=\"sheader\">character details</div></td></tr> <tr><td align=\"center\">Name<br><input size=20 maxlength=20 type=text name=\"name\" value = \"$name\"></td>"; ?> <td align="center">Password<br><input type="password" name="password1" size=20 maxlength=20></td> <td align="center">Password again<br><input type="password" name="password2" size=20 maxlength=20></td></tr> <tr><td colspan="3" align="center"><input type="submit" value="Register my character"></td></tr></table> </td></tr></table> <hr> </form> </centER> Anyone able to offer up any advice or where its going wrong, If I remove the validation stuff, it still doesn't insert the user into the database. Cheers OK So I have a quick question... how would I go about making a query like: mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' AND key='$key' "); You see, theres an error: Quote 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 ' key='1234' LIMIT 1' at line 1 I know this is a simple issue, and I know you cant keep creating AND's inside the query, but how would I do it? I've never attempted to use more than one AND before, so its new to me even though I'm a experienced PHP Developer. Thanks in advance! Hi, why won't this work, there is no error messages so it gets to this point, but won't redirect??? (Obviously a lot is missed out here) $query = mysql_query("SELECT * FROM `users` WHERE `username`='$username'"); if ($username==$dbusername&&$password==$dbpassword) { $_SESSION['user'] = $username; while($row = mysql_fetch_array($query)){ $type = $row['Type']; if ($type=="0") { header("Location: chefpanel.php"); }else{ header("Location: restpanel.php"); } } } else $errors[] = 'Password Incorrect'; } else $errors[] = 'Username Incorrect'; I am getting a "mysqli_query() expects parameter 1 to be mysqli, null given" error. the code I am using is below but simplified. connect() does connect to the database without throwing any errors but when I get down to query() I get the above error. public function connect() { mysqli_connect(self::DBHOST, self::DBUSER, self::DBPASS, self::DBNAME); } public function query($query) { mysqli_query(self::connect(), $query); } below is what I am using to call the function. I am not sure if I have to pass the $link in the query function too. I have tried but it didn't seem to do any better. $link = db::connect(); $query = "SELECT name FROM plugins"; db::query($query); I am sure this is something simple that I have overlooked but I am new to this and still learning. Thank you for any help you can provide. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=328375.0 |