Jump to content

mlummus

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Everything posted by mlummus

  1. I'm trying to create a table form that pulls in "Extra" choices from a table and allows users to select a number of days and number of guests for each choice. I started creating it a a checkbox field but am thinking just using the name as a label and setting days and guests to default "0" might be a better bet. Guidance from someone more experienced with this? Also, how do I store the submission (db structure - in the "reservations" table, another?). I'm new to this and feel kind of lost with this challenge. //Extras $query = "select * from extras"; $data = mysqli_query($db, $query); $num = mysqli_num_rows($data); echo "<p><b>Extras:</b></p>"; for ($i=0; $i<$num; $i++) { $row = mysqli_fetch_array($data); $extra_id = $row['extra_id']; $extra_name = $row['extra_name']; $extra_rate = $row['extra_rate']; echo "<p><input type='checkbox' name='extra_id[]' value = '$extra_id' />$extra_name <i>\$$extra_rate</i> Num Days<input type='text' name='d$extra_id' /> Num Guests<input type='text' name='g$extra_id' />"; }
  2. Getting the error: "Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean" and haven't been able to spot where its coming from. Any insight out there? $db = mysqli_connect("dbserver.com", "user", "password"); if (!db) {echo "Error: Could not connect to database."; exit;} mysqli_select_db($db, "dbname"); $query = "SELECT id FROM student"; $result = mysqli_query($db, $query); $num_results = mysqli_num_rows($result);
  3. When viewing this program in a browser, I'm getting nothing - no html, no php, no source whatsoever - just white. The page is coming up blank. Any idea why? <html> <head> <title> Student Delete </title> </head> <body> <h1>Student Delete Form </h1> <h2>Select a Student</h2> <?php $db = mysqli_connect("dbserver.com", "user", "password"); if (!db) {echo "Error: Could not connect to database."; exit;} mysqli_select_db("dbname"); $query = "SELECT id from student"; $result = mysqli_query($query); $num_results = mysqli_num_rows($result); echo "<p> Number of students found: ".$num_results."</p>"; echo "<form method='post' action='studentfind.php'>"; echo "ID:" <select name = 'id'>"; for ($i=0; $i < $num_results; $i++) { $row=mysqli_fetch_array($result); $id = $row["id"]; echo "<option value = "$id"> $id </option>"; } echo "<input type='submit' value='delete' />"; echo "</form>"; mysqli_close("$db"); ?> </body> </html>
  4. Thanks jwk811. By the way, does anyone know of a program out there that helps you find these kinds of syntax errors?
  5. Does anyone see the error in the code below? I am receiving the program's error code "Error in placing data in database." It may be something simple - I am fairly new to this. Thanks in advance for your help. $db = mysqli_connect('server', 'user', 'password'); mysqli_select_db($db, "database"); $query = "UPDATE student SET id='$id', name_last='$name_last', name_first='$name_first', email='$email', class='$class', major='$major', living='$living WHERE id='$id'"; $result = mysqli_query($db, $query); if ($result) { echo "student updated in database.</h2>"; } else { echo "<h2> Error in placing data in database </h2>"; } mysqli_close($db);
  6. I'm receiving a "Warning: mysqli_query() expects at least 2 parameters, 1 given." Would would be the second parameter it is looking for? $SQLstring = "SELECT * FROM student WHERE id = '$id'"; $QueryResult = mysqli_query($SQLstring); Any help is greatly appreciated. Thanks!
  7. Thanks. I must have missed the "i" on that one. I've fixed that error but am now receiving "Warning: mysqli_query() expects at least 2 parameters, 1 given." Would would be the second parameter it is looking for? $SQLstring = "SELECT * FROM student WHERE id = '$id'"; $QueryResult = mysqli_query($SQLstring);
  8. I'm getting the following response when running the code below. The input should be calling a valid record. Any idea where the errors may be coming from? I'm am able to connect to the database and table using the same credentials in other similar php programs (for instance, a call all records program). Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /net/oitg/export/home1/home3/mdl0002/public_html/assignment1/lookupstudent.php on line 31 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /net/oitg/export/home1/home3/mdl0002/public_html/assignment1/lookupstudent.php on line 31 Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /net/oitg/export/home1/home3/mdl0002/public_html/assignment1/lookupstudent.php on line 33 No Records Found. $db = mysqli_connect('host','user','password'); if (!$db) { echo "Error: Could not connect to database. Please try again later."; exit; } mysqli_select_db($db, "database"); $SQLstring = "SELECT * FROM student WHERE id = '$id'"; $QueryResult = mysql_query($SQLstring); $NumRows = mysqli_num_rows($QueryResult); if ($NumRows == 0) echo "<p>No Records Found."; else { $Row = mysql_fetch_array($QueryResult); $id = $Row['id']; $name_last = $Row['name_last']; $name_first = $Row['name_first']; $email = $Row['email']; $class = $Row['class']; $major = $Row['major']; $living = $Row['living'];
  9. Thanks Ken. Of course it was something blatantly obvious - been staring at it too long I guess!
  10. I'm learning PHP and am having an issue I can't seem to figure out this issue. I'm getting the following error on the line: {echo "<option value='freshman' selected = 'selected'>Freshman</option>}";} Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /net/oitg/export/home1/home3/mdl0002/public_html/assignment1/lookupstudent.php on line 58 Any help is much appreciated. Thanks! $SQLstring = "SELECT * FROM student WHERE id = '$id'"; $QueryResult = @mysql_query($SQLstring); $NumRows = mysqli_num_rows($QueryResult); if ($NumRows == 0) echo "<p>No Records Found."; else { $Row = mysql_fetch_arraw($QueryResult); $id = $Row['id']; $name_last = $Row['name_last']; $name_first = $Row['name_first']; $email = $Row['email']; $class = $Row['class']; $major = $Row['major']; $living = $Row['living']; echo "<form action='updatestudent.php' method='get'>"; echo "ID <input type='text' name='id' value=$id/> <br />"; echo "Last Name <input type='text' name='name_last' value=$name_last /> <br /> "; echo "First Name <input type='text' name='name_first' value=$name_first/> <br /> "; echo "Email Address <input type='text' name='email' value=$email/> <br /> "; echo "Classification <select name='class'> if ($class == 'freshman') {echo "<option value='freshman' selected = 'selected'>Freshman</option>}";} else {echo "<option value='freshman'> Freshman </option>";} if ($class == 'sophomore') {echo "<option value='sophomore' selected = 'selected'> Sophomore </option>";} else {echo "<option value='sophomore'> Sophomore </option>";} if ($class == "junior") {echo "<option value='junior' selected = 'selected' Junior </option>";} else {echo "<option value='junior'> Junior </option>";} if ($class == "senior") {echo "<option value='senior' selected = 'selected' Senior </option>";} else {echo "<option value='senior'> Senior </option>";} if ($class == "graduate") {echo "<option value='graduate' selected = 'selected' Graduate </option>";} else {echo "<option value='graduate'> Graduate </option>";} </select> <br />"; <input type="submit"> </form> mysqli_close($db);
×
×
  • 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.