Jump to content

Search the Community

Showing results for tags 'mysql_num_rows'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 3 results

  1. Hello, I created a page that gets some information from a MySQL database and displays it on a page. The information is selected based on the ID of the row in the database. So, if ...script.php?id=55 it will display the information from submission ID #55. All of that works great, but I am having difficulty sending it to an error page if someone manually enters an ID number that does not exist. For instance script.php?id=7777 Right now I am using if (mysql_num_rows($result)==0) { die (include "/path/to/public_html/errors/no_classes_selected.php"); } Unfortunately it ALWAYS includes that error page, as it seems $result is always equal to 0 even if the ID number is a real entry. For instance, if I take that line out, and an ID that exists is entered, it displays the data fine. If I leave that code in and I use the same ID, it displays the error page. Am I doing this right? <?php // Get required login info include "/path/to/login_info.php"; $db = new mysqli('localhost', $username, $password, $database); // Connect to DB using required login info if($db->connect_errno > 0){ die('Unable to connect to database [' . $db->connect_error . ']'); } unset($username);// put these variables back to null unset($password);// put these variables back to null unset($database);// put these variables back to null date_default_timezone_set('America/Los_Angeles'); // set default time zone PST // ************GET ID FROM URL*********************** $id = (int)$_GET['id']; // this gets the id from the url if($id != '' && $id > 0) { // this checks to make sure that the ID is an integer // ************************************************** $sql = <<<SQL SELECT ft_form_8.*,ft_form_7.* FROM ft_form_7 LEFT JOIN ft_form_8 ON ft_form_8.Instructor=ft_form_7.Instructor WHERE ft_form_7.submission_id=$id SQL; if(!$result = $db->query($sql)){ // if there is an error in running the query, show error message. die('There was an error running the query [' . $db->error . ']'); } if (mysql_num_rows($result)==0) { die (include "/path/to/public_html/apps/errors/no_classes_selected.php"); } while($row = $result->fetch_assoc()){ // Get start date information $start_date = $row['class_start_date']; // Get event_start_date for conversion and call it $start_date $start_date_formatted = date("l M d, Y", strtotime($start_date)); // Convert start_date $end_date = $row['class_end_date']; // Get event_end_date for conversion and call it $start_date $end_date_formatted = date("M d, Y", strtotime($end_date)); // Convert start_date // Do above for start and end date two for multiple day classes (ex. jan 1-2 and feb 2-3) $start_date_2 = $row['class_start_date_2']; $start_date_2_formatted = date("l M d, Y", strtotime($start_date_2)); $end_date_2 = $row['class_end_date_2']; $end_date_2_formatted = date("M d, Y", strtotime($end_date_2)); // Get time information. $start_time = $row['class_start_time']; // Get event_start_time for conversion and call it $start_time $start_time_formatted = date("h:i A", strtotime($start_time)); // Convert start_time $end_time = $row['class_end_time']; // Get event_end_time for conversion and call it $end_time $end_time_formatted = date("h:i A", strtotime($end_time)); // Convert end_time // echo information... echo "<h2>" , $row['class_name'],"</h2>" ; // echo event name echo "<p><strong>",$start_date_formatted; // echo the start date if (empty($end_date) or $end_date = $start_date) { echo '<br/>'; } else { echo " - ","", $end_date_formatted , "<br />"; } // echo end date if (empty($start_date_2)) {echo '';} else { echo $start_date_2_formatted; } // echo the start date if (empty($end_date_2) or $end_date_2 = $start_date_2) { echo ''; } else { echo " - ","", $end_date_2_formatted , "<br />"; } // echo end date if (empty($start_time)) { echo ''; } else { echo $start_time; } // echo start time if (empty($end_time)) { echo ')'; } else { echo " - ", $end_time; } // echo end time // if there is no start time, echo nothing. (otherwise it seems to echo 4pm). If it does contain a time, echo the time. echo "</strong>"; $chef_full_name = $row['Instructor']; $chef_id = $row['submission_id']; $full_bio = $row['full_bio']; echo "<div class=\"showbio\">" , "<div class=\"underline\">" , $chef_full_name , "</div>"; echo "<div class=\"bio\" style=\"display: none;\">"; echo $full_bio , "</div></div><br />"; echo $row['class_description'], "<br />"; echo "<strong>" , $row['type'], " - Cost: $",$row['cost'] , " - #" , $row['course_number'] , " - <a href=\"registration.php\" target=\"_blank\"> (Register Online)</a> </strong><br />" , "</p>"; // echo class type and cost } $db->close(); $result->free(); } else { die (include "/path/to/public_html/apps/errors/no_id.php"); //display error if ID is not an integer } ?>
  2. 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); } ?>
  3. Does anyone know what mysql_num_rows has been changed to, and how to write it out for newer versions of PHP base?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.