Jump to content

pmi

Members
  • Posts

    4
  • Joined

  • Last visited

pmi's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks much for the help. I got it working! Appreciate it!
  2. Sorry all, just noticed I should have posted this in the "PHP coding section" of PHP Freaks. I don't want to double post and I don't think there is any way to move it now.
  3. Hello All, I am relatively new to PHP and this site so I apologize in advance if I am asking this in the wrong place. I am trying to very simply connect a PHP script to my localhost database. I am using WAMP server 2. The PHP version is 5.3.13, Apache version 2.2.22, and MySQL version 5.5.24 I believe with my current code I am now able to connect, but I am unable to output the query result. I have tried a lot of things, and I know this is a simple task, but I'm stuck. The error I seem to be getting often is: "mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\wamp\www\DB_connect_5_04052013\index.php on line 29" Any suggestions would be much appreciated. <?php // Create connection $con=mysql_connect("localhost","root"); // Check connection if ($con == FALSE) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // Check connection again $link = mysql_connect("localhost","root", "", "autosite_db"); if (!$link) { die("Can't connect to database server"); } // Select the Database mysql_select_db ("autosite_db", $con) or die ("Unable to select database"); // Execute Sample Query $SQL = "SELECT * FROM vehicle"; $result = mysql_query($SQL); while ( $db_field = mysql_fetch_assoc($result) ) { print $db_field['vin'] . "<BR>"; print $db_field['year'] . "<BR>"; print $db_field['make'] . "<BR>"; print $db_field['model'] . "<BR>"; }
  4. I had this working before. I have errors in PHP and I don't think the code will run. Any suggestions would be much appreciated, <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="test.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="container"> <div class="header"><!-- end .header --></div> <div id="h-navbar"><a href="#">Home</a> | <a href="#">About Us</a> | <a href="#">Contact Us</a></div> <div class="sidebar1"> <ul class="nav"> <li><a href="#">Inventory</a></li> <li><a href="#">Financing</a></li> <li><a href="#">Service</a></li> <li><a href="#">Promotions</a></li> </ul> <p>sidebar</p> <p>(hours & location)</p> <!-- end .sidebar1 --></div> <div class="content"> <h1 align="center">Sign up for Deals & Special Offers!</h1> <?php $displayForm = true; if (isset($_POST['submit'])) { $displayForm = false; } if (isset($_POST['username'], $_POST['email'], $_POST['age'], $_POST['password'])) { $errors = array(); $username = $_POST['username']; $age = $_POST['age']; $email = $_POST['email']; $password = $_POST['password']; /* if (empty($name) || empty($age) || empty($email) || empty($password)) { $errors[] = 'All fields are required!'; } else */ //allows only letters and numbers for username if (!ctype_alnum($username)) { $errors[] = 'Name must contain a combination of letters and numbers only!'; } // age must be numeric if (!preg_match ("/^([0-9]+)$/", $age)) { $errors[] = 'Age must be a number!'; } //email must be valid if (!filter_var($email, FILTER_VALIDATE_EMAIL) == true) { $errors[] = 'You must enter a valid email!'; } //password must be between 8 and 16 characters in length //password must only contain letters and numbers if (!preg_match("/^[a-z0-9]{8,16}$/i", $password)) { $errors[] = 'Password invalid, must be between 8 and 16 characters!'; } // if there are validation errors, loops and outputs errors stored in array if (!empty($errors)) { foreach ($errors as $error) { echo $error; } } //if there are no validation errors, confirms registration else { echo "Thanks for registering!" echo "Your username is: " . $username echo "Your email address is: " . $email echo "Your age is: " . $age, echo "Your password is: " . $password $file_name = fopen('registrationfile.csv', 'a+'); $record = array( $username, $email, $age, $password); fputcsv($file_name, $record); fclose($file_name); } } if ($displayForm) { ?> <p> <form action="" method="post"> <label>Username:</label> <input type="text" name="username" /><br> <label>Email:</label> <input type="text" name="email" /><br> <label>Age:</label> <input type="text" name="age" /><br> <label>Password:</label> <input type="password" name="password" /><br> <input type="submit" name="submit" value="Register" /> </form> <p> <p>content</p> <!-- end .content --></div> <div class="footer"> <p>Copyright 2013 - Quality Auto Group</p> <!-- end .footer --></div> <!-- end .container --></div> </body> </html>
×
×
  • 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.