Search the Community
Showing results for tags 'mysql_fetch_array'.
-
Hello everyone. I have a problem with my php code, where I placed in hosting server. Everything works fine, my database,registration system(where I getting users names and emails to my database), even in this code, I'm recieving a message where I coded to message me that function "mail_body", is sent to the registered users(When I check registered user email, there is nothing(no email from this php system)). There are two problems , when I active this php file, I'm getting those two errors (below my text). If someone could help me, I would be truly grateful for such a help. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a1848137/public_html/newsletter.php on line 6 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a1848137/public_html/newsletter.php on line 8 <?php include_once "connect_to_mysql.php"; $sql = mysql_query("SELECT * FROM newsletter WHERE received='0' LIMIT 20"); $numRows = mysql_num_rows($sql); $mail_body = ''; while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $name = $row["name"]; $email = $row["email"]; $mail_body = '<html> <body style="background-color:#676666; font-family: Arial, Helvetica, sans-serif; line-height:1.8em;"> <h3 style="color:EE0000"><a href="http://pc123.com"><img src="img/baltas logo.png" alt="PC123.com" width="230" height="80" border="0"></a> Newsletter </h3> <p>Hi !' . $name . ',</p> <p>Text about something</p> <p>Testing</p> <hr> <p>u can refuse our <a href="/unregister/opt_out.php' . $email . '">clicking here</a> newsletter</p> </body> </html>'; $subject = "PC newsletter"; $headers = "From:PC123.com\r\n"; $headers .= "Content-type: text/html\r\n"; $to = "$email"; $mail_result = mail($to, $subject, $mail_body, $headers); if ($mail_result) { mysql_query("UPDATE newsletter SET received='1' WHERE email='$email' LIMIT 1"); } else { } } ?> <?php if ($numRows == 0) { $subj = "Newsletters had been sent"; $body = "Newsletters had been sent"; $hdr .= "Content-type: text/html\r\n"; mail("myemail@gmail.com", $subj, $body, $hdr); } ?>
-
Hey there, First time using MySQL database to connect to a member login. I have a paid subscription site through ccbill which they add the username and logins to. I have setup a database, username and password as well as a table that I have connected correctly "I believe" to my website but get this message: warning: MySQL-fetch_array()expects parameter 1 to be resource, Boolean given in /home.... My table I have setup just has username and password to authenticate the users, which I was told by ccbill is all I need. Maybe I need authentication 1 or 0 etc. Any help on this would be amazing. Spent hours trying to figure this out but nothing. Thanks for your time. Steven
- 3 replies
-
- mysql
- phpmyadmin
-
(and 2 more)
Tagged with:
-
Hi, I tried to prefrom a mysql_fetch_array using OOP and i get the folloing error message. Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in .... filename I have created a class named mysql database, and inside that class I have included a method named "fetch_array". Below is how the code looks. (There are obviously other mehtods in that class i have just included the one I am having trouble with) <?php // I have created a file named database.php and created the class mySQLDatabase for that file class mySQLDatabase { public function fetch_array($result_set) { return mysql_fetch_array($result_set); } public function query($sql) { $result = mysql_query($sql, $this->connection); $this->confirm_query($result); // end of if (!$result) return $result; } // end of function query($sql) } $database = new mySQLDatabase();//Created an instance of the class to include in my user.php file. (Below) ?> then i have created a new file named user.php.. included the database.php and have created a class the preforms the queries called the "User" Class <?php class User { public static function find_all() { $result_set = self::find_by_sql("SELECT * FROM users"); return $result_set; } public static function find_by_id($id=0) { // I have pulled in the global $database variable that I have instantiated from the database.php file global $database; $result_set = self::find_by_sql("SELECT * FROM users WHERE id={$id} LIMIT 1"); // I used the find_by_sql(below) method to perform my functions for functions inside this class $found = $database->fetch_array($result_set); return $found; } public static function find_by_sql($sql="") { global $database; $result_set = $database->query($sql); $return = $result_set; } } ?> Lastly on my index.php i used the static method to run the query and preform the mysql_fetch_array on the username and it doesn't seem to be working. here is how did this on the index.php file. $record = User::find_by_id(1); echo $record['username'];
-
I receive the below error for my code Warning: mysql_fetch_array() expects parameter 1 to be resource Please help" <!DOCTYPE html> <html> <body> <?php $fname=$_POST['fname']; $lname=$_POST['lname']; $uname=$_POST['uname']; $pwd=$_POST['pwd']; $email=$_POST['email']; echo $fname."<br>"; echo $lname."<br>"; echo $uname."<br>"; echo $pwd."<br>"; echo $email."<br>"; mysql_connect("localhost","","") or die("Could not connect: " . mysql_error()); mysql_select_db("projecto"); $result = mysql_query("SELECT uname,firstname FROM udata"); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf("ID: %s Name: %s", $row1[0], $row1[1]); } mysql_free_result($result); /* //$result = mysql_query("SELECT fname,password FROM udata"); if ($db_found) { $result = mysql_query("SELECT fname,password FROM udata"); while ( $db_field = mysql_fetch_assoc($result) ) { if ($db_field['uname']==$uname && $db_field['password']==$pwd) header( 'Location: www.youtube.com' ) ; print $db_field['fname'] . "<BR>"; print $db_field['lname'] . "<BR>"; print $db_field['uname'] . "<BR>"; print $db_field['password'] . "<BR>"; } } else { print "Database NOT Found "; mysql_close($db_handle); } */ mysql_close($con); ?> </body> </html>